我已经在search.php中搜索了mysql数据库,并在registration.php中使用了我的表单。现在我想根据该人员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>
提前谢谢。
答案 0 :(得分:0)
简单,在MySQL中使用UPDATE。
W3 Schools的语法:
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
您应该使用:
"UPDATE yesData
SET addressEmail=newemail
WHERE socialSecNum="."%$searchTerm%";