hi all
am new to php .. am running the following code to connect my DB..
$conn = new mysqli('localhost', 'phpuser', 'phpuser', 'phpdb');
$stmt = $conn->prepare($loginSql);
$stmt->bind_param("s", $username);
$stmt->execute();
but am getting Fatal error: Call to a member function bind_param() on a non-object in error.. cud any1 help me out of dis
mysql prepare
Moderator: General Moderators
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: mysql prepare
Whats the value of $loginSql? Is it even defined?
Re: mysql prepare
no.. no.. it has
var $loginSql = "select * from login where username=?";
var $loginSql = "select * from login where username=?";
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: mysql prepare
Why is there a var before $loginSql? Is this a class property? If so, you access it with $this->loginSql(if you're inside the class), not just $loginSql. That would explain the error you've been getting.var $loginSql = "select * from login where username=?";
Post a more complete code example.
Re: mysql prepare
here is my code
$loginSql = "select userId from user where username=?";
$conn = new mysqli('localhost', 'phpuser', 'phpuser', 'phpdb');
$stmt = $conn->prepare($loginSql);
$stmt->bind_param("s", $username);
$stmt->execute();
when i tried to run this code am getting
Fatal error: Call to a member function bind_param() on a non-object in D:\Web\WebServer\Apache2\htdocs\DbConn\test.php on line 10
$loginSql = "select userId from user where username=?";
$conn = new mysqli('localhost', 'phpuser', 'phpuser', 'phpdb');
$stmt = $conn->prepare($loginSql);
$stmt->bind_param("s", $username);
$stmt->execute();
when i tried to run this code am getting
Fatal error: Call to a member function bind_param() on a non-object in D:\Web\WebServer\Apache2\htdocs\DbConn\test.php on line 10
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: mysql prepare
Also turn on error reporting to full
Code: Select all
error_reporting(E_ALL); ini_set('display_errors', true);