Tutorial :PHP mysqli unexpected parameter Question



Question:

I feel like a total n00b for not understanding what I'm doing wrong, but here goes.

I'm writing a simple web form that's storing information in a MySQL database. I'm getting this error:

mysqli_stmt_init() expects parameter 1 to be mysqli, null given in /myfile.php  

Here's my code:

$server = 'localhost';  $username = 'myusername';  $password = 'mypassword';  $db = 'mydb';  $link = mysqli_connect($server, $username, $password, $db);  .  .  .   $stmt = mysqli_stmt_init($link); /*This line throws the error*/  

Any ideas? Thanks in advance.


Solution:1

Are you 100% sure you are successfully connecting to the database?

Add at the top of your script:

error_reporting(E_ALL);  ini_set('display_errors', 1);  

Also add right below your connection line:

if (mysqli_connect_errno()) {      printf("Connect failed: %s", mysqli_connect_error());      exit;  }  


Solution:2

If this is your dev server you should probably set the following lines in your php.ini file rather than in each script.

error_reporting = E_ALL display_errors = on

if that doesn't solve you problem than you should print our $link to see what it is.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »