[SOLVED] newbie's script going badly wrong!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
garethnash
Forum Newbie
Posts: 18
Joined: Sun Jun 13, 2004 11:35 am
Location: UK

[SOLVED] newbie's script going badly wrong!

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you never perform a query, $result is never set.
garethnash
Forum Newbie
Posts: 18
Joined: Sun Jun 13, 2004 11:35 am
Location: UK

Post by garethnash »

Grrrrrrrrrr will try it and get back to you lol. Thanks man total newbie berk here!
garethnash
Forum Newbie
Posts: 18
Joined: Sun Jun 13, 2004 11:35 am
Location: UK

Post by garethnash »

Now it works. Damn I need to work on this stuff a bit more lol. I always get in too deep lol!
Post Reply