[英]php form updating mysql
I am trying to update a mysql database with new information from an edit form I created. 我正在尝试使用我创建的编辑表单中的新信息更新mysql数据库。 I cant put my finger on whats wrong. 我不能把手指放在哪里出了问题。 The code is popping a mysql error. 该代码弹出一个mysql错误。 Any ideas? 有任何想法吗?
<?php
// connect to datebase
require "episodelist.db.php";
// real escape all strings
$season_num = mysql_real_escape_string($_POST['season_num']);
$eps_num = mysql_real_escape_string($_POST['eps_num']);
$temp_eps_num = mysql_real_escape_string($_POST['temp_eps_num']);
$title = mysql_real_escape_string($_POST['title']);
$inspired = mysql_real_escape_string($_POST['inspired']);
$descrip = mysql_real_escape_string($_POST['descrip']);
// update data in mysql database
$sql="UPDATE $season SET season_num='$season_num', eps_num='$eps_num', temp_eps_num='$temp_eps_num', title='$title', inspired='$inspired', descrip='$descrip' WHERE id='$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";$result=mysql_query($sql);
echo "<a href='../episodelist_superadmin.html'>View result</a>";
}
else {
echo "Whoops: " . mysql_error(); ;
}
mysql_close();
?>
You don't appear to be defining $season
anywhere. 您似乎没有在任何地方定义$season
。 As a result it's causing problems with your query syntax. 结果,这会导致查询语法出现问题。
Personally I would avoid putting variables directly in strings and instead concatenate them ( "string".$var."more string"
). 就我个人而言,我避免将变量直接放在字符串中,而是将它们连接起来( "string".$var."more string"
)。
I removed the $ from in-front of season and it went thought and now its all working. 我从赛季开始前删除了美元,然后开始思考,现在一切正常。 Thanks for the 2nd set of eyes :) 感谢第二组的眼睛:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.