我有以下更新查询但由于某种原因它无法正常工作。我认为这与" id ='"。$ id。"'有关。但我尝试了三种不同的方式,似乎无法让它发挥作用。我以前写过更新查询没有任何问题,但由于某种原因,这个问题很痛苦。提前致谢。
$id = $_GET['id'];
$speaker = mysql_real_escape_string($_POST['speaker']);
$message = $_POST['message'];
$title = mysql_real_escape_string($_POST['title']);
$date = $_POST['date'];
$day = $_POST['day'];
$password = mysql_real_escape_string($_POST['password']);
$complete = $_POST['complete'];
$title = ucwords(strtolower($title));
if ($complete && ($password == "*****"))
{
$db = mysql_connect($hostname, $username, $password) or die(mysql_error());
mysql_select_db($dbname,$db) or die(mysql_error());
mysql_query("UPDATE sermons SET speaker = '$speaker', message = '$message', title = '$title', date = '$date', day = '$day' WHERE id = '$id'");
$num_rows = mysql_num_rows(mysql_query("SELECT speaker, message, title, date, day FROM sermons WHERE speaker = '$speaker' AND message = '$message' AND title = '$title' AND date = '$date' AND day = '$day'", $db));
if ($num_rows == 1)
echo "<script type='text/javascript'> alert('Sermon Information Entered Successfully!'); </script>";
else
echo "<script type='text/javascript'> alert('Error! Please Try Again.'); </script>";
}
else if ($complete && ($password != "*****"))
{
echo "<script type='text/javascript'> alert('Incorrect Password! Please Try Again.'); </script>";
}
答案 0 :(得分:0)
因为id是Integer,所以这是正确的代码尝试:
mysql_query(&#34; UPDATE布道SET演讲者=&#39; $ speaker&#39;,message =&#39; $ message&#39;,title =&#39; $ title&#39;,date = &#39; $ date&#39;,day =&#39; $ day&#39; WHERE id =&#34;。$ id);
我预计它会有效。
答案 1 :(得分:0)
将此作为答案写为答案,因为在评论中提供代码很难阅读
尝试更改
mysql_query("UPDATE sermons SET speaker = '$speaker', message = '$message', title = '$title', date = '$date', day = '$day' WHERE id = '$id'");
要
mysql_query("UPDATE sermons SET speaker = '$speaker', message = '$message', title = '$title', date = '$date', day = '$day' WHERE id = '$id'") or die(mysql_error());
然后将错误消息添加到您的问题中。