我已经使用registration.php中的表单用search.php搜索了mysql数据库。现在我想根据那个人的ID用另一封电子邮件替换用户的电子邮件。我该怎么做。
这是search.php`
$searchTerm = ($_GET['keyname']);
//check whether the name parsed is empty
if($searchTerm == "")
{
echo "Enter name you are searching for.";
exit();
}
$host = "localhost";
$my_db = "xxx";
$my_user = "xxx";
$my_password = "xxx";
$link = mysqli_connect("localhost",$my_user,$my_password,$my_db);
$query = "SELECT * FROM yesData WHERE socialSecNum LIKE '%$searchTerm%' ";
$results = mysqli_query($link, $query);
if(mysqli_num_rows($results) >= 1)
{
$output = "";
while($row = mysqli_fetch_array($results))
{
$output .= "First Name: " . $row['nameFirst'] . "<br />";
$output .= "Last Name: " . $row['nameLast'] . "<br />";
$output .= "SSN: " . $row['socialSecNum'] . "<br />";
$output .= "ID: " . $row['id'] . "<br /><br />";
$output .= "Email: " . $row['addressEmail'] . "<br /><br />";
}
echo $output;
}
else
echo "There was no matching record for the name " . $searchTerm;
?>
`
这是registration.php
<!DOCTYPE html>
<html dir="ltr" lang="en-US" >
<head>
<meta charset="UTF-8" />
<title>Registration Page</title>
</head>
<body>
<h1>Registration</h1>
<form action="search.php" method="get">
<label>Name:
<input type="text" name="keyname" />
</label>
<input type="submit" value="Search" />
</form>
</body>
</html>
提前谢谢。
简单,在MySQL中使用UPDATE。
W3学校的语法:
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
您应该使用:
"UPDATE yesData
SET addressEmail=newemail
WHERE socialSecNum="."%$searchTerm%";