zainab .a.k zainab .a.k - 2 years ago 87
PHP Question

PHP could not execute query

i am using php 5.6.20

in the admin page i am trying to Add product but it seems like the post dose not work and the query dose not executed
The database taple
The Form

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

<table class="userinf">
<th colspan="2"><label class="labeli">Add Product</label></th>
<td><label class="labelii">PID</label></td>
<td><input id ="iitxt0" class ="itxt"type="text" name="PID" value="<?php echo $row["UID"]; ?>"></td>
<td><label class="labelii">Name</label></td>
<td><input id ="iitxt1" class ="itxt"type="text" name="Name" required value="<?php echo $row["Name"]; ?>" "></td>
<td><label class="labelii">Picture</label></td>
<td><input id ="iitxt2" class ="itxt" type="text" name="Picture" required value="<?php echo $row["Email"]; ?>"></td>
<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>
<td><label class="labelii">Type</label></td>
<td><input id ="iitxt4" class ="itxt" type="text" name="Type" required value="<?php echo $row["CreditNo"]; ?>"></td>
<td><label class="labelii">Stock</label></td>
<td><input id ="iitxt5" class ="itxt"type="number" name="Stock" value="<?php echo $row["City"]; ?>"></td>
<td colspan="2">
<button type="submit" id="Sbutt" class="Ebutton" onclick="submitform()">Save</button>

The PHP Code


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

$query="INSERT INTO `product` (`PID`, `Name`, `Picture`, `Price`, `Type`, `Stock`)"+
+"VALUES ('$PID', '$Name', '$Picture','$Price', '$Type', '$Stock')";
die("Could not connect to database</body></html>");
die("Could not open database</body></html>");
print("<p>could not execute query</p>");

And when i try to post
ii get the error
Warning: var_dump() expects at least 1 parameter, 0 given in C:\xampp\htdocs\web\pages\Admin.php on line 294
could not execute query

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0' at line 1

Answer Source

You are concatenating the query using plus(+) In PHP Strings are concatenating using dot(.) Also either remove the var_dump() or add any parameter to it.

$query="INSERT INTO `product` (`PID`, `Name`, `Picture`, `Price`, `Type`, `Stock`)" . "VALUES ('$PID', '$Name', '$Picture','$Price', '$Type', '$Stock')";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download