2011-05-18 114 views
0

嗨我有一个小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

我不明白你在问什么,但我想指出你已经开放给SQL注入了。请阅读使用PDO准备好的查询。另外,你不能在302重定向中使用相对路径(这就是你对位置标题所做的)。 – Brad 2011-05-18 14:55:27

回答

0

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

+0

谢谢你的快速反应,我会更新脚本,即第二个脚本吗? – andy 2011-05-18 14:55:19

+0

@andy在html中的第一部分和动作脚本中的第二部分(不要忘记用$ option替换$ _REQUEST ['status']) – Catalin 2011-05-18 14:56:27

+0

@andy NOTE brads评论:) – Catalin 2011-05-18 14:58:14

0

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

我的坏。

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

用它代替你的输入。

+0

糟糕的ideea ...他只需要一个callid(对于一个特定的行) – Catalin 2011-05-18 14:59:23