-1

I've got a little question about my script, I'm trying to enter a lot of data in my MySQL database but I've got the next problem

I can't enter the data with php because there is a space in one of my 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 could help me, thanks in forward !

Janelle
  • 69
  • 9

4 Answers4

0

Use backticks (`) tilde symbol.

$qw1 = "voornaam, achternaam, straat, postcode, geboortejaar, telefoonnummer, email, `ORDER DATE`";
Praveen
  • 55,303
  • 33
  • 133
  • 164
perfectweb
  • 59
  • 1
  • 7
  • thanks for the fast answer, but that didn't really worked my $qw1 now looks like this voornaam, achternaam, straat, postcode, geboortejaar, telefoonnummer, email, bestellingsdatum, 'Standaard', 'Standaard met drankbonnen' – Pieter-Jan Coenen Jul 12 '13 at 18:50
  • use backticks, not apostrophes. The backtick key is next to the "1" key. – perfectweb Jul 12 '13 at 18:54
0

Use Backticks

 $qw1 = "`voornaam`, `achternaam`, `straat`, `postcode`, `geboortejaar`, `telefoonnummer`, `email`, `ORDER DATE`";
Orangepill
  • 24,500
  • 3
  • 42
  • 63
Kirtan
  • 120
  • 1
  • 6
0

why dont you use the sql error ? so you can see what the msitake is .

try this

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

use backticks around this also

    `ORDER DATE`

Note: this ` is not same as this '

try this

   $qw2 = $vnaam .','.$anaam .','.$straat.','. $code.','. $geboorte.','. $tel.', '.$email.', '.$dateandhour ;
echo_Me
  • 37,078
  • 5
  • 58
  • 78
  • This is the syntax 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 'ORDER DATE') – Pieter-Jan Coenen Jul 12 '13 at 19:15
  • make order date as in my answer with backticks , just copy it and paste it in your code if you dont know what is backticks and single quote. backticks is not same as single quote – echo_Me Jul 12 '13 at 19:23
  • You really helped me out with it ! Thank you so much, i really didn't saw there is a diference between the two Thanks !!! – Pieter-Jan Coenen Jul 12 '13 at 19:40
0

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

John
  • 1