 |
|
|
10-31-2007, 04:46 PM
|
MySQL Error in PHP
|
Posts: 46
Name: matt
|
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..
|
|
|
|
10-31-2007, 05:01 PM
|
Re: MySQL Error in PHP
|
Posts: 11
Name: Stewart Howe
Location: Denver, CO
|
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
|
|
|
|
10-31-2007, 05:35 PM
|
Re: MySQL Error in PHP
|
Posts: 522
Name: Gabe Solomon
Location: Romania
|
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
|
|
|
|
11-01-2007, 02:26 PM
|
Re: MySQL Error in PHP
|
Posts: 46
Name: matt
|
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
|
|
|
|
11-01-2007, 02:46 PM
|
Re: MySQL Error in PHP
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
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.
|
|
|
|
11-01-2007, 04:37 PM
|
Re: MySQL Error in PHP
|
Posts: 522
Name: Gabe Solomon
Location: Romania
|
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
|
|
|
|
|
« Reply to MySQL Error in PHP
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|