0

I'm trying to add a row to my table video_games by using the value of a $_GET like this:

$yourname = $_GET['yourName'];

$bdd->exec('INSERT INTO video_games(name, owner, console, price) VALUES($yourname, \'Patrick\', \'PC\',45)');

But I get this error:

Unknown column $yourname in field list

I tried several other solutions like $name or name or 'name' instead of $name. But I can't have the value of $_GET to be inserted.

I have also checked other posts and I did not find any solution, yet it should be a famous question.

To make it simple, the problem is: How to put the value of a variable in an INSERT statement using the exec() function ?

Thanks.

Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
adrTuIPKJ44
  • 2,793
  • 2
  • 9
  • 8

1 Answers1

0

Did you try like this....

$yourname = $_GET['yourName'];

$bdd->exec("INSERT INTO video_games(name, owner, console, price) VALUES('$yourname', 'Patrick', 'PC',45)");
Hikmat Sijapati
  • 6,869
  • 1
  • 9
  • 19
  • Yes, and I get a Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '\'Patrick\', \'PC\',45) – adrTuIPKJ44 Dec 20 '16 at 08:54
  • 1
    no need to `\'Patrick\'`.just use like `'Patrick'` – Hikmat Sijapati Dec 20 '16 at 08:56