Could you please help me see what this problem is? The code is as follows:
Item Detail
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'])){echo "delete click";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_ID = $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";print"Current datetime: $curr_datetime ";$result = mysql_query("SELECT * FROM ITEM WHERE ITEM_ID = $item_id");if($result){$row = mysql_fetch_array($result);$btime = 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.':00';$end_datetime = strtotime("$end_date $end_time");$now = strtotime($default_datetime);$problem = false;if ($end_datetime <= $now){print'You 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_ID = $item_id");mysql_query("UNLOCK TABLES");header("location: " . $_SERVER['REQUEST_URI']);}}refresh();}?>
|
|
|
I don't want to mislead everyone, but I think the problem lies in my own analysis.
94-149The php code between lines.
In the IMAGES table, blob images are stored, while IMG_ID is set to automatically increase. IMAGES with IMG_ID 1 are default error messages.
Every time I insert a new image named IMAGES, a new image is inserted and IMG_ID is generated automatically. the IMG_ID in the ITEM cannot be automatically updated (see row 121 for details ),
135-147The same is true for line code. if you delete an image successfully, you cannot change IMG_ID to 1.
I have already done an experiment, print $ item_id value, and found that the value of $ item_id is correct. In addition, the spelling of the table is correct...
Why did we accidentally lock the table without unlock? But even if I lock it, I should still have the permission to modify it, right? The younger brother is puzzled
I am very grateful to you for helping me analyze the cause.
Reply to discussion (solution)
Self-growth id should not be rolled back, right?
Self-growth id should not be rolled back, right?
Thank you. Can I explain the details? How can this problem be solved?
$ Pic_id = mysql_insert_id ();
Mysql_query ("update item set IMG_ID = $ pic_id WHERE ITEM_ID = $ item_id ");
Since IMG_ID increases automatically, IMG_ID is the primary key.
Primary keys cannot be repeated!
SET IMG_ID = $ pic_id indicates duplicate data.
At least you do not see the code that assigns values to ITEM_ID in your code.
However
$ Item_id = $ _ SESSION ['eidt _ item_id '];
However, session_start ();
Although ITEM_ID may have an initial value, if $ item_id is null, the SQL command is
Update item set IMG_ID = nnnn WHERE ITEM_ID =
It is obviously wrong.
It is estimated that the column name is mixed up.
Bamboo eyes ~
$ Pic_id = mysql_insert_id ();
Mysql_query ("update item set IMG_ID = $ pic_id WHERE ITEM_ID = $ item_id ");
Since IMG_ID increases automatically, IMG_ID is the primary key.
Primary keys cannot be repeated!
SET IMG_ID = $ pic_id indicates duplicate data.
At least you do not see the code that assigns values to ITEM_ID in your code.
However
$ Item_id = $ _ SESSION ['eidt _ item_id '];
However, session_start ();
Although ITEM_ID may have an initial value, if $ item_id is null, the SQL command is
Update item set IMG_ID = nnnn WHERE ITEM_ID =
It is obviously wrong.
It is estimated that the column name is mixed up.
Thank you, moderator
Let me explain my ideas.
Because I want to display the image immediately after changing the image, the following statement is added:
Header ("location:". $ _ SERVER ['request _ URI ']);
But there will be a problem after joining. Once you click the Change chart button, the page will be automatically refreshed. refreshing will cause the item_id to be lost.
if(isset($_POST['submit_edit_item_id'])){$_SESSION['edit_item_id'] = $_POST['sub_edit_item_id'];}$item_id = $_SESSION['edit_item_id'];
Therefore, the item_id is stored in SESSION ['edit _ item_id ']. if item_id is not transmitted from a previous webpage, the item_id in the session is directly read, so that you can continue to use it after refreshing the page. As for session_start (), I put it in header. php. sorry, I didn't provide relevant instructions.
The younger brother has just learned the webpage and does not know whether this idea is correct. In other words, item_id. let me check if it is null...
$ Pic_id = mysql_insert_id ();
Mysql_query ("update item set IMG_ID = $ pic_id WHERE ITEM_ID = $ item_id ");
Since IMG_ID increases automatically, IMG_ID is the primary key.
Primary keys cannot be repeated!
SET IMG_ID = $ pic_id indicates duplicate data.
At least you do not see the code that assigns values to ITEM_ID in your code.
However
$ Item_id = $ _ SESSION ['eidt _ item_id '];
However, session_start ();
Although ITEM_ID may have an initial value, if $ item_id is null, the SQL command is
Update item set IMG_ID = nnnn WHERE ITEM_ID =
It is obviously wrong.
It is estimated that the column name is mixed up.
Img_id is indeed the primary key in IMAGES, but there is also one in the ITEM table, not the primary key.
I did a test. if I delete an image, the img_id in the ITEM table will change to 1, which is the default image. If I change the image again and no new image is inserted, the relative img_id will change to 0... It may be because the image is not inserted, so the value returned by mysql_insert_id () is 0, right?
Just in case, I tested the insert statement in mysql and found no syntax problems... Why... Crazy...
Slightly modified the code... Before, you can insert images...
Item Detail
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_ID = $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";print"Current datetime: $curr_datetime ";$result = mysql_query("SELECT * FROM ITEM WHERE ITEM_ID = $item_id");if($result){$row = mysql_fetch_array($result);$btime = 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.':00';$end_datetime = strtotime("$end_date $end_time");$now = strtotime($default_datetime);$problem = false;if ($end_datetime <= $now){print'You 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_ID = $item_id");mysql_query("UNLOCK TABLES");header("location: " . $_SERVER['REQUEST_URI']);}}refresh();}?>
|
|
|