php - Issue with retrieving some values out of my Database -
<?php include 'session.php'; ?> <html> <head> <link href="css/adminopmaak.css" rel="stylesheet" type="text/css"/> <?php mysql_connect("localhost", "admin", "") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); ?> </head> <body> <div class = "header"> <a href="index.php"><img src="home-icon.png" width="25" height ="25"></a> </div> <!--header--> <div class = "menu"> </div> <!--menu--> <div class ="content"> <form action="login.php" method="post"> <input type="text" align="center" name="account" value="<?php echo isset ($_post['account'])?$_post['account']:"";?>"/> <br /> <input type="text" align="center" name="password" value="<?php echo isset ($_post['password'])?$_post['password']:"";?>" /><br /> <input type="submit" name="login" value="login"/><br /> <?php if(isset ($_post ['login'])) { $querystring ="select account admins account ='".$_post['account']."';"; $result = mysql_query($querystring); mysql_query($querystring)or die (mysql_error()); if (empty($_post['account']) || empty($_post['password'])) { echo "niet alles ingevoerd"; } elseif (mysql_num_rows($result) == 1) { $user = mysql_fetch_assoc($result); } else { echo "dit account bestaat niet"; } if(md5($_post['password']) != $user['password']) { echo "wachtwoord niet correct";?><br/> <?php echo "het account is:".$user['account'];?><br/> <?php echo "het wachtwoord is: ".$user['password'];?><br/> <?php echo mysql_fetch_assoc($result); } } ?> </form> </div> </body> </html>
it's kinda strange since recognize $user['account']; , doesnt recognize password version.
my database has right values. echo's:
wachtwoord niet correct het account is:probeersel het wachtwoord is:
so dont know why recognize account doesn't recognize wachtwoord. why that?
there few problems.
first, mysql statement wrong.
change this:
$querystring ="select account admins account ='".$_post['account']."';";
to this:
$querystring ="select * admins account ='" .$_post['account']. "'";
next, 1 test, echo out account name , password db query, can make sure getting expect (perhaps capitalization wrong field name or that).
$user = mysql_fetch_assoc($result); echo 'got username: ' .$user['account']. '<br />'; echo 'got password: ' .$user['password']. '<br />';
once have confidence getting correct data, can finish script.
this:
if(md5($_post['password']) != $user['password']) { echo "wachtwoord niet correct";?><br/> <?php echo "het account is:".$user['account'];?><br/> <?php echo "het wachtwoord is: ".$user['password'];?><br/> <?php echo mysql_fetch_assoc($result); }
can re-written as:
if(md5($_post['password']) != $user['password']) { echo "wachtwoord niet correct<br />"; echo "het account is: " .$user['account']. "<br />"; echo "het wachtwoord is: " .$user['password']. "<br />"; }
Comments
Post a Comment