Page 1 of 1

[SOLVED] newbie's script going badly wrong!

Posted: Sun Jun 13, 2004 11:35 am
by garethnash
Trying to use this code:

Code: Select all

<?php
$user="garethna_fishacc";
$pass="<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>";
$db="garethna_Fishdatabase";
$link=@mysql_connect("localhost",$user, $pass);
if (! $link){
die ("Couldnt connect to mysql:".mysql_error());
}
print "<h2>Successfully connected to server</h2>\n\n";
@mysql_select_db($db)
or die ("Couldnt open $db: ".mysql_error());
print "Successfully selected $db";
$row = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
$your_col = $row["your_col"];
$any_other_cols = $row["any_other_cols"];
echo $your_col."<br />";
echo $any_other_cols;
}
mysql_close($link);
?>
I keep getting this back:
Successfully connected to server
Successfully selected garethna_Fishdatabase
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/home/garethna/public_html/printmysql.php on line 21

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/home/garethna/public_html/printmysql.php on line 22
Anybody know whats wrong. New to PHP and think it may be obvious. Thanks in advance!

Posted: Sun Jun 13, 2004 11:42 am
by feyd
you never perform a query, $result is never set.

Posted: Sun Jun 13, 2004 11:48 am
by garethnash
Grrrrrrrrrr will try it and get back to you lol. Thanks man total newbie berk here!

Posted: Sun Jun 13, 2004 11:53 am
by garethnash
Now it works. Damn I need to work on this stuff a bit more lol. I always get in too deep lol!