0

This says I have an error on Line 15.

I'm hoping to add information and then for it to appear in a table. enter image description here

Parse error: syntax error, unexpected ';' in N:\ftp\compc\ac12mm\untitled folder\addContact.php on line 15

3 Answers3

0

Change your query like this way :

INSERT INTO TABLE_NAME (id,name, ...) VALUES (0,'name', ..) ;
Nivs
  • 376
  • 2
  • 15
Shaymol Bapary
  • 468
  • 3
  • 11
0

You have forgot to close your $db->prepare function.

Replace this(line 15):

$dbQuery = $db->prepare("insert into stock values (
     null, :game, :console, :age, :genre,:price, :status, :stock, :purchased,
     :low, :date, :picture,)";

With this:

$dbQuery = $db->prepare("insert into stock values (
         null, :game, :console, :age, :genre,:price, :status, :stock, :purchased,
         :low, :date, :picture)");

Also:

Replace this(line 16):

$dbParams = array('game'=> $newstockgame, 'console'=> $newstockconsole,
'age'=> $newstockage, 'genre'=> $newstockgenre, 'status'=> $newstockstatus, 
'purchased'=> $newstocklow, 'date'=> $newstockdate, 'picture'=> $newstockpicture);

With this:

$dbParams = array('game'=> $newstockgame, 'console'=> $newstockconsole, 
'age'=> $newstockage, 'genre'=> $newstockgenre, 'price'=> $newstockprice, 
'status'=> $newstockstatus, 'stock'=>$newstockstock, 'purchased'=> $newstockpurchased, 
'low'=>$newstocklow, 'date'=> $newstockdate, 'picture'=> $newstockpicture);
Rahul Singh
  • 892
  • 9
  • 24
  • Hi It is still appearing errors – Michael Mulligan Oct 28 '15 at 12:05
  • You have forgot to add price, stock and low parameters in your $dbParams array – Rahul Singh Oct 28 '15 at 12:07
  • I have updated the answer to cover the error at line 16 – Rahul Singh Oct 28 '15 at 12:16
  • Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'game' cannot be null' in N:\ftp\compc\ac12mm\Practical 2 Files\addContact.php:17 Stack trace: #0 N:\ftp\compc\ac12mm\Practical 2 Files\addContact.php(17): PDOStatement->execute(Array) #1 {main} thrown in N:\ftp\compc\ac12mm\Practical 2 Files\addContact.php on line 17 – Michael Mulligan Oct 28 '15 at 12:25
  • That means in your database you have marked 'game' column as not null while null is being passed through your query – Rahul Singh Oct 28 '15 at 12:31
  • Also be careful in your query because when you pass values without specifying statements like insert into x values('hii') instead of insert into x(`name`) values('hii'). You need to pass values for all the columns in your database table and in exact order as they exist there. – Rahul Singh Oct 28 '15 at 12:35
  • I suggest you to read some PHP books and get more clear understanding of PHP. – Rahul Singh Oct 28 '15 at 12:36
0

There is a semantic error in your code:

$dbQuery = $db->prepare("insert into stock values (null, :game, :console,
:age, :genre, :price, :status, :purchased, :low, :date, :picture,)";

Take a look at the end, you need to fix your line, somehing like that will work way better:

$dbQuery = $db->prepare("insert into stock values (null, :game, :console,
:age, :genre, :price, :status, :purchased, :low, :date, :picture)");

Removing the "," after "picture" and adding ")" to close your statement will make a valid php line.

EDIT: You also forget to add params for ":price", ":stock" and ":low" on line 16, so your query will probably fail if you don't set those variable.

Florian
  • 699
  • 1
  • 5
  • 19