Insert data into mysql colum with spaces with php

I have a small question about my script, I am trying to enter a lot of data into a MySQL database, but I have the following problem.

I cannot enter data using php because there is a space in one of the column names

here is the code

$qw1 = "voornaam, achternaam, straat, postcode, geboortejaar, telefoonnummer, email, ORDER DATE";

$qw2 = "'$vnaam', '$anaam','$straat', $code, $geboorte, $tel, '$email', '$dateandhour'";

mysql_query("INSERT INTO bestellingen ($qw1) VALUES ($qw2)");

      

I hope someone can help me, thanks go ahead!

-2


source to share


4 answers


why aren't you using sql error? so you can see what msitake means.

try it

mysql_query("INSERT INTO bestellingen ($qw1) VALUES ($qw2)") or die(mysql_error());

      

use inverse elements around this as well



    `ORDER DATE`

      

Note: this is 'not the same as this'

try it

   $qw2 = $vnaam .','.$anaam .','.$straat.','. $code.','. $geboorte.','. $tel.', '.$email.', '.$dateandhour ;

      

0


source


Use back keys (`) tilde character .



$qw1 = "voornaam, achternaam, straat, postcode, geboortejaar, telefoonnummer, email, `ORDER DATE`";

      

0


source


Use Backticks

 $qw1 = "`voornaam`, `achternaam`, `straat`, `postcode`, `geboortejaar`, `telefoonnummer`, `email`, `ORDER DATE`";

      

0


source


don't use spaces in column names, but use AS in your query. For example, select orderDate as "ORDER DATE"

0


source







All Articles