【问题标题】:PHP could not execute queryPHP 无法执行查询
【发布时间】:2016-08-30 18:58:29
【问题描述】:

我正在使用 php 5.6.20

在管理页面中,我正在尝试添加产品,但似乎后剂量不起作用并且查询剂量未执行 The database taple 表格

        <form id="myform"method="post"action="Admin.php">

        <table class="userinf">
            <tr>
                <th colspan="2"><label class="labeli">Add Product</label></th>
            </tr>
            <tr>
                <td><label class="labelii">PID</label></td>
                <td><input id ="iitxt0" class ="itxt"type="text" name="PID" value="<?php echo $row["UID"]; ?>"></td>
            </tr>
            <tr>
                <td><label class="labelii">Name</label></td>
                <td><input id ="iitxt1" class ="itxt"type="text" name="Name" required value="<?php echo $row["Name"]; ?>" "></td>
            </tr>
            <tr>
                <td><label class="labelii">Picture</label></td>
                <td><input id ="iitxt2" class ="itxt" type="text" name="Picture" required value="<?php echo $row["Email"]; ?>"></td>
            </tr>
            <tr>
                <td><label class="labelii">Price</label></td>
                <td><input id ="iitxt3" class ="itxt" type = "text" name="Price" pattern="[-+]?([0-9]*\.[0-9]+|[0-9]+)" required value="<?php echo $row["PhoneNo"]; ?>"></td>
            </tr>
            <tr>
                <td><label class="labelii">Type</label></td>
                <td><input id ="iitxt4" class ="itxt" type="text" name="Type"  required value="<?php echo $row["CreditNo"]; ?>"></td>
            </tr>
            <tr>
                <td><label class="labelii">Stock</label></td>
                <td><input id ="iitxt5" class ="itxt"type="number" name="Stock" value="<?php echo $row["City"]; ?>"></td>
            </tr>   
            <tr>
                <td colspan="2">
                    <button type="submit" id="Sbutt" class="Ebutton" onclick="submitform()">Save</button>
                </td>
            </tr>
        </table>
    </form>

PHP 代码

<?php

        var_dump();
        if (isset($_POST["PID"]) && isset($_POST["Name"]) && isset($_POST["Picture"]) && isset($_POST["Price"]) && isset($_POST["Type"]) && isset($_POST["Stock"])){

        $PID=$_POST['PID'];
        $Name=$_POST['Name'];
        $Picture=$_POST['Picture'];
        $Price=floatval($_POST['Price']);
        $Type=$_POST['Type'];
        $Stock=intval($_POST['Stock']);
        $query="INSERT INTO `product` (`PID`, `Name`, `Picture`, `Price`, `Type`, `Stock`)"+
         +"VALUES ('$PID', '$Name', '$Picture','$Price', '$Type', '$Stock')";
        }
        if($_POST){
        if(!($database=mysql_connect("localhost","wadiahS","123456")))
          die("Could not connect to database</body></html>");
        if(!mysql_select_db("glow",$database))
          die("Could not open database</body></html>");
        if(!($result=mysql_query($query,$database))){
          print("<p>could not execute query</p>");
          die(mysql_error()."</body></html>");
        }
        mysql_close($database);
        }
   ?>

当我尝试发帖时 ii 得到错误 /// 警告:var_dump() 至少需要 1 个参数,0 在第 294 行的 C:\xampp\htdocs\web\pages\Admin.php 中给出 无法执行查询

您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的“0”附近使用正确的语法 ///

【问题讨论】:

  • 您没有为 var dump 添加参数。将其添加到括号中。
  • 在第 1 行的 PHP 代码中,您使用的是 var_dump();没有任何参数。
  • 第一行'var_dump();'这是错误。您需要放置要查看的变量。还要检查 '$query="INSERT INTO product (PID, Name, Picture, Price, Type, Stock)"+ +"VALUES ('$PID', '$Name', '$Picture','$Price', '$Type', '$Stock')";' '+' 不被 php 接受。它应该是'。'
  • 是否需要连接查询?
  • 谢谢它确实解决了我的问题

标签: php mysql database forms post


【解决方案1】:

我认为您在查询中有语法错误。您需要用下面的代码替换您的查询代码,希望对您有所帮助。如果你想连接任何你需要的东西,你可以在 PHP 中使用 (+) 运算符连接 (.) 运算符。所以请用下面给出的改变你的查询变量。

 $query = "INSERT INTO `product` (`PID`, `Name`, `Picture`, `Price`, `Type`, `Stock`) VALUES ('$PID', '$Name', '$Picture','$Price', '$Type', '$Stock')";

用上面的替换你的查询变量。

【讨论】:

    【解决方案2】:

    从查询中删除空的 var_dump() 和 +

    $query="INSERT INTO `product` (`PID`, `Name`, `Picture`, `Price`, `Type`, `Stock`) VALUES ('$PID', '$Name', '$Picture','$Price', '$Type', '$Stock')";
    

    【讨论】:

      【解决方案3】:

      您正在使用加号(+)连接查询 在 PHP 中,字符串使用 dot(.) 连接 也可以删除 var_dump() 或添加任何参数。

      $query="INSERT INTO `product` (`PID`, `Name`, `Picture`, `Price`, `Type`, `Stock`)" . "VALUES ('$PID', '$Name', '$Picture','$Price', '$Type', '$Stock')";
      

      【讨论】:

        猜你喜欢
        • 2013-08-04
        • 2016-01-27
        • 2016-03-11
        • 1970-01-01
        • 2015-10-06
        • 2017-09-28
        • 2023-03-03
        • 2011-10-17
        相关资源
        最近更新 更多