gpt4 book ai didi

javascript - 更新值时出错

转载 作者:行者123 更新时间:2023-11-29 06:00:14 26 4
gpt4 key购买 nike

我正在创建一个小项目来向我的学生解释如何使用 PHP 代码更新 SQL 数据库中的值。我在 MySQL 中创建了表,所有字段都为 VARCHAR。我写了下面的代码,它抛出以下错误:更新值错误您的 SQL 语法有误;检查与您的 MySQL 服务器版本对应的手册,了解在第 1 行的 'Mbps WHERE dsl = '25610669'' 附近使用的正确语法,其中 25610669 是数据库中的现有记录。这是代码:

<?php
if((isset($_POST['B2'])))
{
$server = 'localhost' ;
$un = 'root' ;
$pass = 'icsk' ;
$db = 'yusuf' ;
$conn = mysqli_connect($server, $un, $pass, $db);
$update = "UPDATE homereg SET Fname = {$_POST['First']}, Lname = {$_POST['Last']}, cid = {$_POST['cid']}, pack = {$_POST['choice']} WHERE dsl = {$_POST['dsl']}" ;
$result = mysqli_query($conn, $update);
if($result == 1)
{
echo "Successfully Updated" ;
}
else
{
echo "Error in Updting value" . mysqli_error($conn) ;
}
}

?>
<html>
<head>
<title>Update User Information</title>
</head>
<body background="HomePageMap.gif">
<CENTER><B><FONT COLOR = 'RED'>SEARCH & UPDATE THE EXISTING RECORD HERE </FONT></B></CENTER><P>
<form method="POST" action="modify.php" name = "frm">
<div align="center">
<table border="1" width="314">
<tr>
<td width="130"><b>DSL Number</b></td>
<td width="168"><input type="text" name="dsl" size="20"></td>
</tr>
<tr>
<td width="130"><b>First Name</b></td>
<td width="168"><input type="text" name="First" size="20"></td>
</tr>
<tr>
<td width="130"><b>Last Name</b></td>
<td width="168"><input type="text" name="Last" size="20"></td>
</tr>
<tr>
<td width="130"><b>Civil ID</b></td>
<td width="168"><input type="text" name="cid" size="20"></td>
</tr>
<tr>
<td width="130"><b>Net Pack</b></td>
<td width="168"><select size="1" name="choice">
<option value = "2 Mbps">2 Mbps</option>
<option value = "5 Mbps">5 Mbps</option>
<option value = "10 Mbps">10 Mbps</option>
<option value = "15 Mbps">15 Mbps</option>
</select></td>
</tr>
</table>
</div>
<p align="center"><input type="submit" value="Search" name="B1">&nbsp;&nbsp;
<p align="center"><input type="submit" value="Modify" name="B2">&nbsp;&nbsp;
<input type="reset" value="Reset" name="B2"></p>
</form>
<p align="center">&nbsp;</p>
</body>

</html>

最佳答案

如果我下面的回答不起作用,试试这个:

 $update = "UPDATE homereg SET Fname = `$_POST['First']}`, Lname = `$_POST['Last']`, cid = `$_POST['cid']`, pack = `$_POST['choice']` WHERE dsl = `$_POST['dsl']`" ;

关于javascript - 更新值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45658860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com