-3

This is the error I am getting. "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in on line 188" What I am trying to do is connect to the database and insert data into the table, but i can't figure out this error.

$tableName = "customer";
$nullStr = "NULL";

$SQLstring = "INSERT INTO $tableName VALUES
            ('".$nullstr."','".$fname."', '".$lname."','".$address."','".$state."','".$zip."',          '".$phone"','".$email"')";
$result = $mysqli->query($SQLstring);
user2168066
  • 627
  • 11
  • 21
  • Hmm, okay, it's not really a duplicate, but you just have a super normal syntax error here: `$email"')";` Triple check that part. – deceze Apr 18 '13 at 01:44
  • String concatenation in SQL queries is **always** a problem for many reasons. You should be using a prepared statement with parameter binding – Phil Apr 18 '13 at 01:45

3 Answers3

3

You're missing the string concatenation operator . in a couple of places.

Replace

$SQLstring = "INSERT INTO $tableName VALUES
        ('".$nullstr."','".$fname."', ".$lname."','".$address."','".$state."','".$zip."','".$phone"','".$email"')";

with

$SQLstring = "INSERT INTO $tableName VALUES
        ('".$nullStr."','".$fname."', '".$lname."','".$address."','".$state."','".$zip."','".$phone."','".$email."')";

BTW, variable names are case-sensitive. You define $nullStr then try to use $nullstr. I fixed it in the above code.

Mark Parnell
  • 9,175
  • 9
  • 31
  • 36
3

Use a prepared statement with parameter binding instead. Not only does it make this a lot cleaner, it also avoids SQL injection.

$query = "INSERT INTO $tableName VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('sssssss', $fname, $lname, $address, $state,
    $zip, $phone, $email);
$stmt->execute();
Phil
  • 157,677
  • 23
  • 242
  • 245
1

You are missing some periods. Try this...

$SQLstring = "INSERT INTO $tableName VALUES ('".$nullstr."','".$fname."','".$lname."','".$address."','".$state."','".$zip."','".$phone."','".$email."')";
Bafsky
  • 761
  • 1
  • 7
  • 16