0

我有一个表格,我将数据发布到数据库。我希望它更新 sku=sku 的记录,我以前从未这样做过,所以我已经阅读了这个并尝试了各种方法,但它们没有奏效。这是我到目前为止所尝试的。

<?php
if(isset($_POST['submit']))
{

$hostname_conn = "host address";
$database_conn = "database";
$username_conn = "username";
$password_conn = "password";
$conn = mysql_connect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR); 

    mysql_select_db("bi_social", $conn);

    $sqlCmd = sprintf("UPDATE table2 SET sku2=%s sku=%s WHERE sku='%s'", 
    mysql_real_escape_string($_POST["sku"]),
    mysql_real_escape_string($_POST["sku2"]),
    mysql_real_escape_string($_POST["sku3"]));

    //echo $sqlCmd;
    //die();    

    mysql_query($sqlCmd);

    mysql_close($conn);
}

?>
<form method="post">
            <div class="large-3 columns">
<input name="sku" type="text" id="sku" placeholder="sku" value="<?=$_GET["sku"]?>"/>
            </div>
            <div class="large-3 columns">
<input name="sku2" type="text" id="sku2" placeholder="sku2" value="<?=$_GET["sku2"]?>"/>
            </div>
            <div class="large-3 columns">
<input name="sku3" type="text" id="sku3" placeholder="sku3" value="<?=$_GET["sku3"]?>"/>
            </div>
            <div class="large-3 columns">
    <input class="alert button" name="submit" type="submit" value="MATCH!"/>
    </div>
    </div>
    </div>
    </div>
</form>

我不确定我做了什么使它不起作用我可以插入数据库但更新不起作用。我哪里出错了,我该如何解决这个问题。谢谢瑞恩

4

2 回答 2

1

您在更新语句中缺少逗号。更新语句应如下所示:

UPDATE table2 SET sku2='%s', sku='%s' WHERE sku='%s'
于 2013-07-23T08:58:20.750 回答
0

改变:

$sqlCmd = sprintf("UPDATE table2 SET sku3=%s, sku2=%s WHERE sku='%s'", 
mysql_real_escape_string($_POST["sku3"]),
mysql_real_escape_string($_POST["sk2"]),
mysql_real_escape_string($_POST["sku"]));

或者,

$sqlCmd = "update table2 set sku3 = '".mysql_real_escape_string($_POST['sku3'])."', sku2 = '".mysql_real_escape_string($_POST['sku2'])."' where sku = '".mysql_real_escape_string($_POST['sku'])."'";
于 2013-07-23T08:55:23.340 回答