dsuvs66406 2011-10-10 06:52
浏览 20
已采纳

如何在PHP中更新单行?

I have 2 buttons, approve and reject to update booking status. I am lost when trying to pass value to approve_booking.php. Have no idea how to update single row according to bookingID. Need help on coding!!!

index.php

<head>
<script src="jquery-latest.js" type="text/javascript"></script>
<script src="jquery.tablesorter.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$("#myTable").tablesorter({widgets: ['zebra']});
});

$(document).ready(function() 
{ 
    $("#myTable").tablesorter(); 
} 
);

$(document).ready(function() 
{ 
    $("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} ); 
} 
);
</script>
<link href="style.css" rel="stylesheet" type="text/css">
<link href="stylelogin.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="form1" method="post" action="approve_booking.php" >
<?php

$db = new mysqli("localhost", "root", "", "eventdb");

$query = "SELECT customer.companyName, customer.contactName,eventinfo.eventTitle,boothAlias,date, testbook.bstatus, testbook.username, bookingID  from eventinfo, testbook, customer where testbook.username=customer.username AND testbook.eventID=eventinfo.eventID";

$result = $db->query($query, MYSQLI_STORE_RESULT);

$o = '<table id="myTable" class="tablesorter" width="660px"><thead><tr><th>Company Name</th><th>Contact Name</th><th>Event</th><th>Booth</th><th>Date</th><th>Status</th></tr></thead><tbody>';

while(list($companyName, $contactName, $eventTitle, $boothAlias, $date, $bstatus,$bookingID) = $result->fetch_row()) {

if($bstatus==0){
    $status="Pending";
}else if($bstatus==1){
    $status="Successful";
}else{
    $status="Reject";
}


$o .= '<tr><td width="120px">'.$companyName.'</td><td width="120px">'.$contactName.'</td><td width="180px">'.$eventTitle.'</td><td width="70px">'.$boothAlias.'</td><td width="170px">'.$date.'</td><td width="70">'.$status.'</td><td width="100"><input width="100px" name="APPROVED" type="submit" id="APPROVED" value="Approve"> <input width="100px" name="REJECT" type="submit" id="REJECT" value="Reject"></td></tr>';
}

$o .= '</tbody></table>';

echo $o;
?>
</form>
</body>

approve_booking.php

<?php

mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("eventdb") or die (mysql_error());

if(isset($_POST['APPROVED']))
    {

        $query2 = "UPDATE testbook SET bstatus ='0' WHERE bookingID='$_POST[booking]'";
            $result2 = @mysql_query($query2);
    }


if (isset($_POST['REJECT']))
    {
        $query3 = "UPDATE testbook SET bstatus ='2' WHERE bookingID='$_POST[booking]'";
            $result3 = @mysql_query($query3);

    }



?>

http://i.stack.imgur.com/0KGLB.jpg

  • 写回答

4条回答 默认 最新

  • dou12352 2011-10-10 06:56
    关注

    If booking id is your auto increament / primary key so it update only single row but if its not then use your primary key in WHERE condition so it can find and update only 1 row.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思