PHP更新查询没有用

时间:2013-10-11 11:34:38

标签: phpquery

我在index.php中有一个表单文本字段,我填写8080

http_port : <input size="5" name="http_port" value="3128">

和桌子&#39; squid&#39;像这样

没有|标签|值

1 | http_port | 3128

当我点击提交按钮时,它会重定向到submit.php,但表格没有更新值或仍然是3128。

submit.php

<?php
include("conn.php");
$value = $_POST['http_port'];
$query = mysql_query("update squid set http_port='$value' where '$no'=1");
echo "Update was Succesful<br>
<a href=\"index.php\">Bac</a>";
?>

我的剧本有什么问题?谢谢,抱歉我的英语不好:)

3 个答案:

答案 0 :(得分:1)

你的mysql_query调用中有一个错误,应该是:

$query = mysql_query("update squid set tag ='$value' where no=1");

我已经用PHP编写了很多东西,但是有很多关于这种简单的MySQL / PHP表单的教程。代码I提供了更新标记列,并且以类似的方式可以更新其他列...

$query = mysql_query("update squid set value ='$value' where no=1 and tag = 'http_port'");

答案 1 :(得分:0)

试试这个:

的index.html:

<html>
    <body>
        <form action="submit.php" method="post">
        http_port : 
            <input size="5" name="http_port" value="3128" />
            <input type="submit" />
        </form>
    </body>
</html>

submit.php:

<?php
    require("conn.php");
    if(isset($_POST['http_port']))
    {
        $value = $_POST['http_port'];

        //You should sanitize data before inserting into table
        $value = mysql_real_escape_string(htmlentities(strip_tags(trim($value))));
        $no="your table field name";
        $sql = "UPDATE squid SET http_port=".$value." where ".$no."=1";
        $query = mysql_query($sql) OR die("Err:".mysql_error());
        echo "Update was Successful<br /><a href=\"index.php\">Back</a>";
    }
    else
    {
        echo "Something else";
    }
?>

答案 2 :(得分:0)

$ value是单引号,因此不会获得变量$ value的值。

$sql = "update squid set http_port='".$value."'where no=1";