【发布时间】: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