sridhar sridhar - 4 years ago 123
SQL Question

inserting into mySql through php prepared statement fails

Here are the binding variables:

$uid = 28;
$csr = 1;
$inr = 1;
$hdr = 1;
$prn = 1;
$pay = 2;

and these are the codes:

$stmt = $mysqli->prepare("INSERT INTO mytable(uid, csr, inr, hdr, prn, pay) VALUES(?,?,?,?,?,?) LIMIT 1");
$stmt->bind_param("iiiiii", $uid, $csr, $inr, $hdr, $prn, $pay);

and this is the error message I am getting: PHP Fatal error: Call to a member function bind_param() on a non-object

Can anyone spot the mistake here?

Answer Source

The Limit is used when retrieving data from the query (i.e In a SELECT). It only receives the limit you set. For more information MySQL Limits

Try this instead, it is without the limit and single quotes (just incase) in bind_param.

$stmt = $mysqli->prepare("INSERT INTO mytable(uid, csr, inr, hdr, prn, pay) VALUES(?,?,?,?,?,?)");
$stmt->bind_param('iiiiii', $uid, $csr, $inr, $hdr, $prn, $pay);

You should also check that your connection is valid.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download