0

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);
$stmt->execute();

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?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
sridhar
  • 1,321
  • 5
  • 17
  • 26
  • Can you `var_dump($stmt);` after `$mysqli->prepare`, and tell us what it returns to you ? – Yoluk Dec 24 '15 at 17:38
  • 4
    inserts have no limit. it's utterly pointless to specifiy one. "Here's some data for a new record, but make sure only one record is created". uh, no... an insert creates one record only (ignoring mysql's extended insert syntax). if you don't want multiple records created, you don't provide the data for multiple records. In other words, RTFM: http://dev.mysql.com/doc/refman/5.7/en/insert.html no where is there a "limit" in the main insert syntax. – Marc B Dec 24 '15 at 17:38
  • 1
    Your `prepare` sentence does not returns an object. Use `$mysqli->error()` to get its error message. (And, yeah, there'll probably be something about `LIMIT`) – Denis Alexandrov Dec 24 '15 at 17:40
  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1 – Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ Dec 24 '15 at 17:52
  • Check the database connection. See this issue http://stackoverflow.com/questions/27787773/call-to-a-member-function-bind-param-on-a-non-object – SomethingElse Dec 24 '15 at 17:54

2 Answers2

2

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);
$stmt->execute();

You should also check that your connection is valid.

Reference: http://php.net/manual/en/mysqli-stmt.bind-param.php

myselfmiqdad
  • 2,518
  • 2
  • 18
  • 33
0

Remove from your statement this: LIMIT 1.

It doesn't belong in an "Insert" statement!.

Captain Crunch
  • 567
  • 3
  • 13