请大侠们帮我看看这个问题出在哪?
代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><?php require_once 'header.php'; require_once 'check.php';?><meta content="en-us" http-equiv="Content-Language" /><meta content="text/html; charset=utf-8" http-equiv="Content-Type" /><title>Item Detail</title><style type="text/css">.auto-style2 { text-align: center;}.auto-style1 { font-size: 36pt; text-align: left; font-family: Default;}.auto-style3 { font-family: Broadway;}</style></head><body><?php if(isset($_POST['submit_edit_item_id'])) { $_SESSION['eidt_item_id'] = $_POST['sub_edit_item_id']; } $item_id = $_SESSION['eidt_item_id']; $result = mysql_query("SELECT * FROM ITEM WHERE ITEM_ID = $item_id"); if($result) { $row = mysql_fetch_array($result); $user_id = $_SESSION['id']; $name = $row['NAME']; $dsc = $row['DESCRIPTION']; $auc = $row['RESERVE_PRICE']; $bin = $row['BIN_PRICE']; $btime = $row['BEGIN']; $etime = $row['END']; $status = $row['STATUS']; $seller = $row['SELLER_ID']; $winner = $row['WINNER_ID']; $curr_bid = $row['CURR_BID']; $num_bid = $row['NUM_BID']; $img_id = $row['IMG_ID']; } $result = mysql_query("SELECT USER_NAME FROM USER WHERE USER_ID = $seller"); if($result) { $row = mysql_fetch_array($result); $seller_name = $row['USER_NAME']; }?> <table align="center" style="width: 100%"> <tr> <td> <div class="auto-style2"> <table align="center" style="width: 100%"> <tr> <td class="auto-style1">Edit item:</td> <td> <a href="http://acadweb1.salisbury.edu/~rwan/home.php"> <img src="/static/imghw/default1.png" data-src="logo.jpg" class="lazy" style="max-width:90%" style="float: right" style="max-width:90%" / alt="请大侠们帮我看看这个问题出在哪?" ></a></td> </tr> </table> </div> <hr /> <table style="width: 100%"> <tr> <td rowspan="2"> <?php display_image($img_id, 500, 400); ?> <form action="edit_item.php" method="post" enctype="multipart/form-data"> <table><tr><td><input type="file" name="image" /></td></tr> <tr><td><input name="sub_change_pic" type="submit" value="Change picture"> <input name="sub_del_pic" type="submit" value="Delete picture"></td></tr> </table></form> <?php if(isset($_POST['sub_change_pic'])) { if(isset($_FILES['image'])) { $file = $_FILES['image']['tmp_name']; if(!empty($file)) { $image = addslashes(file_get_contents($file)); $image_name = addslashes($_FILES['image']['name']); $image_size = getimagesize($file); if($image_size == false) { print'<p class = "error">The file is not an image.</p>'; } 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 = 1 WHERE 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']); } ?> </td> <td><form action="edit_item.php" method="post"> <textarea cols="50" name="title" rows="4"><?php print $name; ?></textarea><br> <input name="change_item_title" type="submit" value="Change item title" /></form></td> </tr> <tr> <td><hr /> <?php if(isset($_POST['change_item_title'])) { $name = $_POST['title']; mysql_query("LOCK TABLES ITEM WRITE"); mysql_query("UPDATE ITEM SET NAME = '$name' WHERE ITEM_ID = $item_id"); mysql_query("UNLOCK TABLES"); header("location: " . $_SERVER['REQUEST_URI']); } if($status == "SOLD") { $result = mysql_query("SELECT * FROM ITEM_SOLD WHERE ITEM_ID = $item_id"); $row = mysql_fetch_array($result); $buyer = $row['BUYER_ID']; if($_SESSION['id'] == $buyer) { print'<p class = "error">Congratulations! The item is yours.</p>'; } else { print'<p class = "error">Sorry, the item has been sold!</p>'; } } else if($status == "NA") { print'<p class = "error">Item is not available yet!</p>'; } else if($status == "EXPIRE") { print'<p class = "error">Item is expired.</p>'; } 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"<p><strong>Current datetime: $curr_datetime</strong></p>"; $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'<table><tr><td><form action="edit_item.php" method="post"> Change End time:</td></tr><tr><td><input type="date" name="end_date" value='.$date.'> <input type="time" name="end_time" value='.$time.'></td> <td><input type="submit" name= "go" value="Set Time"> </form></td></tr></table>'; 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(); } ?> <hr /><br /> <table><tr><td>Buy it Now Price:</td></tr> <tr><td><form action ="edit_item.php" method="post"> <input name="price" type="text" value="<?php print $bin; ?>" ></td></tr> <tr><td><input name="sub_change_price" type="submit" value="Change price" /></form></td></tr></table> <?php if(isset($_POST['sub_change_price'])) { $price = $_POST['price']; mysql_query("LOCK TABLES ITEM WRITE"); mysql_query("UPDATE ITEM SET BIN_PRICE = $price WHERE ITEM_ID = $item_id"); mysql_query("UNLOCK TABLES"); header("location: " . $_SERVER['REQUEST_URI']); } ?> </td> </tr> <tr> <td class="auto-style3" colspan="2"> <form action ="edit_item.php" method="post"> <textarea cols="80" name="description" rows="10"><?php print $dsc; ?></textarea><br> <input name="change_dsc" type="submit" value="Change item description" /></form></td> </tr> <?php if(isset($_POST['change_dsc'])) { $dsc = $_POST['description']; mysql_query("LOCK TABLES ITEM WRITE"); mysql_query("UPDATE ITEM SET DESCRIPTION = '$dsc' WHERE ITEM_ID = $item_id"); mysql_query("UNLOCK TABLES"); header("location: " . $_SERVER['REQUEST_URI']); } ?> </table> </td> </tr> </table> </body><?php require_once 'webmaster.php'; ?></html>
我不想误导大家, 但我自己的分析,认为问题出在 94-149行之间的这段php代码上。
IMAGES的表里存储的是BLOB图片,IMG_ID我设置的是自动增长的,IMG_ID为1的图片是默认的错误信息图。
每当我插入一张新的图片,名为IMAGES里面会有新的图片插入,并自动生成IMG_ID,ITEM里面的IMG_ID无法自动更新(详情见121行), 135-147行代码也是相同的问题,如果成功删除图片,无法将IMG_ID改回1。
我已经做了实验,print $item_id的值,发现$item_id的值是没有问题的。另外table的拼写也无错误。。。
难道是什么地方不小心把table lock了,而且没有unlock?可是即使lock了,我自己应该还是有权限修改的不是吗?小弟百思不得其解
麻烦各位大神帮小弟分析一下原因,小弟感激不尽
回复讨论(解决方案)
自增长id应该是不会回退的吧?
自增长id应该是不会回退的吧?
谢谢你。可以解释的详细点吗? 问题该怎么解决呢?
$pic_id = mysql_insert_id();
mysql_query("UPDATE ITEM SET IMG_ID = $pic_id WHERE ITEM_ID = $item_id");
既然 IMG_ID 是自动增长的, 那么 IMG_ID 就是主键了
主键是不可重复的!
SET IMG_ID = $pic_id 就有重复的嫌疑
至少在你的代码中没有看到对 ITEM_ID 赋值的代码
而有
$item_id = $_SESSION['eidt_item_id'];
但是也没有看到 session_start();
虽说 ITEM_ID 可能有初值,但 $item_id 为空的话将造成 SQL 指令为
UPDATE ITEM SET IMG_ID = nnnn WHERE ITEM_ID =
显然是错误的
估计是列名弄混了
斑竹 火眼金睛~
$pic_id = mysql_insert_id();
mysql_query("UPDATE ITEM SET IMG_ID = $pic_id WHERE ITEM_ID = $item_id");
既然 IMG_ID 是自动增长的, 那么 IMG_ID 就是主键了
主键是不可重复的!
SET IMG_ID = $pic_id 就有重复的嫌疑
至少在你的代码中没有看到对 ITEM_ID 赋值的代码
而有
$item_id = $_SESSION['eidt_item_id'];
但是也没有看到 session_start();
虽说 ITEM_ID 可能有初值,但 $item_id 为空的话将造成 SQL 指令为
UPDATE ITEM SET IMG_ID = nnnn WHERE ITEM_ID =
显然是错误的
估计是列名弄混了
谢谢版主大神
我解释一下我的构思
因为我想换了图片以后,立即显示出来,所以加了以下语句
header("location: " . $_SERVER['REQUEST_URI']);
但加入之后会有个问题。一旦点击换图按钮,页面就会自动刷新,刷新会导致我会丢失item_id
if(isset($_POST['submit_edit_item_id'])) { $_SESSION['edit_item_id'] = $_POST['sub_edit_item_id']; } $item_id = $_SESSION['edit_item_id'];
所以把item_id存在了SESSION['edit_item_id']里,如果item_id不是之前网页传递过来的,就直接读取存在session里的item_id,方便刷新页面以后继续使用。 至于session_start()我放在了header.php里,抱歉我没有做相关的说明。
小弟刚学网页不久,也不知道这种思路是不是正确。话说item_id,我去检查一下,是不是为空。。。
$pic_id = mysql_insert_id();
mysql_query("UPDATE ITEM SET IMG_ID = $pic_id WHERE ITEM_ID = $item_id");
既然 IMG_ID 是自动增长的, 那么 IMG_ID 就是主键了
主键是不可重复的!
SET IMG_ID = $pic_id 就有重复的嫌疑
至少在你的代码中没有看到对 ITEM_ID 赋值的代码
而有
$item_id = $_SESSION['eidt_item_id'];
但是也没有看到 session_start();
虽说 ITEM_ID 可能有初值,但 $item_id 为空的话将造成 SQL 指令为
UPDATE ITEM SET IMG_ID = nnnn WHERE ITEM_ID =
显然是错误的
估计是列名弄混了
img_id在IMAGES里确实是主键,但在ITEM表里也有一个,不是主键。
我做了下测试,如果我删除图片,ITEM表里的img_id就会变成1,即为默认图片。如果我再换图片,没有新的图片插入进去,相对的img_id会变成0。。。可能是应为没有插进去图片,所以mysql_insert_id()返回的值为0吧?
为了以防万一,我在mysql里测试了一下insert语句,发现没有语法问题啊。。。 为什么会这样啊。。。 要抓狂了。。。
对代码稍微做了点修改。。。之前还能插入图片。。。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><?php require_once 'header.php'; require_once 'check.php';?><meta content="en-us" http-equiv="Content-Language" /><meta content="text/html; charset=utf-8" http-equiv="Content-Type" /><title>Item Detail</title><style type="text/css">.auto-style2 { text-align: center;}.auto-style1 { font-size: 36pt; text-align: left; font-family: Default;}.auto-style3 { font-family: Broadway;}</style></head><body><?php if(isset($_POST['submit_edit_item_id'])) { $_SESSION['edit_item_id'] = $_POST['sub_edit_item_id']; } $item_id = $_SESSION['edit_item_id']; $result = mysql_query("SELECT * FROM ITEM WHERE ITEM_ID = $item_id"); if($result) { $row = mysql_fetch_array($result); $user_id = $_SESSION['id']; $name = $row['NAME']; $dsc = $row['DESCRIPTION']; $auc = $row['RESERVE_PRICE']; $bin = $row['BIN_PRICE']; $btime = $row['BEGIN']; $etime = $row['END']; $status = $row['STATUS']; $seller = $row['SELLER_ID']; $winner = $row['WINNER_ID']; $curr_bid = $row['CURR_BID']; $num_bid = $row['NUM_BID']; $img_id = $row['IMG_ID']; echo "item_id is $item_id"; echo "img_id is $img_id"; } $result = mysql_query("SELECT USER_NAME FROM USER WHERE USER_ID = $seller"); if($result) { $row = mysql_fetch_array($result); $seller_name = $row['USER_NAME']; }?> <table align="center" style="width: 100%"> <tr> <td> <div class="auto-style2"> <table align="center" style="width: 100%"> <tr> <td class="auto-style1">Edit item:</td> <td> <a href="http://acadweb1.salisbury.edu/~rwan/home.php"> <img src="/static/imghw/default1.png" data-src="logo.jpg" class="lazy" style="max-width:90%" style="float: right" style="max-width:90%" / alt="请大侠们帮我看看这个问题出在哪?" ></a></td> </tr> </table> </div> <hr /> <table style="width: 100%"> <tr> <td rowspan="2"> <?php display_image($img_id, 500, 400); ?> <form action="edit_item.php" method="post" enctype="multipart/form-data"> <table><tr><td><input type="file" name="image" /></td></tr> <tr><td><input name="sub_change_pic" type="submit" value="Change picture"> <input name="sub_del_pic" type="submit" value="Delete picture"></td></tr> </table></form> <?php if(isset($_POST['sub_change_pic'])) { if(isset($_FILES['image'])) { $file = $_FILES['image']['tmp_name']; if(!empty($file)) { $image = addslashes(file_get_contents($file)); $image_name = addslashes($_FILES['image']['name']); $image_size = getimagesize($file); if($image_size == false) { print'<p class = "error">The file is not an image.</p>'; } 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 = 1 WHERE 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']); } ?> </td> <td><form action="edit_item.php" method="post"> <textarea cols="50" name="title" rows="4"><?php print $name; ?></textarea><br> <input name="change_item_title" type="submit" value="Change item title" /></form></td> </tr> <tr> <td><hr /> <?php if(isset($_POST['change_item_title'])) { $name = $_POST['title']; mysql_query("LOCK TABLES ITEM WRITE"); mysql_query("UPDATE ITEM SET NAME = '$name' WHERE ITEM_ID = $item_id"); mysql_query("UNLOCK TABLES"); header("location: " . $_SERVER['REQUEST_URI']); } if($status == "SOLD") { $result = mysql_query("SELECT * FROM ITEM_SOLD WHERE ITEM_ID = $item_id"); $row = mysql_fetch_array($result); $buyer = $row['BUYER_ID']; if($_SESSION['id'] == $buyer) { print'<p class = "error">Congratulations! The item is yours.</p>'; } else { print'<p class = "error">Sorry, the item has been sold!</p>'; } } else if($status == "NA") { print'<p class = "error">Item is not available yet!</p>'; } else if($status == "EXPIRE") { print'<p class = "error">Item is expired.</p>'; } 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"<p><strong>Current datetime: $curr_datetime</strong></p>"; $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'<table><tr><td><form action="edit_item.php" method="post"> Change End time:</td></tr><tr><td><input type="date" name="end_date" value='.$date.'> <input type="time" name="end_time" value='.$time.'></td> <td><input type="submit" name= "go" value="Set Time"> </form></td></tr></table>'; 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(); } ?> <hr /><br /> <table><tr><td>Buy it Now Price:</td></tr> <tr><td><form action ="edit_item.php" method="post"> <input name="price" type="text" value="<?php print $bin; ?>" ></td></tr> <tr><td><input name="sub_change_price" type="submit" value="Change price" /></form></td></tr></table> <?php if(isset($_POST['sub_change_price'])) { $price = $_POST['price']; mysql_query("LOCK TABLES ITEM WRITE"); mysql_query("UPDATE ITEM SET BIN_PRICE = $price WHERE ITEM_ID = $item_id"); mysql_query("UNLOCK TABLES"); header("location: " . $_SERVER['REQUEST_URI']); } ?> </td> </tr> <tr> <td class="auto-style3" colspan="2"> <form action ="edit_item.php" method="post"> <textarea cols="80" name="description" rows="10"><?php print $dsc; ?></textarea><br> <input name="change_dsc" type="submit" value="Change item description" /></form></td> </tr> <?php if(isset($_POST['change_dsc'])) { $dsc = $_POST['description']; mysql_query("LOCK TABLES ITEM WRITE"); mysql_query("UPDATE ITEM SET DESCRIPTION = '$dsc' WHERE ITEM_ID = $item_id"); mysql_query("UNLOCK TABLES"); header("location: " . $_SERVER['REQUEST_URI']); } ?> </table> </td> </tr> </table> </body><?php require_once 'webmaster.php'; ?></html>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

PHP日志记录对于监视和调试Web应用程序以及捕获关键事件,错误和运行时行为至关重要。它为系统性能提供了宝贵的见解,有助于识别问题并支持更快的故障排除

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

文章讨论了PHP 5.3中引入的PHP中的晚期静态结合(LSB),从而允许静态方法的运行时分辨率调用以获得更灵活的继承。 LSB的实用应用和潜在的触摸
