Hey Guys...i know this is a common problem and ive read other threads, but can't figure out my specific problem. Any help would be appreciated!!

This script worked perfect until i moved it to a different host. Getting this error:

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\Inetpub\vhosts\levelznightclub.com\httpdocs\index.php on line 285

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Inetpub\vhosts\levelznightclub.com\httpdocs\index.php on line 357

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\Inetpub\vhosts\levelznightclub.com\httpdocs\index.php on line 362

Here are the lines from the script that are listed above. If you need other information please let me know!!

Line 285:

$num=mysql_numrows($result);

Line 357:

if (!mysql_num_rows($result)) {

Line 362:

$num2=mysql_numrows($result2);

Are you sure that $result has a value at this point?
Do you have any checks to ensure that $result is defined and has a value?

I normally only get this error when the variable being passes is NULL

xan, i read through that before i posted. still can't figure it out.

My bad, missed the first line of your post, oops :)

In that case, post your actual query (The one(s) providing $result and $result2) and any related code, as the error is caused by an omission or problem with the query.

xan, i read through that before i posted. still can't figure it out.

If you read through the FAQ then you would have A) Figured it out or B) posted the MySQL error that your are getting instead of just the error that says invalid argument.

So read through the FAQ again, and post the error that gets returned it should look like, "Error in MySQL syntax near...".

wowzers, no need to get huffy :/

those are the only errors i see that i am getting.

maybe it would be easier if i give you the link to check it out so you can see what im talking about. also you can view source that way if it helps.

http://levelznightclub.com/index.php

i also wanted to reiterate that i was running this on a different host with no problems. i switched over to this host without changing any files and thats when the problems started. (of course i had to edit database info, but its seems to connect to the database no problem)

after taking a peek at the link, let me know what other code you might need to take a look at.

We can see the HTML source of your page, but we cannot see any PHP code....

Can you post the actual query to be reviewed.

yeah just noticed that actually...sorry!! ;)

<?php



//Connect To Database
include("admin/config.php");
mysql_connect($dbhost,$dbuser,$dbpass) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname) or die( "Unable to select database");


$query="SELECT * FROM events WHERE 
(year >= $current_year AND month > $current_month) 
OR (year >= $current_year AND month = $current_month AND day >= $current_day) 
OR (year_end >= $current_year AND month_end = $current_month AND day_end >= $current_day) 
OR (year > $current_year) 

OR (year_show >= $current_year AND month_show > $current_month)
OR (year_show >= $current_year AND month_show = $current_month AND day_show >= $current_day) 
OR (year_show > $current_year) 
ORDER BY year, month, day LIMIT 0, $maxnum";


$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {

//Get all the data and assign variables
$id=mysql_result($result,$i,"id");
$event=mysql_result($result,$i,"event");
$hour=mysql_result($result,$i,"hour");
$minute=mysql_result($result,$i,"minute");
$ampm=mysql_result($result,$i,"ampm");
$hour_end=mysql_result($result,$i,"hour_end");
$minute_end=mysql_result($result,$i,"minute_end");
$ampm_end=mysql_result($result,$i,"ampm_end");
$month=mysql_result($result,$i,"month");
$day=mysql_result($result,$i,"day");
$year=mysql_result($result,$i,"year");
$month_end=mysql_result($result,$i,"month_end");
$day_end=mysql_result($result,$i,"day_end");
$year_end=mysql_result($result,$i,"year_end");
$month_show=mysql_result($result,$i,"month_show");
$day_show=mysql_result($result,$i,"day_show");
$year_show=mysql_result($result,$i,"year_show");
$location=mysql_result($result,$i,"location");
$email=mysql_result($result,$i,"email");
$phone=mysql_result($result,$i,"phone");
$link=mysql_result($result,$i,"link");
$link_name=mysql_result($result,$i,"link_name");
$description=mysql_result($result,$i,"description");
$html=mysql_result($result,$i,"html");
// removes slashes
$description=stripslashes($description);

//replaces carriage returns with html line breaks
if ($html =="0") {
$description=preg_replace("/\n/","<br>", ($description));
}

// removes the first zero from the hour.  We need the zero at first, to keep the numbering in order.  
//Of course the number ten needs the zero left in.
if ($hour !="10") {
$hour=preg_replace("/0/","", ($hour));
}

if ($hour_end !="10") {
$hour_end=preg_replace("/0/","", ($hour_end));
}

if (($hour_end =='') && ($minute_end =='') && ($ampm_end =='')) { $end_time ='';}
else { $end_time= " - $hour_end:$minute_end $ampm_end"; }

if (($month_end =='') && ($day_end =='') && ($year_end =='')) { $end_date ='';}
else { $end_date= "- $month_end/$day_end/$year_end"; }

// Here is where we actually print out the events.  
echo "
<a name=$id></a><span class=\"event_name\">$event</span> <br>
Date: $month/$day/$year $end_date  <br>
Time: $hour:$minute $ampm $end_time<br>
Location: $location <br>";
// email, phone and link is optional, so we have to use a conditional statement.  We don't want extra line breaks if these fields aren't used.
if ($email) { echo "Contact email: <a href='mailto:$email'>$email</a> <br>"; } 
if ($phone) { echo "Contact phone: $phone <br>"; } 
echo"<br>$description <br>";
if ($link)  { echo "<br><a href='$link' target='_blank'>$link_name</a>"; }
echo "<div class=\"separator\"></div>";
// looks for the next event id and if it exists, prints it out.
$i++;
}


// If there are no scheduled events, print the no events message
if (!mysql_num_rows($result)) {
mysql_connect($dbhost,$dbuser,$dbpass) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname) or die( "Unable to select database");
$query2="SELECT * FROM no_events WHERE id=1";
$result2=mysql_query($query2);
$num2=mysql_numrows($result2);
mysql_close();
$k=0;
while ($k < $num2) {
$description2=mysql_result($result2,$k,"description");
$description2=stripslashes($description2);
$description2=preg_replace("/\n/","<br>", ($description2));
echo "$description2";
$k++;
}
}


?>

You were wrong at mysql_numrows.
It should be mysql_num_rows() everywhere.Your code modified below -

<?php
//Connect To Database
include("admin/config.php");
mysql_connect($dbhost,$dbuser,$dbpass) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname) or die( "Unable to select database");


$query="SELECT * FROM events WHERE 
(year >= $current_year AND month > $current_month) 
OR (year >= $current_year AND month = $current_month AND day >= $current_day) 
OR (year_end >= $current_year AND month_end = $current_month AND day_end >= $current_day) 
OR (year > $current_year) 

OR (year_show >= $current_year AND month_show > $current_month)
OR (year_show >= $current_year AND month_show = $current_month AND day_show >= $current_day) 
OR (year_show > $current_year) 
ORDER BY year, month, day LIMIT 0, $maxnum";


$result=mysql_query($query);
$num=mysql_num_rows($result);
$i=0;
while ($row = mysql_fetch_array($result))
{
//Get all the data and assign variables
$id=$row['id'];
$event=$row['event'];
$hour=$row['hour'];
$minute=$row['minute'];
$ampm=$row['ampm'];
$hour_end=$row['hour_end'];
$minute_end=$row['minute_end'];
$ampm_end=$row['ampm_end'];
$month=$row['month'];
$day=$row['day'];
$year=$row['year'];
$month_end=$row['month_end'];
$day_end=$row['day_end'];
$year_end=$row['year_end'];
$month_show=$row['month_show'];
$day_show=$row['day_show'];
$year_show=$row['year_show'];
$location=$row['location'];
$email=$row['email'];
$phone=$row['phone'];
$link=$row['link'];
$link_name=$row['link_name'];
$description=$row['description'];
$html=$row['html'];
// removes slashes
$description=stripslashes($description);

	//replaces carriage returns with html line breaks
	if ($html =="0") {
	$description=preg_replace("/\n/","<br>", ($description));
	}

	// removes the first zero from the hour.  We need the zero at first, to keep the numbering in order.  
	//Of course the number ten needs the zero left in.
	if ($hour !="10") {
	$hour=preg_replace("/0/","", ($hour));
	}
	
	if ($hour_end !="10") {
	$hour_end=preg_replace("/0/","", ($hour_end));
	}

	if (($hour_end =='') && ($minute_end =='') && ($ampm_end =='')) { $end_time ='';}
	else { $end_time= " - $hour_end:$minute_end $ampm_end"; }

	if (($month_end =='') && ($day_end =='') && ($year_end =='')) { $end_date ='';}
	else { $end_date= "- $month_end/$day_end/$year_end"; }

	// Here is where we actually print out the events.  
	echo "
	<a name=$id></a><span class=\"event_name\">$event</span> <br>
	Date: $month/$day/$year $end_date  <br>
	Time: $hour:$minute $ampm $end_time<br>
	Location: $location <br>";
	// email, phone and link is optional, so we have to use a conditional statement.  We don't want extra line breaks if these fields aren't used.
	if ($email) { echo "Contact email: <a href='mailto:$email'>$email</a> <br>"; } 
	if ($phone) { echo "Contact phone: $phone <br>"; } 
	echo"<br>$description <br>";
	if ($link)  { echo "<br><a href='$link' target='_blank'>$link_name</a>"; }
	echo "<div class=\"separator\"></div>";
	// looks for the next event id and if it exists, prints it out.
	$i++;
}


// If there are no scheduled events, print the no events message
if (!mysql_num_rows($result)) {
mysql_connect($dbhost,$dbuser,$dbpass) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname) or die( "Unable to select database");
$query2="SELECT * FROM no_events WHERE id=1";
$result2=mysql_query($query2);
$num2=mysql_numrows($result2);
mysql_close();
$k=0;
while ($k < $num2) {
$description2=mysql_result($result2,$k,"description");
$description2=stripslashes($description2);
$description2=preg_replace("/\n/","<br>", ($description2));
echo "$description2";
$k++;
}
}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.