Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Like the other guys said, put the comments in the array reference. That being said you really need to escape the $_POST variables to avoid SQL Injection, its also easier to debug if the code is clearly ordered :)</p> <p>With ordered code you can type echo "some text"; at any touch point you want to so you can see where the code breaks.</p> <p>Also switching on error reporting in your php.ini or in code (<a href="http://php.net/manual/en/function.error-reporting.php" rel="nofollow">http://php.net/manual/en/function.error-reporting.php</a>) would be the best bet for watching the errors that you can't predict.</p> <pre><code>&lt;?php $hostname = "myHostName"; $username = "PreRegCustomers"; $dbname = "PreRegCustomers"; $password = "myPassword"; $usertable = "CustomerInfo"; //connect to mysql $link_id = mysql_connect($hostname, $username, $password); if (!$link_id) { die("Unable to connect to database! Please try again later. error:".mysql_errno()); } echo "connected to mysql"; //make sure your DB exists if (!mysql_select_db($dbname)) die ("Connected to mysql but could not connect to the DB. error:".mysql_errno()); echo "connected to database"; //avoid sql_injection $firstName = mysql_real_escape_string($_POST['firstName']); $lastName = mysql_real_escape_string($_POST['lastName']); $streetAddress = mysql_real_escape_string($_POST['streetAddress']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $zip = mysql_real_escape_string($_POST['zip']); $country = mysql_real_escape_string($_POST['country']); $email = mysql_real_escape_string($_POST['email']); $phone = mysql_real_escape_string($_POST['phone']); $badgeName = mysql_real_escape_string($_POST['badgeName']); echo "sanitised input"; //write the query $sql = "INSERT INTO $usertable (firstName, lastName, streetAddress, city, state, zip, country, email, phone, badgeName) VALUES ('$firstName', '$lastName', '$streetAddress', '$city', '$state', '$zip', '$country', '$email', '$phone', '$badgeName')"; echo "build query: ".$sql; //then you'll need to execute the query :) if (mysql_query($sql)) echo "query success"; else echo "query failed"; //ps you can ignore the last? &gt; </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.
    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