|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||||
|
|||||
|
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:
|
|
#3
|
|||
|
|||
|
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"); |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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... |
|
#6
|
|||
|
|||
|
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); ?> |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > So simple but just won't work 2: The Revenge |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|