更新ID的单元格

时间:2015-12-13 13:59:41

标签: php html mysql

我有这样的表格:

<?php
  $id = $_GET['id'];
?>
<form method="POST" action="send.php?<?php echo $id; ?>"
<p><input type="text" class="result" size="80%" required placeholder="number">
</p>
<p>
<input type="hidden" name="id">

<div style="width:200px;">
<span class="a-button a-button-primary a-padding-none  a-button-span12">
  <span class="a-button-inner">
    <input id="continue-top" class="a-button-text " tabindex="0" type="submit" value="Continue" >
  </span>
</span>
  </div>
</p>
</form>

我想更新列result

$id = $_GET['id'];

我如何在这里更新'结果',其中id =示例26?:

mysql_query("UPDATE `cc` SET `result`=
                         ('".$_POST['result']."')",$db)  ;
header( 'Refresh: 1; url=admin.php' );

3 个答案:

答案 0 :(得分:1)

<?php 
$id = $_GET['id']; 
?>
<form method="POST" action="send.php">
    <p><input type="text" class="result" name="result" size="80%" required placeholder="number"></p>
    <p>
        <div style="width:200px;">
            <span class="a-button a-button-primary a-padding-none  a-button-span12">
                <span class="a-button-inner">
                    <input id="continue-top" class="a-button-text " tabindex="0" type="submit" value="Continue" >
                </span>
            </span>
        </div>
    </p>
    <input type="hidden" name="id" value="<?php echo $id; ?>" />
</form>

在send.php上,使用$_POST['id']$_POST['result']获取此ID和结果,并使用mysql_real_escape_string保护。

就像那样:

$id = mysql_real_escape_string($_POST['id']);
$result = mysql_real_escape_string($_POST['result']);

要更新db表cc,请执行以下操作:

mysql_query("UPDATE `cc` SET `result` = ' " . $result . " ' WHERE `id` = ' " . $id . " '", $db);

答案 1 :(得分:0)

$sql = "UPDATE cc SET result='Doe' WHERE id=26";

但如果你想让$ _GET [id]工作,那么这里应该是这样的:

<form method="POST" action="send.php?id=<?php echo $id;?>"

不要忘记清理数据,避免使用mysql注入:

$id = mysql_real_escape_string($_GET['id']); 

答案 2 :(得分:0)

将值隐藏在输入类型中。您要更新哪个ID记录

替换此代码。

<form method="POST" action="send.php?<?php echo $id; ?>"
<p><input type="text" class="result" size="80%" required    placeholder="number">
</p>
<p>
<input type="hidden" name="id" value='26'>

<div style="width:200px;">
<span class="a-button a-button-primary a-padding-none  a-button-span12">
<span class="a-button-inner">
<input id="continue-top" class="a-button-text " tabindex="0" type="submit" value="Continue" >
</span>
</span>
</div>
</p> 
</form>