【问题标题】:PHP Update Query didnt worksPHP更新查询不起作用
【发布时间】:2013-10-11 11:34:37
【问题描述】:

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

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

还有这样的表'鱿鱼'

没有 |标签 |价值

1 | http_port |第3128章

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

提交.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>";
?>

我的脚本有什么问题?感谢和抱歉我的英语不好:)

【问题讨论】:

  • 什么是 $no ??不应该是no
  • $no 是表 'squid' 中的第 1 列,先生。我改变 $query = mysql_query("update squid set http_port='$value' where no = 1");它也没有工作
  • 你看到我的回答了吗??

标签: phpquery


【解决方案1】:

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

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

我已经很久没有用 PHP 编写过任何代码了,但是对于这种简单的 MySQL/PHP 表单有很多教程。我提供的代码更新标签列,并且您可以以类似的方式更新其他列...

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

【讨论】:

  • $query = mysql_query("update squid set value ='$value' where no=1");它的工作原理thx先生:)
  • 它应该不能正常工作。 $value 用单引号括起来,所以不会得到变量 $value 的值。
  • 尽管我没有测试过这段代码,但我认为即使使用单引号也能正常工作,因为双引号,比如 query(" '$value' ")
【解决方案2】:

试试这个:

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>

提交.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";
    }
?>

【讨论】:

    【解决方案3】:

    $value 用单引号括起来,所以不会得到变量 $value 的值。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-04
      • 1970-01-01
      • 2017-11-12
      • 1970-01-01
      • 2015-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多