Can anybody tell me what is wrong with this line of code? I am currently new and now trying to use mysqli prepared statement in order to connect to the database back end.
So far I can't seem to get it to update the database.
$stmt = $mysqli->prepare("INSERT INTO canada VALUES (?,?,?,?,?,?)");
$stmt->bind_param('sssiss',$_REQUEST["UserID"],$_REQUEST["FirstName"],
$_REQUEST["LastName"],$_REQUEST["Age"],$_REQUEST["WhatParty"],
$_REQUEST["Electorate"]);
$stmt->execute();
The problem is the first parameter to bind param it specifys there are two fields of type integer which is not true.
Bind parameters
if user id and age is int, and rest are string type then
it should be
i for integer, s for string
-- Update
$db = new mysqli($server_host, $server_user, $server_password, $server_db);
if (mysqli_connect_errno()) {
printf("DB error: %s", mysqli_connect_error());
exit();
}
$stmt = $db->prepare("INSERT INTO canada
userid,firstname,lastname,age,whatparty,electorate)
VALUES (?,?,?,?,?,?))");
$stmt->bind_param("ississ",$_REQUEST["UserID"],$_REQUEST["FirstName"],
$_REQUEST["LastName"],$_REQUEST["Age"],
$_REQUEST["WhatParty"],$_REQUEST["Electorate"]);
$stmt->execute();
the problem is that there is 6 (?,?,?,?,?,?)
and you 7 parameter in bind_param
try
$stmt = $mysqli->prepare("INSERT INTO canada VALUES (?,?,?,?,?,?,?)");