PHP:使用脚本更新数据库

时间:2011-05-18 14:46:12

标签: php

您好我的小PHP脚本问题。我试图让我的用户改变"工作的状态"所以我不得不使用选项和发布。

我可以得到选项答案,但不是id。那么如何将id传递给新的脚本以下是脚本。

<?php
$conx; //connection object to the server
$comd;//instance of a command object
$sql; //string variable to hold the SQL commands
$itemsAdded; //numeric var to hold num records added to table (1 or 0)
$dbpath;

$db = realpath("../Database/iceserv.mdb");

$conn = new COM('ADODB.Connection') or exit('Cannot start ADO.');

$connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=$db";

$conn->Open($connStr);

$sql = "SELECT callback.*,  status.stat_disc AS Status
FROM callback INNER JOIN  status ON callback.callback_STATID = status.stat_ID";

$rs = $conn->Execute($sql);
if (!$rs) {exit("Error in SQL");}
echo "<form method='post' action='../scripts/update_stat.php' id='status' name='status'><table><tr>";
echo "<th> Cutomer ID</th>";
echo "<th>Customer First Name</th>";
echo "<th>Customer Surname</th>";
echo "<th>Customer Phone Number</th>";
echo "<th>Customer Reason For Callback</th>";
echo "<th>Callback Status</th>";
echo "<th>Change Status</th>";
echo "<th></th>";

while (!$rs->EOF) {

     $callid=$rs->Fields['callback_ID']->Value;
     //echo $callid;
     $fname=$rs->Fields['callback_fname']->Value;
     $sname=$rs->Fields['callback_sname']->Value;
     $phone=$rs->Fields['callback_phnum']->Value;
     $reason=$rs->Fields['callback_reason']->Value;
     $status=$rs->Fields['Status']->Value;
     echo "<tr><td align='center'>$callid</td>";
     echo "<td align='center'>$fname</td>";
     echo "<td align = 'center'>$sname</td>";
     echo "<td align = 'center'>$phone</td>";
     echo "<td align = 'center'>$reason</td>";
     echo "<td align = 'center'>$status</td>";
     //echo "<td align = 'center'><input type='text' name='calledid' value = '$callid'></td>";
     echo"<td align = 'center'><select name ='status' size='1'>
     <option value =''>Choose status</option>
     <option value ='1'>Open </option>
     <option value ='2'>Waiting Qoute</option>
     <option value ='3'>Closed </option></td>
     </select>";
     echo  "<td><input type='submit' name='submit_btn' id='submit_btn' value='Update' class='submit_btn1'</input></td></tr></table></form>";

  exit;
  }
?>

所以上面的脚本正在调用并从数据库中提取信息

    <?php

    //variable listing and usage
    $conx; //connection object to the server
    $comd;//instance of a command object
    $sql_comd; //string variable to hold the SQL commands
    $itemsAdded; //numeric var to hold num records added to table (1 or 0)
    $dbpath;

        $db = realpath("../Database/iceserv.mdb");

        $conn = new COM('ADODB.Connection') or exit('Cannot start ADO.');

        $connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=$db";

        $conn->Open($connStr);
              $id = $_POST['callid'];
              echo "ID is " +$id;
              $option= $_POST['status'];

    $sql_comd="UPDATE callback
    SET callback_STATID=$option
    WHERE callback_ID=$id
    ";
    $conn->Execute($sql_comd);

//$result = null;
$conn = null;

header('Location: ../admin/callback.php');

?>

上面的脚本正在尝试更新表但id没有通过,那么如何将ID传递给脚本呢?

请问我是否不清楚

2 个答案:

答案 0 :(得分:0)

您可以设置选择的值,如:<option value ='{$callid}|1'>Open </option>然后按“|”爆炸分割结果list($id,$option)=explode("|",$_REQUEST['status'])

答案 1 :(得分:0)

<击>

<击>
<input type="hidden" name="calledid" value="<?=$callid;?>" />

<击>

我的坏。

<button name="calledid" type="submit" value="<?=$callid;?>">Submit</button>

使用它代替您的输入。