Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Ne0
Forum Commoner
Posts: 60 Joined: Sat Feb 14, 2004 11:48 am
Post
by Ne0 » Sat Feb 14, 2004 11:48 am
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.
Last edited by
Ne0 on Sat Feb 14, 2004 11:58 am, edited 1 time in total.
Straterra
Forum Regular
Posts: 527 Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:
Post
by Straterra » Sat Feb 14, 2004 11:55 am
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?
Ne0
Forum Commoner
Posts: 60 Joined: Sat Feb 14, 2004 11:48 am
Post
by Ne0 » Sat Feb 14, 2004 11:57 am
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?
Straterra
Forum Regular
Posts: 527 Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:
Post
by Straterra » Sat Feb 14, 2004 12:05 pm
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";
}
?>
Ne0
Forum Commoner
Posts: 60 Joined: Sat Feb 14, 2004 11:48 am
Post
by Ne0 » Sat Feb 14, 2004 12:18 pm
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
Straterra
Forum Regular
Posts: 527 Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:
Post
by Straterra » Sat Feb 14, 2004 12:35 pm
Hm..what line is the error on?
Ne0
Forum Commoner
Posts: 60 Joined: Sat Feb 14, 2004 11:48 am
Post
by Ne0 » Sat Feb 14, 2004 12:49 pm
i dunno, the whole page is just:
No input file specified.
ive never seen that b4...
Bill H
DevNet Resident
Posts: 1136 Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:
Post
by Bill H » Sat Feb 14, 2004 12:53 pm
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);
?>
Straterra
Forum Regular
Posts: 527 Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:
Post
by Straterra » Sat Feb 14, 2004 12:54 pm
Prolly..Like I said earlier, I use SQLite, not MySQL
Ne0
Forum Commoner
Posts: 60 Joined: Sat Feb 14, 2004 11:48 am
Post
by Ne0 » Sat Feb 14, 2004 12:55 pm
thx, but i got the same thing.....
Straterra
Forum Regular
Posts: 527 Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:
Post
by Straterra » Sat Feb 14, 2004 12:56 pm
Why not put the username and password directly into the connect function?
Ne0
Forum Commoner
Posts: 60 Joined: Sat Feb 14, 2004 11:48 am
Post
by Ne0 » Sat Feb 14, 2004 1:00 pm
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";
}
?>
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sat Feb 14, 2004 1:21 pm
try:
Code: Select all
$result = @mysql_query ("select * from users");
while ($row = mysql_fetch_object ($result)) {
print "$row["username"]"; or die (mysql_error());
}
Last edited by
tim on Sat Feb 14, 2004 1:29 pm, edited 1 time in total.
Ne0
Forum Commoner
Posts: 60 Joined: Sat Feb 14, 2004 11:48 am
Post
by Ne0 » Sat Feb 14, 2004 1:24 pm
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())
}
?>
Last edited by
Ne0 on Sat Feb 14, 2004 1:29 pm, edited 1 time in total.
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sat Feb 14, 2004 1:26 pm
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