Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 13th, 2002, 02:44 AM
mell349 mell349 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 mell349 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
So simple but just won't work 2: The Revenge

I hope someone can help with this. It's similar to the So simple but just won't work post hence the title. I have this code which was taken from phpdeveloper.org although changed slightly and it looks like this:-

<html>

<head>

<title>User Page</title>

</head>

<body>

<?php
$db=mysql_connect("localhost","root");
mysql_select_db("login",$db);
$result=mysql_query("select * from member where name='$name'",$db);
while($row = mysql_fetch_array($result)){
if($row["pass"]==$pass){
print"Sucessfully logged in!";
}
}
?>

</body>

</html>

The needed variables are being sent from the previous page and are named 'name' and 'pass' - but whenever I try and run it I get this come up.

Warning: Supplied argument is not a valid MySQL result resource in C:apachehtdocstttestuser.php on line 15

line 15 is:
while($row = mysql_fetch_array($result)){

and I can't see what's going wrong. Can anyone help please?

Steve

Reply With Quote
  #2  
Old August 13th, 2002, 02:51 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: So simple but just won't work 2: The Revenge

What is most likely happening is that the database connection is failing, you are trying to select a database that does not exist, or you are trying to query a table that doesn't exist or doesn't have the fields you are looking for. Try this instead, so that you can determine the problem....

php Code:
Original - php Code
  1. <html>
  2. <head>
  3. <title>User Page</title>
  4. </head>
  5. <body>
  6. <?php
  7. $db=mysql_connect("localhost","root") or die ("Unable to connect to server.);
  8. mysql_select_db("login",$db) or die ("Unable to select database.);
  9. $result=mysql_query("select * from member where name='$name'",$db);
  10. if(!$result) { echo "Problem with query."; }
  11. while($row = mysql_fetch_array($result)){
  12. if($row["pass"]==$pass){
  13. print"Sucessfully logged in!";
  14. }
  15. }
  16. ?>
  17. </body>
  18. </html>

Reply With Quote
  #3  
Old August 13th, 2002, 02:53 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: So simple but just won't work 2: The Revenge

This:
$db=mysql_connect("localhost","root");

Should be:
$db=mysql_connect("localhost","root","password");

Reply With Quote
  #4  
Old August 13th, 2002, 02:58 AM
mell349 mell349 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 mell349 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: So simple but just won't work 2: The Revenge

OK - tried the first sugustion and got

Parse error: parse error in C:apachehtdocstttestuser.php on line 8

But the database I'm connecting to doesn't have a password, and I would have thought I would have a problem with line 12 if that were the case.

Reply With Quote
  #5  
Old August 13th, 2002, 03:26 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: So simple but just won't work 2: The Revenge

change:

$db=mysql_connect("localhost","root") or die ("Unable to connect to server.);

to:

$db=mysql_connect("localhost","root") or die ("Unable to connect to server.");


and


mysql_select_db("login",$db) or die ("Unable to select database.);

to:

mysql_select_db("login",$db) or die ("Unable to select database.");

forgot a a couple quotes...

Reply With Quote
  #6  
Old August 13th, 2002, 03:48 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: So simple but just won't work 2: The Revenge

OK that came up unable to connect to database. which is strange because it's the same database as used in the below code and that works fine.

<?php require_once('Connections/login.php'); ?>
<?php
mysql_select_db($database_login, $login);
$query_Recordset1 = "SELECT * FROM member";
$Recordset1 = mysql_query($query_Recordset1, $login) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>User Information taken from MYSQL Database:-</p>
<form name="form1" method="post" action="user.php">
<p>Username:
<input name="name" type="text" maxlength="20">
<br>
Password:
<input name="pass" type="text" maxlength="20">
</p>
<blockquote>
<blockquote>
<p>
<input name="submit" type="submit" id="submit" value="Submit">
</p>
</blockquote>
</blockquote>
</form>
<?php do { ?>
<div align="left">
<table width="30%" border="0">
<tr>
<td><div align="right">USER ID:</div></td>
<td><div align="left"><?php echo $row_Recordset1['id']; ?></div></td>
</tr>
<tr>
<td><div align="right">NAME:</div></td>
<td><div align="left"><?php echo $row_Recordset1['name']; ?></div></td>
</tr>
<tr>
<td><div align="right">PASSWORD:</div></td>
<td><div align="left"><?php echo $row_Recordset1['pass']; ?></div></td>
</tr>
</table>
</div>
<hr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > So simple but just won't work 2: The Revenge


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway