请大侠们帮我看看这个问题出在哪?
代码如下
<!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 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제









Laravel은 직관적 인 플래시 방법을 사용하여 임시 세션 데이터 처리를 단순화합니다. 응용 프로그램에 간단한 메시지, 경고 또는 알림을 표시하는 데 적합합니다. 데이터는 기본적으로 후속 요청에만 지속됩니다. $ 요청-

PHP 클라이언트 URL (CURL) 확장자는 개발자를위한 강력한 도구이며 원격 서버 및 REST API와의 원활한 상호 작용을 가능하게합니다. PHP CURL은 존경받는 다중 프로모토콜 파일 전송 라이브러리 인 Libcurl을 활용하여 효율적인 execu를 용이하게합니다.

Laravel은 간결한 HTTP 응답 시뮬레이션 구문을 제공하여 HTTP 상호 작용 테스트를 단순화합니다. 이 접근법은 테스트 시뮬레이션을보다 직관적으로 만들면서 코드 중복성을 크게 줄입니다. 기본 구현은 다양한 응답 유형 단축키를 제공합니다. Illuminate \ support \ Facades \ http를 사용하십시오. http :: 가짜 ([ 'google.com'=> 'Hello World', 'github.com'=> [ 'foo'=> 'bar'], 'forge.laravel.com'=>

Laravel의 서비스 컨테이너 및 서비스 제공 업체는 아키텍처의 기본입니다. 이 기사는 서비스 컨테이너, 세부 정보 서비스 제공 업체 생성, 등록 및 예제와 함께 실질적인 사용을 보여줍니다. 우리는 ove로 시작합니다

고객의 가장 긴급한 문제에 실시간 인스턴트 솔루션을 제공하고 싶습니까? 라이브 채팅을 통해 고객과 실시간 대화를 나누고 문제를 즉시 해결할 수 있습니다. 그것은 당신이 당신의 관습에 더 빠른 서비스를 제공 할 수 있도록합니다.

PHP 로깅은 웹 애플리케이션을 모니터링하고 디버깅하고 중요한 이벤트, 오류 및 런타임 동작을 캡처하는 데 필수적입니다. 시스템 성능에 대한 귀중한 통찰력을 제공하고 문제를 식별하며 더 빠른 문제 해결을 지원합니다.

기사는 PHP 5.3에 도입 된 PHP의 LSB (Late STATIC BING)에 대해 논의하여 정적 방법의 런타임 해상도가보다 유연한 상속을 요구할 수있게한다. LSB의 실제 응용 프로그램 및 잠재적 성능

이 기사에서는 프레임 워크에 사용자 정의 기능 추가, 아키텍처 이해, 확장 지점 식별 및 통합 및 디버깅을위한 모범 사례에 중점을 둡니다.
