Little brother just learned PHP soon, wrote the following code, you heroes laughed at.
The approximate function of the code is the picture and text displayed on the current page modification page. Text messages and picture information are stored in MySQL's corresponding table.
<title>Item Detail</title>
| The file is not an image.';} Else{mysql_query ("Lock TABLES IMAGES write") mysql_query ("Lock TABLES ITEM write"), if ($img _id = = 1) {mysql_query (" INSERT into IMAGES (Img_name, IMG) VALUES (' $image _name ', ' $image '), $pic _id = mysql_insert_id (); mysql_query ("UPDATE ITEM SET img_id = $pic _id WHERE item_id = $item _id ");} Else{mysql_query ("UPDATE IMAGES SET img_name = ' $image _name ', IMG = ' $image ' WHERE img_id = $img _id");} mysql_query ("UNLOCK TABLES"); Header ("Location:".) $_server[' Request_uri ');}}} if (Isset ($_post[' sub_del_pic ')) {mysql_query ("LOCK TABLES item WRITE"); mysql_query ("UPDATE item SET img_id = 1WHERE item_id = $item _id "), if ($img _id! = 1) {mysql_query (" LOCK TABLES IMAGES WRITE ") mysql_query (" DELETE from IMAGES WHERE img_i D = $img _id ");} mysql_query ("UNLOCK TABLES"); Header ("Location:".) $_server[' Request_uri ');}? > |
|
| congratulations! The item is yours.';} Else{print ' Sorry, the item has been sold! ';}} else if ($status = = "NA") {print 'Item is not available yet! ';} else if ($status = = "EXPIRE") {print 'Item is expired. ';} Else{date_default_timezone_set (' america/new_york '); $curr _date = Date ("y-m-d"), $curr _time = Date ("H:i"); $curr _ datetime = "$curr _date $curr _time:00";p rint "Current datetime: $curr _datetime "; $result = mysql_query (" select * from ITEM WHERE item_id = $item _id "), if ($result) {$row = Mysql_fetch_array ($result); $bti me = Strtotime ($row [' BEGIN ']), $etime = Strtotime ($row [' END ']), $date = Date ("y-m-d", $etime), $time = Date ("H:i", $etime);} Print
'; if ($_post[' go '] = = "Set time") {$end _date = $_post[' end_date '); $end _time = $_post[' end_time ']; $end _time = $end _time. ': 0 0 '; $end _datetime = Strtotime ("$end _date $end _time"), $now = Strtotime ($default _datetime); $problem = False;if ($end _ DateTime <= $now) {print ' Cannot set End time earlier than current time! '; $problem = true;} if (! $problem) {mysql_query ("LOCK TABLES item WRITE") mysql_query ("UPDATE item SET END = ' $end _date $end _time ' WHERE item_i D = $item _id "); mysql_query (" UNLOCK TABLES "); Header (" Location: ". $_server[' Request_uri ');}} Refresh ();}? >
|
|
|
Question: section
120 RowsWhy can't I execute the insert command? What causes? How to solve?
Reply to discussion (solution)
Own more echo output and see what the return value of mysql_query () is?
mysql_query ("INSERT into IMAGES (Img_name, IMG) VALUES (' $image _name ', ' $image ')");
and
$image = Addslashes (file_get_contents ($file));
$file is obviously a binary file
So just addslashes for MySQL 5 is not possible (MySQL 4 can)
Because most non-printable ASCII characters can affect MySQL's behavior
If the picture data must be stored in the database, then the base64 encoding of the image data should be stored