简体   繁体   中英

php form updating mysql

I am trying to update a mysql database with new information from an edit form I created. I cant put my finger on whats wrong. The code is popping a mysql error. 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. 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" ).

I removed the $ from in-front of season and it went thought and now its all working. Thanks for the 2nd set of eyes :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM