我有这个问题
错误
Could not update data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ..... line 1.
这是代码
<html>
<head>
<title>Update a Record in MySQL Database</title>
</head>
<body>
<?php
if(isset($_POST['update']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'catalog';
$conn = mysql_connect($dbhost, $dbuser, $dbpass,$db);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$adresa_e = $_POST['ADRESAE'];
$nr_matricol = $_POST['NR_MATRICOL'];
$sql = "UPDATE elevi ".
"SET ADRESAE = $adresa_e ".
"WHERE NR_MATRICOL = $nr_matricol" ;
mysql_select_db('catalog');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">ADRESA ELEV</td>
<td><input name="ADRESAE" type="text" id="ADRESAE"></td>
</tr>
<tr>
<td width="100">NR MATRICOL</td>
<td><input name="NR_MATRICOL" type="text" id="NR_MATRICOL"></td>
</tr>
<tr>
<td width="100"></td>
<td></td>
</tr>
<tr>
<td width="100"></td>
<td><input name="update" type="submit" id="update" value="Update"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
变量在您的请求中被视为简单文本:
试试这个
$sql = "UPDATE elevi SET ADRESAE = '".$adresa_e."' WHERE NR_MATRICOL = '".$nr_matricol."'" ;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句