phpmysqlmodx-evolution

errors inserting variables in mysql statement


I am trying to insert four variables into a mysql table. The following mysql INSERT statement produces T_STRING errors. I would be grateful if any one can advise where my error is in the syntax.

function add_student($name, $phone, $email, $id) {
global $modx;
$session_id = intval($id, 10);
$query = $modx->db->INSERT INTO `xtra_students`(`name`, `phone`, `email`, `session_id`) VALUES ('$name', '$phone', '$email', '$session_id');    
return $query;
}

The first 3 variables are varchar and the $session_id is an int(4).


Solution

  • You're missing a function call and the quotes around the string:

    $query = $modx->db->query("INSERT INTO `xtra_students`(`name`, `phone`, `email`, `session_id`) VALUES ('$name', '$phone', '$email', '$session_id')");