Page 1 of 3
help please?! mysql_num_rows():
Posted: Sat Feb 14, 2004 11:48 am
by Ne0
ok, im a n00b, i admit it (with PHP and MySQL anywho...)
and i got a problem.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\ne0\index4.php on line 10
and heres the code:
Code: Select all
<?
$username="ne0";
$pwrd="****"
$database="db";
mysql_connect(localhost,$username,$pwrd);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM users";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$user=mysql_result($result,$i,"name");
$password=mysql_result($result,$i,"password");
$email=mysql_result($result,$i,"email");
$sig=mysql_result($result,$i,"sig");
$avatar=mysql_result($result,$i,"avatar");
$web=mysql_result($result,$i,"web");
echo "UserName: $user<br>Password: $password<br>E-mail: $email<br>Signature: $sig<br>WebSite: <a href=$web>Visit</a><br><br";
++$i;
} // while loop
?>
i wrote the code, but got the basic crud of a tutorial, and i have no clue whats wrong...
thanks in advanced.
Posted: Sat Feb 14, 2004 11:55 am
by Straterra
Woah..Um..what is this script supposed to do? Also, with the whole $i=0;
while ($i < $num) thing, were you trying to do a for-loop?
Posted: Sat Feb 14, 2004 11:57 am
by Ne0
well, based on the tutorial i was readin, this is supposed to get all of the data out of the table users and display it.
and in the tutorial it used a while-loop, but i guess a for loop would work, right?
Posted: Sat Feb 14, 2004 12:05 pm
by Straterra
Hm.. That code looks a bit weird to me. Here is how I would get all info from a database.
Code: Select all
<?php
$username="ne0";
$pwrd="****"
$database="db";
mysql_connect(localhost,$username,$pwrd);
@mysql_select_db($database) or die( "Unable to select database");
$result=mysql_query(SELECT * FROM users);
while ($row=mysql_fetch_array($result)) {
echo "UserName: ".$row['username']."<br>Password: ".$row['password']"."<br>E-mail: ".$row['email']."<br>Signature: ".$row['sig']."<br>WebSite: <a href="".$row['web']."">Visit</a><br><br";
}
?>
Posted: Sat Feb 14, 2004 12:18 pm
by Ne0
ok, that makes sense, but this is what it returned:
No input file specified.
Code: Select all
<?php
$name="ne0";
$pwrd="****"
$database="db";
mysql_connect(localhost,$name,$pwrd);
@mysql_select_db($database) or die( "Unable to select database");
$result=mysql_query(SELECT * FROM users);
while ($row=mysql_fetch_array($result)) {
echo "UserName: ".$row['username']."<br>Password: ".$row['password']"."<br>E-mail: ".$row['email']."<br>Signature: ".$row['sig']."<br>WebSite: <a href="".$row['web']."">Visit</a><br><br";
}
?>
and i changed the **** to the passwordd...
thanks 4 helpin btw

Posted: Sat Feb 14, 2004 12:35 pm
by Straterra
Hm..what line is the error on?
Posted: Sat Feb 14, 2004 12:49 pm
by Ne0
i dunno, the whole page is just:
No input file specified.
ive never seen that b4...
Posted: Sat Feb 14, 2004 12:53 pm
by Bill H
My guess would be that
Code: Select all
<?php
mysql_connect(localhost,$name,$pwrd);
?>
should be
Code: Select all
<?php
mysql_connect("localhost",$name,$pwrd);
?>
Posted: Sat Feb 14, 2004 12:54 pm
by Straterra
Prolly..Like I said earlier, I use SQLite, not MySQL
Posted: Sat Feb 14, 2004 12:55 pm
by Ne0
thx, but i got the same thing.....
Posted: Sat Feb 14, 2004 12:56 pm
by Straterra
Why not put the username and password directly into the connect function?
Posted: Sat Feb 14, 2004 1:00 pm
by Ne0
ok, this problem just got a whole lot bigger,
now all of my pages (the one that creates the table, the one that inserts data into the table, and this one)
show that message.
that cant be good...
EDIT: nvm, now its giving me this:
Parse error: parse error, unexpected T_STRING in c:\program files\apache group\apache\htdocs\ne0\index4.php on line 4
Code: Select all
<?php
mysql_connect(localhost,"ne0","****");
@mysql_select_db($database) or die( "Unable to select database");
$result=mysql_query(SELECT * FROM users);
while ($row=mysql_fetch_array($result)) {
echo "UserName: ".$row['username']."<br>Password: ".$row['password']"."<br>E-mail: ".$row['email']."<br>Signature: ".$row['sig']."<br>WebSite: <a href="".$row['web']."">Visit</a><br><br";
}
?>
Posted: Sat Feb 14, 2004 1:21 pm
by tim
try:
Code: Select all
$result = @mysql_query ("select * from users");
while ($row = mysql_fetch_object ($result)) {
print "$row["username"]"; or die (mysql_error());
}
Posted: Sat Feb 14, 2004 1:24 pm
by Ne0
Parse error: parse error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program files\apache group\apache\htdocs\ne0\index4.php on line 6
Code: Select all
<?php
mysql_connect(localhost,"ne0","****");
@mysql_select_db($database) or die( "Unable to select database");
$result = @mysql_query ("select * from users");
while ($row = mysql_fetch_object ($result)) {
print "$row["username"]; or die (mysql_error())
}
?>
Posted: Sat Feb 14, 2004 1:26 pm
by tim
my apologies
I edited the post but seemingly you pasted it befor the edit
I forgot the ; after the mysql_error
the code should be good to go now, sorry. bad timing