2017-11-10 5 views
0

내 업데이트 성명이 작동하지 않습니다. "RECORD UPDATED"를 표시하지만 테이블을 업데이트하지는 않습니다. 여기에 코드가 있습니다. 제발 도와주세요.WHILE 루프 및 배열을 사용하는 PHP 업데이트 문

<?php 
$db=mysqli_connect("localhost","root","")or die("Connection error"); 
mysqli_select_db($db,"suhaib")or die("dbase error"); 

연관 배열을 생성하고 테이블을 업데이트 WHILE 루프를

<?php 
if(isset($_GET['edit'])){ 
$sql=$db->query("SELECT * FROM forma"); 
while($result=mysqli_fetch_assoc($sql)){ 
?> 
<form name="update1" action="" method="GET"> 
DataNumber:<input type="text" name="datanum" 
value="<?php echo $result['datanumber']; ?>"> 
Date:<input type="text" name="date" value="<?php echo $result['date']; ?>"> 
Type:<input type="text" name="type" value="<?php echo $result['type']; ?>"> 
Subject:<input type="text" name="subject" 
value="<?php echo $result['subject']; ?>"> 
Amount:<input type="text" name="amount" 
value="<?php echo $result['amount']; ?>"> 
SOE:<input type="text" name="soe" value="<?php echo $result['soe']; ?>"> 
Note:<input type="text" name="note" value="<?php echo $result['note']; ?>"> 
Liquidate:<input type="text" name="liquidate" 
value="<?php echo $result['liuidatedate']; ?>"> 
Checker Info:<input type="text" name="checkerinfo" 
value="<?php echo $result['checkerinfo']; ?>"> 
Accounting Info:<input type="text" name="accountingconfir" 
value="<?php echo $result['accountingconfir']; ?>"> 
<input type="submit" value="update" name="upd"> 
</form> 
<?php }} ?> 

업데이트 문을 실행. 표가 업데이트되지 않는 그러나 "RECORD 업데이트"라는 메시지를 보여줍니다

if(isset($_GET['upd'])){ 
$datanum=$_GET['datanum']; 
$date=$_GET['date']; 
$type=$_GET['type']; 
$subject=$_GET['subject']; 
$amount=$_GET['amount']; 
$soe=$_GET['soe']; 
$note=$_GET['note']; 
$liquidate=$_GET['liquidate']; 
$checkerinfo=$_GET['checkerinfo']; 
$accounting=$_GET['accountingconfir']; 

$up="UPDATE forma SET datanumber='$datanum' , date='$date' , 
type='$type' , subject='$subject' , 
amount='$amount', soe='$soe' , note='$note', liuidatedate='$liquidate' , 
checkerinfo='$checkerinfo', accountingconfir='$accounting'"; 
mysqli_query($db, $up); 
echo "record updated"; 
+0

전체 테이블 데이터 또는 특정 ID를 업데이트하십시오. – Bhargav

+0

HTML에 올바르게 색을 지정하는 방법에 대해 질문하는' ArtisticPhoenix

+0

mysqli_query ($ db, $ up) 또는 die (mysqli_error ($ db)); ' – Barmar

답변

0

이궁, 여기에 아주 중요한 누락 된 것을

$up="UPDATE 
     forma 
    SET 
     datanumber='$datanum', 
     date='$date', 
     type='$type', 
     subject='$subject', 
     amount='$amount', 
     soe='$soe', 
     note='$note', 
     liuidatedate='$liquidate' , 
     checkerinfo='$checkerinfo', 
     accountingconfir='$accounting'"; 

당신이 당신의 데이터베이스에있는 모든 데이터를 덮어 쓰기 위해 노력하지 않는 내 말은 . 당신은 그것을 보십니까 ...

Where ... ? 

WHERE 절을 생략하면 모든 행이이 데이터로 업데이트됩니다. 희망

  • 당신은 당신이
  • 하여 여전히 사용하여 테스트 데이터 테스트 사이트
  • 쿼리가 깨진에 백업이이 (unlikly)
  • 의도.

는 또한 중 하나는 구문 오류

if(isset($_GET['upd'])){ 
    .... 

에게 귀하의 질문에 폐문 }이없는 질문에 코드의 일부를 놓친 나. 문제에 관해서는

, 나는이

<?php //right at top of php after the tag 
    error_reporting(-1); 
    ini_set('display_errors', 1); 

처럼 PHP는 무엇이 잘못되었는지를 알려줍니다이 방법을 오류보고 및 디스플레이 오류를 켜는 것이 좋습니다.