reetyn reetyn - 1 year ago 78
Perl Question

SQLite prepare method fails due to syntax error

So I want to create a database for Users and insert values into the fields using variable. Initially I tried using it calling the do function, but it wasn't reading the variables properly so I decided to just use prepare and execute separately. This is my code:

$dbh->do("DROP TABLE IF EXISTS Users");
$dbh->do("CREATE TABLE Users(
zid TEXT,
Name TEXT,
Email TEXT,
password TEXT,
Mates TEXT,
Program TEXT,
Courses TEXT,
Suburb TEXT,
Birthday TEXT)");

$zid = "z33432523";
$name = "John Doe";
$email = "";
$password = "alien";
$mates = "z3459148 z3458291";
$program = "";
$courses = "";
$suburb = "";
$birthday = "13/5/1992";

$sth = $dbh->prepare('INSERT INTO Users VALUES (?, ?, ?, ?, ?. ?, ?, ?, ?)');
$sth->execute($zid, $name, $email, $password, $mates, $program, $courses, $suburb, $birthday);

However, if I try running this code I get the following error:

DBD::SQLite::db prepare failed: near ".": syntax error at ./ line 35.

I'm not sure exactly what the problem is?

Answer Source
near ".": syntax error

INSERT INTO Users VALUES (?, ?, ?, ?, ?. ?, ?, ?, ?)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download