Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Syntax error when inserting
    primarykey
    data
    text
    <p>I've got a syntax error in the following code, but I can't find it:</p> <pre><code>$tableSelect = $_POST["tableSelect"]; $companyName = $_POST["companyName"]; $telephone = $_POST["telephone"]; $fax = $_POST["fax"]; $email = $_POST["email"]; $address = $_POST["address"]; $postcode = $_POST["postcode"]; $category = $_POST["category"]; $contact = $_POST["contact"]; $contactTel = $_POST["contactTel"]; $contactEmail = $_POST["contactEmail"]; $sql = "INSERT INTO '" . $tableSelect . "' ('" . $companyName . "', '" . $telephone . "', '" . $fax . "', '" . $email . "', '" . $address . "','" . $postcode . "', '" . $category . "', '" . $contact . "', '" . $contactTel . "', '" . $contactEmail . "')"; mysqli_query($con,$sql); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } </code></pre> <p>Cheers!</p> <p><strong>EDIT:</strong> I have modified the code to this:</p> <pre><code>$sql = "INSERT INTO `" . $tableSelect . "` (name, telephone, fax, email, address, postcode, category, contact, contactTel, contactEmail) VALUES (`" . $companyName . "`, `" . $telephone . "`, `" . $fax . "`, `" . $email . "`, `" . $address . "`,`" . $postcode . "`, `" . $category . "`, `" . $contact . "`, `" . $contactTel . "`, `" . $contactEmail . "`)"; </code></pre> <p>and now have the error "Error: Unknown column [companyName] in 'field list'", where [companyName] is the value submitted through the form. But surely I've defined the column as "name"?</p> <p><strong>Edit 2:</strong> Thanks, I'm now aware of the injection issue. I'd like to get it working, then I'll change it to using prepared statements.</p>
    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