Note that there are some explanatory texts on larger screens.

plurals
  1. PO'Query was empty' error when pushing form data to Database PHP, MYSQL
    text
    copied!<p>The code I am using (below) doesn't work for some reason, I check everything matches in the html form - I just can't figure this out.</p> <p>Could I be getting the error because something that is wrong on the HTML side? I'm using the jQuery form validator (this works fine) could this cause problems? <a href="http://jqueryvalidation.org/" rel="nofollow">http://jqueryvalidation.org/</a></p> <pre><code>&lt;?php $host="localhost"; // Host name $username="USERNAME"; // Mysql username $password="PASSWORD"; // Mysql password $db_name="DBNAME"; // Database name $tbl_name="Persons"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $fname=$_POST['fname']; $lname=$_POST['lname']; $company=$_POST['company']; $email=$_POST['email']; $registered=$_POST['registered']; $percentage=$_POST['percentage']; $products=$_POST['products']; $prize=$_POST['prize']; $terms=$_POST['terms']; $newsletter=$_POST['newsletter']; // Insert data into mysql $sql="INSERT INTO $tbl_name(FirstName, LastNname, Company, EmailAddress, Registered, PercentOfBusiness, ProductsSold, WhichPrize, Newsletter)VALUES('$fname', '$lname', '$company', '$email', '$registered', '$percentage', '$products', '$prize', '$terms', '$newsletter')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "&lt;BR&gt;"; echo "&lt;a href='insert.php'&gt;Back to main page&lt;/a&gt;"; } else { echo "ERROR"; } ?&gt; &lt;?php $result = mysql_query($query) or die(mysql_error()); ?&gt; &lt;?php // close connection mysql_close(); ?&gt; </code></pre>
 

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