homepage Welcome to WebmasterWorld Guest from 54.161.228.29
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Problem with database reading
Where did the value go?
neiljones




msg:1283555
 8:59 pm on Aug 30, 2003 (gmt 0)

I'm new to PHP and I am doing a new site with it to learn.
This is doing my head in .I can't see why a variable is losing a value. There must be something I don't know. (or a very silly error somewhere.) Can anyone help?

This is the code with all the sensitive values removed.
I've marked the lines between which the value of $passworddb vanishes. The "loop indicator" is just there
to show that there is a single record in the database that matches.

<?php
if ($logon)
{
$host="*****";
$user= "*****";
$passwordl="****";
mysql_connect($host,$user,$passwordl);
mysql_selectdb("*****");
$query="select * from table where nickname='test'";
$back=mysql_query($query);
while (list($nicknamedb,$passworddb) = mysql_fetch_row($back))
{
print" Database password ".$passworddb."<br> \n"; # BETWEEN HERE
print "loop indicator<br>";
}
print "database password ".$passworddb." input password ".$password; #AND HERE
if ($passwordo!= $password)
{
$error1 ="Sorry, there is nobody registered with those details.";
}
}
?>
<form action="" method=post name="">
<input maxlength=10 name=nickname size=10>
<input maxlength=8 name=password size=8 type=password>
<input type="submit" name="logon" value="logon">
</form>
<? if ( $error1) {
echo"<b>".$error1."</b><br>";
}
?>

</BODY></HTML>
Here is the output.

Database password e98009
loop indicator
database password input password e98009

 

justageek




msg:1283556
 10:33 pm on Aug 30, 2003 (gmt 0)

Try.....mysql_fetch_array($back)

justageek




msg:1283557
 10:36 pm on Aug 30, 2003 (gmt 0)

Like this:

while($resultset = mysql_fetch_array($back)){
print" Database password ".$resultset['Password']."<br> \n";
}

Make sure that you match your column name you used for password in the quotes.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved