yoshifish
yoshifish

Reputation: 73

Inserting multiple values using mysqli

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();

Upvotes: 0

Views: 1580

Answers (2)

Naveen Kumar
Naveen Kumar

Reputation: 4601

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();

Upvotes: 1

NullPoiиteя
NullPoiиteя

Reputation: 57312

the problem is that there is 6 (?,?,?,?,?,?) and you 7 parameter in bind_param

try

 $stmt = $mysqli->prepare("INSERT INTO canada VALUES (?,?,?,?,?,?,?)");

Upvotes: 1

Related Questions