I\'m trying to submit values to a database using jquery. I\'m new to ajax but I\'m required to do it with ajax.
This is what I\'ve done so far my php code is
Please reply to some of the comments so we can help figure out what the issues is. This is how your function would look with proper mysqli syntax.
How to make the connection: $mysql = new mysqli(...)
How to prepare the statement: $stmt = $mysqi->prepare(....)
How to bind the parameters: $stmt->bind_param(...)
Execution: $stmt->execute()
Note: you were making your insert string like it was to be used for mysqli but your parameter binding was more similiar to pdo. I wasn't sure which one you were wanting to use so I chose mysqli. I personally prefer PDO, though... so I can re-write this using that if you want. Link to the PDO Prepare Function that also shows some binding.
// this is your database connection for mysqli
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');
function insertSeries($mysqli)
{
$options = array(
'user' => $_POST['user'],
'email' => $_POST['email'],
'summary' => $_POST['summary'],
'due_date' => $_POST['due_date'],
'problem_type' => $_POST['problem_type'],
'status' => $_POST['status']
);
$sql = "insert into ticket_summary('user','email','summary','due_date','problem_type','status')
Values (?, ?, ?, ?, ?, ?)";
if ( $stmt = $mysqli->prepare($sql) )
{
$stmt->bind_param("ssssss", $options['user'], $options['email'],
$options['summary'], $options['due_date'],
$options['problem_type'], $options['status']);
$success = $stmt->execute();
if ($success) { print "query worked"; }
else { print "query failed"; }
}
}