[英]SQL update multiple rows with different values
Edit: I've re-written my question to include more details: 编辑:我重写了我的问题,以包括更多详细信息:
Here's a snapshot of the code that produces the page of results from the database of users: 这是从用户数据库生成结果页面的代码的快照:
userdetails.php userdetails.php
$currenttechnicians = "SELECT * FROM ahsinfo ORDER BY FirstName";
$currenttechniciansresults = sqlsrv_query($conn,$currenttechnicians) or die("Couldn't execut query");
while ($techniciandata=sqlsrv_fetch_array($currenttechniciansresults)){
echo "<tr align=center>";
echo "<td height=35 background=largebg.gif style=text-align: center valign=center>";
echo "<input type=hidden name=\"ID\" value=";
echo $techniciandata['ID'];
echo ">";
echo "<input type=textbox name=\"FirstName\" value=";
echo $techniciandata['FirstName'];
echo "> ";
echo "</td><td height=35 background=largebg.gif style=text-align: center valign=center>";
echo "<input type=textbox name=\"LastName\" value=";
echo $techniciandata['LastName'];
echo "> ";
echo "</td><td height=35 background=largebg.gif style=text-align: center valign=center>";
echo "<input type=textbox size=40 name=\"SIPAddress\" value=";
echo $techniciandata['SIPAddress'];
echo "> ";
echo "</td><td height=35 background=largebg.gif style=text-align: center valign=center>";
echo "<input type=textbox name=\"MobileNumber\" value=";
echo $techniciandata['MobileNumber'];
echo "> ";
echo "</td><td height=35 background=largebg.gif style=text-align: center valign=center>";
?>
Here's the code that handles the form submission: (again, just the SQL query that updates the database. I've removed the database connection string). 这是处理表单提交的代码:(同样,只是更新数据库的SQL查询。我删除了数据库连接字符串)。
edituserdetails.php edituserdetails.php
<?PHP
//Add the new users details to the database
$edituser = " UPDATE ahsinfo SET FirstName='{$_POST['FirstName']}', LastName='{$_POST['LastName']}', SIPAddress='{$_POST['SIPAddress']}', MobileNumber='{$_POST['MobileNumber']}' WHERE ID='{$_POST['ID']}' ";
$editresult = sqlsrv_query($conn,$edituser) or die("Couldn't execute query to update database");
?>
I'm trying to update the entire database (it's a small database) with any changes that a user makes on the userdetails.php page. 我正在尝试使用用户在userdetails.php页面上进行的任何更改来更新整个数据库(这是一个小型数据库)。
You're missing quotes around your string values and used a curly brace instead of a bracket on one of your POST variables: 您在字符串值周围缺少引号,并在其中一个POST变量上使用了花括号而不是方括号:
UPDATE ahsinfo
SET FirstName="{$_POST['FirstName']}",
LastName="{$_POST['LastName']}",
EmailAddress="{$_POST['EmailAddress']}",
MobileNumber="{$_POST['MobileNumber']}"
WHERE ID={$_POST['ID']}
You would have caught this if you checked for errors in your code. 如果您检查代码中的错误,则将捕获此错误。
FYI, you are wide open to SQL injections 仅供参考,您对SQL注入持开放态度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.