0

This is my functions.php file and I have gotten an error when I run it. The source code of the file is:

<?php

function data_insert($to, $from, $text, $ip1, $ip2, $ip3, $ua) {
  try {

    $db = pdoConnect();

    $query = 
      "INSERT INTO sms (
        recepient,
        sender,
        message,
        ip1,
        ip2,
        ip3,
        ua,
        result
      )
      VALUES (
        :recepient,
        :sender,
        :message,
        :ip1,
        :ip2,
        :ip3,
        :ua,
        :result
      )";

    $sqlVars = array(
      ':recepient' => $to;
      ':sender' => $from;
      ':message' => $text;
      ':ip1' => $ip1;
      ':ip2' => $ip2;
      ':ip3' => $ip3;
      ':ua' => $ua;
      ':result' => $result;
    );

    $stmt = $db->prepare($query); 

    if (!$stmt->execute($sqlVars)){
      // Error: column does not exist
      return false;
    }

    $inserted_id = $db->lastInsertId();

    $stmt = null;

    return $inserted_id;

  } catch (PDOException $e) {
    addAlert("danger", "Oops, looks like our database encountered an error.");
    error_log("Error in " . $e->getFile() . " on line " . $e->getLine() . ": " . $e->getMessage());
    return false;
  } catch (ErrorException $e) {
    addAlert("danger", "Oops, looks like our server might have goofed. If you're an admin, please check the PHP error logs.");
    return false;
  } 
}
?>

The error is:

Parse error: syntax error, unexpected ';', expecting ')' in /home/appfesti/public_html/functions.php on line 30

Line 30 contains:

$sqlVars = array(

Can anyone help me with the fix? Any help would be appreciated!

1
  • you should not terminate the line when you are counting array elements Commented Aug 12, 2014 at 6:15

1 Answer 1

3

Array values must be comma separated:

$sqlVars = array(
  ':recepient' => $to,
   ':sender' => $from,
   ':message' => $text,
   ':ip1' => $ip1,
   ':ip2' => $ip2,
   ':ip3' => $ip3,
   ':ua' => $ua,
   ':result' => $result
 );
Sign up to request clarification or add additional context in comments.

2 Comments

It's also the only answer :)
There should not be a comma on the last line, because this creates an empty element.

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.