Page 1 of 1

null given?

Posted: Mon Nov 15, 2010 4:50 pm
by ScottCFR
I am working on the admin panel I plan to put on my site, I am trying to make it so the contact form posts into a mysql db and it displays in the admin panel. For some reason, I can't figure out what I've done wrong.

Errors:

Code: Select all

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /home/scottcfr/public_html/admin/index.php on line 39
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in /home/scottcfr/public_html/admin/index.php on line 152
Lines:

Code: Select all

39: <p><a href="index.php?page=blog">Blog</a> -=- <a href="index.php?page=announcements">Announcements</a> -=- Contacted (<?php include "config.php"; $return = mysql_query("SELECT * FROM contact WHERE read='no'"); mysql_num_rows($return1) ?>)-=- <a href="http://hellbeast.net/">Site Home</a> -=- <a href="http://hellbeast.net/forums/">Site Forums</a>

152: while($myrow = mysql_fetch_assoc($result))

Re: null given?

Posted: Mon Nov 15, 2010 5:06 pm
by Jonah Bron
Intuitively, I would expect this:

Code: Select all

$return = mysql_query("SELECT * FROM contact WHERE read='no'"); mysql_num_rows($return1)
To be:

Code: Select all

$return = mysql_query("SELECT * FROM contact WHERE read='no'"); mysql_num_rows($return)
$return != $return1

Just a wild guess, but the second error might be the same problem. $result != $return != $return1.

Re: null given?

Posted: Mon Nov 15, 2010 5:38 pm
by ScottCFR
Well, I changed them all so they aren't close to the same thing. I still get the same error..

Re: null given?

Posted: Mon Nov 15, 2010 5:57 pm
by s992
You want them to be the same thing.

You're assigning your query to $return, but then you don't do anything with it(that we can see). You check for the number of rows in $return1, and then you try to fetch an associative array of $result - neither of those variables have been declared in the snippet you gave us.

Re: null given?

Posted: Mon Nov 15, 2010 6:44 pm
by ScottCFR
Sorry, but I'm not understanding.

In the one where I am counting the rows where read=no, if I remove "WHERE read='no'" it's fine, but if it's there it doesn't work... explanation?

Re: null given?

Posted: Mon Nov 15, 2010 11:16 pm
by s992
What I was getting at is that it appears that you are trying to reference the results with three different variables.

On line 39, you have two variables($return and $return1):

Code: Select all

<?php include "config.php"; $return = mysql_query("SELECT * FROM contact WHERE read='no'"); 
mysql_num_rows($return1) ?>
The results of your query are stored in $return, not $return1. Judging from the two lines you gave us, $return1 appears to be blank. Likewise on line 152, you reference $result which appears to have not been assigned a value.

However, now that you say that it works fine if you remove the WHERE clause, I'd venture a guess that it has something to do with the data in your database. Your mysql_query() isn't returning any data(hence the null), which means it can't find any records matching the query. Ensure that you actually have records in the DB where read = no. To see if MySQL is throwing an error when you are attempting the query, try this code:

Code: Select all

<?php
include "config.php";
$return = mysql_query("SELECT * FROM contact WHERE read='no'") OR die(mysql_error());
// Plug in the rest of your code...
Let me know if it returns an error message, that will help us figure it out a little bit more.