Dynadot โ€” .com Registration $8.99

Not valid Function

Spaceship Spaceship
Watch

cleanvar()

Account Closed
Impact
0
Hi all,

I am using the script below and i keep getting Warning:
mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/awakened/public_html/search/search.php on line 19

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/awakened/public_html/search/search.php on line 24

and the titles display if there is no result, but i only want them to display when there are some and it says if there isnt any, but its not working, could someone please correct the code?

Will

PHP:
<?php

//include('connect.php');

if (isset($_POST['submit']))
{
$hostt = $_POST['hostt'];
$hc = $_POST['hc'];
$lang = $_POST['land'];
$mds = $_POST['mds'];
$mbw = $_POST['mbw'];
$sl = $_POST['sl'];
$ads = $_POST['ads'];

echo "You chose: <b>Type:</b> $hostt, <b>Cost:</b> $hc, <b>Min Diskspace:</b> $mds, <b>Min B/W:</b> $mbw, <b>Server Location:</b> $sl, <b>Ads:</b> $ads.";

$query = "SELECT * FROM hosts WHERE type = '$hostt' AND cost = '$hc' AND language = '$lang' AND mindisk <= '$mds' AND minbw <= '$minbw' AND serverlocation = '$sl' AND ads = '$ads'";
//$result = mysql_query($query) or die (mysql_error());
$cr = mysql_num_rows($result);
if ($cr == 0)
{
echo "No results found, Sorry.";
}
while ( $row = mysql_fetch_array($result));
{
$name = $row['name'];
$url = $row['url'];
$type = $row['type'];
$cost = $row['cost'];
$language = $row['language'];
$mindisk = $row['mindisk'];
$minbw = $row['minbw'];
$serverlocation = $row['serverlocation'];
$ads = $row['ads'];
// Now echo results
echo "Company matches which meet your criteria";
echo "<a href=\"$url\"><b>$name</b></a><br>
<b>Type:</b>$type<br>
<b>Cost:</b>$cost<br>
<b>Language:</b> $language<br>
<b>Minimum Disk Space:</b> $mindisk<br>
<b>Minimum Bandwith:</b> $minbw<br>
<b>Server Location:</b> $serverlocation<br>
<b>Ads:</b> $ads<br><br>
";
}
}
?>
<form name="search" method="post">
Type of Host: <select name="hostt">
<option>Shared</option>
<option>Reseller</option>
<option>Shoutcast</option>
<option>Dedicated</option>
<option>VPS</option>
<option>File</option>
<option>Image</option>
<option>Video</option>s
<option>Game</option>
<option>Other</option>
</select>ย 
Hosting Cost: <select name="hc"><option>Free</option> <option>Paid</option> <option>Paid to Post</option> <option>Ads</option></select>
Language: <select name="lang"><option>English</option> <option>Chineese</option> <option>German</option> <option>French</option> <option>Other</option></select>
Minimum Diskspace: <select name="mds"><option>0mb</option><option>50mb</option> <option>100mb</option> <option>500mb</option> <option>1000mb</option></select><br>
Minimum Bandwith: <select name="mbw"><option>0gb</option><option>1gb</option> <option>5gb</option> <option>10gb</option> <option>20gb</option></select>
Server Location: <select name="sl"><option>All</option> <option>UK</option> <option>USA</option> <option>Germany</option, <option>Other</option></select>
Ads: <select name="ads"><option>No</option><option>Yes</option></select>
<br><input type="submit" name="submit" value="Search">
</form>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Here yo go:

PHP:
<?php

//include('connect.php');

if (isset($_POST['submit']))
{
$hostt = $_POST['hostt'];
$hc = $_POST['hc'];
$lang = $_POST['land'];
$mds = $_POST['mds'];
$mbw = $_POST['mbw'];
$sl = $_POST['sl'];
$ads = $_POST['ads'];

echo "You chose: <b>Type:</b> $hostt, <b>Cost:</b> $hc, <b>Min Diskspace:</b> $mds, <b>Min B/W:</b> $mbw, <b>Server Location:</b> $sl, <b>Ads:</b> $ads.";

$query = "SELECT * FROM hosts WHERE type = '$hostt' AND cost = '$hc' AND language = '$lang' AND mindisk <= '$mds' AND minbw <= '$minbw' AND serverlocation = '$sl' AND ads = '$ads'";
$result = mysql_query($query) or die (mysql_error());
$cr = mysql_num_rows($result);
if ($cr == 0)
{
echo "No results found, Sorry.";
}
else
{
 while ( $row = mysql_fetch_array($result));
 {
 $name = $row['name'];
 $url = $row['url'];
 $type = $row['type'];
 $cost = $row['cost'];
 $language = $row['language'];
 $mindisk = $row['mindisk'];
 $minbw = $row['minbw'];
 $serverlocation = $row['serverlocation'];
 $ads = $row['ads'];
 // Now echo results
 echo "Company matches which meet your criteria";
 echo "<a href=\"$url\"><b>$name</b></a><br>
 <b>Type:</b>$type<br>
 <b>Cost:</b>$cost<br>
 <b>Language:</b> $language<br>
 <b>Minimum Disk Space:</b> $mindisk<br>
 <b>Minimum Bandwith:</b> $minbw<br>
 <b>Server Location:</b> $serverlocation<br>
 <b>Ads:</b> $ads<br><br>
 ";
 }
} //end else
}
?>
<form name="search" method="post">
Type of Host: <select name="hostt">
<option>Shared</option>
<option>Reseller</option>
<option>Shoutcast</option>
<option>Dedicated</option>
<option>VPS</option>
<option>File</option>
<option>Image</option>
<option>Video</option>s
<option>Game</option>
<option>Other</option>
</select>ย 
Hosting Cost: <select name="hc"><option>Free</option> <option>Paid</option> <option>Paid to Post</option> <option>Ads</option></select>
Language: <select name="lang"><option>English</option> <option>Chineese</option> <option>German</option> <option>French</option> <option>Other</option></select>
Minimum Diskspace: <select name="mds"><option>0mb</option><option>50mb</option> <option>100mb</option> <option>500mb</option> <option>1000mb</option></select><br>
Minimum Bandwith: <select name="mbw"><option>0gb</option><option>1gb</option> <option>5gb</option> <option>10gb</option> <option>20gb</option></select>
Server Location: <select name="sl"><option>All</option> <option>UK</option> <option>USA</option> <option>Germany</option, <option>Other</option></select>
Ads: <select name="ads"><option>No</option><option>Yes</option></select>
<br><input type="submit" name="submit" value="Search">
</form>

You had the $result=mysql_query($query) commented out, and needed an else so that if there were not 0, meaning 1 or more results it actually displays them.

If this works, rep or NP$ is appreciated.
 
Last edited:
0
•••
Im Sorry, But it didnt work:
You chose: Type: Shared, Cost: Free, Min Diskspace: 0mb, Min B/W: 0gb, Server Location: All, Ads: No.
Warning: mysql_query(): Access denied for user 'nobody'@'localhost' (using password: NO) in /home/awakened/public_html/search/search.php on line 18

Warning: mysql_query(): A link to the server could not be established in /home/awakened/public_html/search/search.php on line 18
Access denied for user 'nobody'@'localhost' (using password: NO)

Im not sure if its to do with the conncet:
PHP:
<?php

//connect.php

$dbuser = "*******";
$dbpass = "****";
$host = "localhost";

$db = "******";

mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($db);

?>
Will
 
0
•••
cleanvar() said:
Warning: mysql_query(): Access denied for user 'nobody'@'localhost' (using password: NO) in /home/awakened/public_html/search/search.php on line 18

in this error message the bolded part tells you what is wrong you do not seem to have set the username and password.
 
0
•••
Ive fixed it thanks, i had // before connect.php!
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back