Jump to content

mysqli_select_db


LambPatch

Recommended Posts

I'm not that great at coding but do manage to muddle my way through stuff if I can understand it. I've got a project going where i'd like to have something like the example in w3schools. The link is this one. http://www.w3schools.com/php/php_ajax_database.asp


I have been trying to replicate this on my own server but its not working. what I'm seeing is error message.
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\Hosting\8937614\html\vfd\famguy1.php on line 40

 

I'm seeing on the php file there is a line that goes like this:

mysqli_select_db($con,"ajax");
 

I looked it up but the explanation is very vague, changing databases. Can someone explain what's happening here in why? thanks, Gail
 

 

 

 

Link to comment
Share on other sites

You're looking at the wrong line. The error is caused by the mysqli_fetch_array() call, and this typically happens when a query fails and you don't bother to check for that.

 

So there are actually two problems. First, you need to start checking for errors or enable exceptions so that mysqli does this automatically:

// make mysqli throw an exception whenever it encounters a problem
$mysqli_driver = new mysqli_driver();
$mysqli_driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;

Secondly, you need to fix the query itself. When you enable exceptions, you'll see the MySQL error in the message.

 

Apart from that, w3schools is a very bad resource and known to spread false information. Don't use it for learning.

Edited by Jacques1
Link to comment
Share on other sites

Thanks Jacques1. I appreciate the help. Finding good material to learn from has been a real issue. Lots of old mysql code and its hard to find things that have a simple goal in mind. Many try to throw in 'extras' that make it hard to pick out what you're trying to accomplish from the fluff. Any suggestions on good beginner books, websites or whatever?

Anyway, thanks again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.