2017-11-10 17 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 }} ?> 

UPDATE文を実行しています。表は更新されていないが、それは「レコードが更新」メッセージが表示さ

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に正しく色付けされるように、 '<?php'タグを追加しました。 – 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は、何が間違っていることを教えてくれます。

関連する問題