0

This code gives me an error when I try to insert Cat and Purr. The tutorial didn't have a double quotation mark, but their code didn't work either. This has to be a syntax issue of some sort.

message('creating the db Object');
    $db = new bwSQLite3(DB_FILENAME, TABLE_NAME);
    $tn = TABLE_NAME;
    message('creating the table');
    $db->sql_do("Drop table if exists $tn");
    $db->sql_do("create table $tn ( id integer primary key, animal text, sound text )");
    //insert some records
    $db->sql_do("insert into $tn (animal, sound) values (?, ?), 'cat', 'Purr' "); //right here issues
    $db->sql_do("insert into $tn (animal, sound) values (?, ?), 'dog', 'Woof' ");
    $db->sql_do("insert into $tn (animal, sound) values (?, ?), 'duck', 'Quack' ");
    $db->sql_do("insert into $tn (animal, sound) values (?, ?), 'bear', 'Grr' ");
    message('there are %d rows in the table', $db->count_recs());
}catch (PDOException $e) {
    error($e->getMessage());
}

Here is the error: Parse error: syntax error, unexpected 'insert' (T_STRING) in C:\xampp\htdocs\ExerciseFiles\Chap01\create.php on line 42

2
  • 2
    Please add your error to your question. Commented Apr 5, 2016 at 14:59
  • Parse error: syntax error, unexpected 'insert' (T_STRING) in C:\xampp\htdocs\ExerciseFiles\Chap01\create.php on line 42 Commented Apr 5, 2016 at 15:00

1 Answer 1

1
 $db->sql_do("insert into $tn (animal, sound) values (?, ?), 'cat', 'Purr' "); //right here issues

should be

 $db->sql_do("insert into $tn (animal, sound) values (?, ?)", 'cat', 'Purr'); 

look at the syntax highlighting.

Also it sounds like you don't understand how PHP works with strings, try this to see the difference:

$my_name = 'Matt';
echo 'Hello $my_name.';
echo "Hello $my_name.";
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I see it. I appreciate the tutorial. ' ' = literal string. " " used for commands and strings.
Also @SDJ, the syntax error was due to having a spurious " at the end of the sql_do parameters. You wanted to double quote the parameterized query ( the first argument) , and then provide the parameter values ( the remaining arguments ). Understanding ' vs " is valuable, but the real source of the issues here, was the fact that both the parameterized query and the parameters' values were put all within one double quoted string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.