Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-31-2007, 04:46 PM MySQL Error in PHP
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
Ok here is the script:
PHP Code:
<?
$username
="troop439_wiki";
$password="wiki";
$database="troop439_wiki";

mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM wiki_users";
$result=mysql_query($query);

$num=mysql_num_rows($result);

mysql_close();

echo 
"<b><center>Users In Database</center></b><br><br>";

$i=0;
while (
$i $num) {

$id=mysql_result($result,$i,"user_id");
$name=mysql_result($result,$i,"user_name");
$qwt=mysql_result($result,$i,"user_real_name");
$xmt=mysql_result($result,$i,"user_password");
$zzz=mysql_result($result,$i,"user_newpassword");
$zmw=mysql_result($result,$i,"user_newpass_time");
$flk=mysql_result($result,$i,"user_email");
$flk1=mysql_result($result,$i,"user_options");
$flk2=mysql_result($result,$i,"user_touched");
$flk3=mysql_result($result,$i,"user_token");
$flk4=mysql_result($result,$i,"user_email_authenticated");
$flk5=mysql_result($result,$i,"user_email_token");
$flk6=mysql_result($result,$i,"user_email_token_expires");
$flk7=mysql_result($result,$i,"user_registration");
$flk8=mysql_result($result,$i,"user_editcount");



echo 
"<b>$id | $name</b>";

$i++;
}

?>
and when it runs i get:
Code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/********/public_html/displayusers.php on line 11

Last edited by melefire; 10-31-2007 at 04:47 PM..
melefire is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-31-2007, 05:01 PM Re: MySQL Error in PHP
stewart's Avatar
Novice Talker

Posts: 11
Name: Stewart Howe
Location: Denver, CO
Trades: 0
Well that means that your query string is incorrect.

$query="SELECT * FROM wiki_users";

I dont really see much wrong with it unless you simply do not have a table named wiki_users.....

$query="SELECT * FROM `wiki_users`;";

That is about all i can suggest to do ^
__________________
stewart::howe
Web Developer & Programmer

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
| CelerLabs.com
stewart is offline
Reply With Quote
View Public Profile Visit stewart's homepage!
 
Old 10-31-2007, 05:35 PM Re: MySQL Error in PHP
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
try
Code:
 $result=mysql_query($query) or die ('SQL error: '.mysql_error());
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 11-01-2007, 02:26 PM Re: MySQL Error in PHP
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
thanks for replies
but now after i made some more changes, when trying to select only certain data from the database it does not work.
New script:
PHP Code:
<?
$username
="troop439_wiki";
$password="wiki";
$database="troop439_wiki";
$search=$_POST['searchname'];

mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM `wiki_user` WHERE user_name=$search;";
$result=mysql_query($query) or die ('It apears the user does not exist: '.mysql_error());
$num=mysql_num_rows($result);

mysql_close();

echo 
"<b><center>Users In Database</center></b><br><br>";

$i=0;
while (
$i $num) {

$id=mysql_result($result,$i,"user_id");
$name=mysql_result($result,$i,"user_name");
$qwt=mysql_result($result,$i,"user_real_name");
$xmt=mysql_result($result,$i,"user_password");
$zzz=mysql_result($result,$i,"user_newpassword");
$zmw=mysql_result($result,$i,"user_newpass_time");
$flk=mysql_result($result,$i,"user_email");
$flk1=mysql_result($result,$i,"user_options");
$flk2=mysql_result($result,$i,"user_touched");
$flk3=mysql_result($result,$i,"user_token");
$flk4=mysql_result($result,$i,"user_email_authenticated");
$flk5=mysql_result($result,$i,"user_email_token");
$flk6=mysql_result($result,$i,"user_email_token_expires");
$flk7=mysql_result($result,$i,"user_registration");
$flk8=mysql_result($result,$i,"user_editcount");



echo 
"<b>$id | $name</b>";

$i++;
}

?>
Returns error
Code:
It apears the user does not exist: Unknown column 'testuser' in 'where clause'
i am sure that the user exists
melefire is offline
Reply With Quote
View Public Profile
 
Old 11-01-2007, 02:46 PM Re: MySQL Error in PHP
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
it's because a text value (or string) must be encased between single quotes to let the db distinguish value and column.
PHP Code:
$query="SELECT * FROM wiki_user WHERE user_name='$search';"
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-01-2007, 04:37 PM Re: MySQL Error in PHP
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
try this code instead of you're while
Code:
while ($row = mysql_fetch_assoc($result)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Reply     « Reply to MySQL Error in PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28566 seconds with 12 queries