PHP更新sql记录
我在尝试更新sql数据库中的记录时,不知怎的出现了sql错误 这是我目前的密码 html格式:PHP更新sql记录,php,html,sql,Php,Html,Sql,我在尝试更新sql数据库中的记录时,不知怎的出现了sql错误 这是我目前的密码 html格式: <html> <head> <title>title here</title> </head> <body> <form action="end.php" method="POST"> <input type="text" id="comment" name="comment" placeholder="Komm
<html>
<head>
<title>title here</title>
</head>
<body>
<form action="end.php" method="POST">
<input type="text" id="comment" name="comment" placeholder="Kommentar"><p>
<input type="submit" value="Stop arbejde">
</form>
</body>
</html>
标题在这里
end.php
<?php
$host="localhost";
$username="root";
$password="password";
$db_name="db";
$tbl_name="log";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$comment=$_POST['comment'];
$datetime=date("y/m/d H:i:s");
$editit=date("W/D");
$sql="UPDATE log SET end=$datetime, comment=$comment WHERE editid='$editit'";
$result=mysql_query($sql);
if($result){
echo "Successful<BR>";
}
else {
echo "Fejl";
}
mysql_close();
?>
字符串必须用单引号括起来
$sql="UPDATE log SET end='$datetime', comment='$comment' WHERE editid='$editit'";
但是您的查询很容易进行SQL注入
。请花点时间阅读下面的文章
$sql中的变量名应位于单个倒置的COMA中
$sql="UPDATE log SET end='$datetime', comment='$comment' WHERE editid='$editit'";
而且,您应该在表单标记中从html代码中删除段落标记。我认为在PHP中,您必须在字符串中的变量名周围添加{}或使用“+$var+”?看看您的$sql字符串again@GeneParmesan: Incorrect@OptimusCrime我知道必须对sql字符串和变量进行处理。显然,它们只需要单引号。@geneparmasan:这是正确的,但在PHP中,变量可以包含在双引号中。