Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL query is empty?
    primarykey
    data
    text
    <p>This php is suposed to send five attributes {id, description, email, price, shape} to the <em>sales</em> table in the <em>salesinformation</em> database.</p> <pre><code>&lt;?php define('DB_NAME', 'salesinformation'); define('DB_USER', 'root'); define('DB_PASSWORD', ''); define('DB_HOST', 'localhost'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Cannot connect: ' . mysql_error()); } $db_selected = mysql_select_db(DB_NAME, $link); if(!$db_selected){ die('Cannot use ' . DB_NAME . ': ' . mysql_error()); } $value = $_POST['description']; $value2 = $_POST['email']; $value3 = $_POST['price']; $value4 = $_POST['shape']; $sql = mysql_query("INSERT INTO sales (id, description, email, price, shape) VALUES ('', '$value', '$value2', '$value3', '$value4')"); if (!mysql_query($sql)){ die('Error: ' . mysql_error()); } mysql_close(); ?&gt; </code></pre> <p>If I <code>echo $value</code> it prints out the correct information that I filled in my html form (So the part that extracts values from the HTML is working atleast). I run xampp and created the database with PhpMyAdmin, and when this PHP runs all I get is <em>Error: Query was empty</em> and nothing is added to the database at all. </p> <p>What makes the mysql_query empty?</p> <p>EDIT: I had missed a ' sign at one of the values. Now instead I get this error message</p> <pre><code>Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload