thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Mysqli_fetch_assoc error #8

Open Zarzelius opened 10 years ago

Zarzelius commented 10 years ago

I keep getting this and i still having been able to fix it .

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Websites\config\setup.php on line 34

That is on setup.php in this lines:

$q = "SELECT * FROM pages WHERE id = $pageid";
$r = mysqli_query($db_connection, $q);
$data = mysqli_fetch_assoc($r);

Any thoughts?

thedigicraft commented 10 years ago

Try adding a bit of error handling.

After this line:

 $data = mysqli_fetch_assoc($r); 

Place this:


echo mysqli_error($db_connection).'<br>'; // This will tell you if there is an error and what kind.
echo $q; // Echo out the query. If there is an error you should see it here.

Let me know what error message you get and also copy/paste the query output.

Zarzelius commented 10 years ago

Ok ill add the code and test it as soon as i can.Ill give you a detailed explanation of what happens when i do. :)

Zarzelius commented 10 years ago

I believe is a problem with the actually xampp, because im not having those issues with my online hosting service. I believe that im not actually getting access to the database even when i dont get a connection error. If i try with dbc('localhost', 'username', 'password', 'database_name') i get an error with "Access denied for user 'username'@'localhost' (using password: YES)" even when i have the correct password.

If i just use : dbc('localhost','root') i get this instead:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Websites\config\setup.php on line 34 No database selected SELECT * FROM pages WHERE id = 1

Any ideas?

thedigicraft commented 10 years ago

When you do dbc('localhost','root') you are leaving out the database name. So it doesn't know where to look for the table in your query.

Try this and see if it helps Issue: PhpMyAdmin User/Privileges Issue - Video #2 & #6

phpclue commented 10 years ago

I remember having the same error message but it's been a while and don't remember how I fixed it. Try adding single quotes around $pageid replace your query:

$q = "SELECT * FROM pages WHERE id = $pageid";

with:

$q = "SELECT * FROM pages WHERE id = '$pageid'";
...
Note: add single quotes around '$pageid'
simpythegimpy commented 9 years ago

Very cool web series, definitely the best that I've seen on the web so far, except I have run into the privileges problem (took a month to find the problem) and now this.

However, I have the same problem as above.

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\xampp\htdocs\dynamic\index.php on line 5

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\dynamic\index

Is it XAMPP? Am I an idiot?