-1

I've only recently started php again, this is supposed to add another game to a chess game database and it's supposed to add all squares as empty, the squares in the database are saved as i0,i1..i63, turno is true when it's white's turn, otherwise false, and the primary key is not metioned here as it's auto increment.

<?php
mysql_connect("localhost","pierostesting","");
mysql_select_db("my_pierostesting");
$query = "INSERT INTO board(";
for($i=0;$i<64;$i++){
    $query.="i$i,";
}
$query.="turno) VALUES(";
for($i=0;$i<64;$i++){
    $query.="'empty',";}$query.="1)";
echo $query;
if(mysql_query($query)){
    echo 'nailed it';
}?>
Piero
  • 49
  • 8
  • On a side note: you shouldn't use mysql_* functions as they are deprecated and will be removed in PHP7 end of this year: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Daniele D May 30 '15 at 10:27
  • Also please tell us the output of `SHOW CREATE TABLE board` and the output of `echo $query` before sending it to the My-SQL server – Daniele D May 30 '15 at 10:29
  • It was a problem with my database, thank you all. – Piero May 30 '15 at 10:31
  • What was the problem with your database? If you explain then it would be useful for other users who may get this same problem. – Gunaseelan May 30 '15 at 10:51
  • I simply didn't add i63 as a field and tried to save in it. – Piero May 30 '15 at 12:25

1 Answers1

3

Unaccepted } closing in your code it would be

<?php
mysql_connect("localhost","pierostesting","");
mysql_select_db("my_pierostesting");
$query = "INSERT INTO board(";
for($i=0;$i<64;$i++){
    $query.="i$i,";
}
$query.="turno) VALUES(";
for($i=0;$i<64;$i++){
    $query.="'empty',";

}
    $query.="1)";


echo $query;
if(mysql_query($query)){
    echo 'nailed it';
}?>

And the output of this code is correct query as you write

Saty
  • 22,443
  • 7
  • 33
  • 51