我有4个名为offerId, AffId, status和deduction的文本框,它从数据库中获取数据并显示5行。表单的每一行都有一个“更新条目”按钮,因此,如果用户编辑文本框的数据并单击更新按钮,则会针对该offerId和。我面临的问题是我的脚本,该脚本更新数据以获取最后一行的AffId和offerId的值(在表单中显示),并更新状态并对其进行推论。如何使用按下按钮所输入的值,并在数据库中对其进行更新?我的表单的脚本以及将我的表单更新到数据库的脚本如下所示:<?phpinclude('adodb/adodb.inc.php');echo '<h1>Mxpresso Revenue Management Solution</h1>';echo '<img src="http://mxpresso.com/images/logo.png" alt="mxpresso logo" style="width:171px;height:108px;">';echo '<h2>1. To See existing records</h2>';$db=NewADOConnection('mysql');$db->Connect("127.0.0.1", "vcc", "abc", "vcc");$sql="select * from rev";$result = $db->Execute($sql);if ($result === false) die("failed2");$records=array();$count=$result->RecordCount();echo "Total Records Found :".$count."<br>";echo '<form action="rev_insert.php" > <input type="submit" value="Add Entry"> </form>';if($count > 0) { for ($x=0;$x<$count;$x++) { $offerId=$result->fields[0]; $affId=$result->fields[1]; $status=$result->fields[2]; $deduction=$result->fields[3]; echo '<form target="_blank" action="updatecopy.php" method="get"> <table id="dataTable" class="form" border="1"> <tbody><tr> <p> <td><input type="checkbox" required="required" name="chk[]" checked="checked"></td> <td> <h4>OfferID</h4> <input type="text" name="offerId" value='.$offerId.' > </td> <td> <h4>ffId</h4> <input type="text" name="affId" value='.$affId.' > </td> <td> <h4>deduction:</h4> <input type="text" name="deduct" value='.$deduction.' > </td> <td> <h4>Status</h4> <input type="text" name="status" value='.$status.' > </select> </td> </p> </tr> </tbody> </table> <input type="submit" value="Update Entry">'; $rec=array("offerId"=>$offerId,"affiliate_id"=>$affId,"status"=>$status, "deduction"=>$deduction); array_push($records,$rec); $result->MoveNext(); } }?>更新的脚本:<?phpinclude('adodb/adodb.inc.php');function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL;}$url=curPageURL();$str = parse_url($url, PHP_URL_QUERY );parse_str($str);$db=NewADOConnection('mysql');//$db->debug = true;echo "created DB connection";$db->Connect("127.0.0.1", "vcc", "abc", "vcc");$sql="update rev set deduction=".$deduct.", status=".$status." where offerId='".$offerId."' and affId='".$affId."';";echo "SQL Query:".$sql; $result = $db->Execute($sql); if ($result === false) die("Failed to Update. Check if OfferId and AffID are correct");?> (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 在为所有行创建单独的表单时。您可以更改URL或简单地添加两个隐藏的输入,当您单击“提交”按钮时,这些输入将被提交。然后在脚本中使用它来标识要更新的行。修复-在HTML方面:1.关闭表单标签。2.如果添加额外的输入字段+一些JS:<input type='hidden' name='update_for_offerid' value='<?php echo $offId?>'><input type='hidden' name='update_for_affid' value='<?php echo $affId?>'>如果只是更改提交网址:echo '<form target="_blank" action="updatecopy.php&update_for_offerid=$offId&update_for_affid=$affId" method="get">在脚本方面:(仅在GET中使用传递的var,而不是loop的变量)$sql="update rev set deduction=".$_GET['deduct'].", status=".$_GET['status']." where offerId='".$_GET['update_for_offerid']."' and affId='".$_GET['update_for_affid']."';"希望它能解决您的问题,请尝试让我知道。 (adsbygoogle = window.adsbygoogle || []).push({}); 08-08 08:08