help please?! mysql_num_rows():

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 »

same message:
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()); 
}
?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

i'm a idiot =]

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)) { 
$user = $row["username"];
echo "$user";
} 
?>
This should atleast display the user colum to just see if it works.. I wish I had a website I can test this on so I know for sure its right but unfortnately I dont. sorry you have to put up with my dumbness.
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

ok, i think were getting closer:
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\ne0\index4.php on line 5

Code: Select all

<?php
mysql_connect(localhost,"ne0","****"); 
@mysql_select_db("db") or die( "Unable to select database"); 
$result = @mysql_query ("select * from users"); 
while ($row = mysql_fetch_object ($result)) { 
$user = $row["username"]; 
echo "$user"; 
} 
?>
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

MySQL_Fetch_Object? try mysql_fetch_array .
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Straterra wrote:MySQL_Fetch_Object? try mysql_fetch_array .
I give up, i dont know what I was thinking.
mysql_fetch_array is what you would want to use (even noticing now that is what you had in your code in the beginning)

call me hank with 3 bottles of empty rum when it comes to coding today
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\ne0\index4.php on line 5
someone up there dont want me or anyone else to get this to work...
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Post what code you have.
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

currently:

Code: Select all

<?php 
mysql_connect(localhost,"ne0","****"); 
@mysql_select_db("db") or die( "Unable to select database"); 
$result = @mysql_query ("select * from users"); 
while ($row = mysql_fetch_array($result)) { 
$user = $row["username"]; 
echo "$user"; 
} 
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Code: Select all

<?php 
mysql_connect(localhost,"ne0","****"); 
mysql_select_db("db") or die( "Unable to select database"); 
$result = mysql_query ("SELECT * FROM users"); 
while ($row = mysql_fetch_array($result)) { 
$user = $row['username']; 
echo $user; 
} 
?>

try that
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

thanks but:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\ne0\index4.php on line 5
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

Code: Select all

<?php 
mysql_connect(localhost,"ne0","****"); 
mysql_select_db("db") or die( "Unable to select database"); 
$result = mysql_query ("SELECT * FROM `users`")or die(mysql_error()); 
while ($row = mysql_fetch_array($result)) { 
$user = $row['username']; 
echo $user;
} 
?>

try this, if there something wrong with ur query, then it will tell you.
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

i figured something out, i dont have a parse error anymore, now i have:
SELECT Error: Table 'db.users' doesn't exist in Query: SELECT * FROM users
but i do have a page that creates the database, mabey someone can explain a little better how to create a table?

ps: i also have a page that added the content, mabey that didnt work as well....

thanks
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Use phpMyAdmin, it is invaluable when it comes to setting up databases and tables. Right now, you don't even have a table. You have to create it before you query it 8O

http://www.phpmyadmin.net/home_page/
Ne0
Forum Commoner
Posts: 60
Joined: Sat Feb 14, 2004 11:48 am

Post by Ne0 »

accualy i do have a table, atleast my page said i do.
error when creating table:Table 'users' already exists
so, now my prblem is that it didnt insert it correctly..
error when inserting:You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'users ('','Ne0','****','moo','My Signatu
so, i contact the webhost asking what server version it is....

no, onto phpMyAdmin....
i have a problem, i am using a free host, and they create the database on request, and yes i said the, as in one.

i have downloaded phpMyAdmin, and it was so confusing, that it didnt seem to aply to what i needed, or to a free host.



so thank u everyone that has helped me, i am onther few steps closer to finishing my site.
Last edited by Ne0 on Sun Feb 15, 2004 10:13 am, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You INSERT query looks invalid from the small error message you pasted. Looks like you have something like "INSERT INTO users ('','Ne0','****','****','My Signature')" when it should be "INSERT INTO users VALUES ('','Ne0','****',****','My Signature')"
Last edited by markl999 on Tue Feb 17, 2004 3:56 pm, edited 1 time in total.
Post Reply