ajsuk Posted January 8, 2007 Share Posted January 8, 2007 Here there, I'm _very_ new to MySQL (as in started today) so please be gentle hehe.I'm playing around with making a simple login system using a form to check login details and display results belonging to that user if login is correct. I've got this all working fine but ofcourse if the details are wrong it'd be nice if I could get it to print something rather than the user being left with a blank page.I'm guessing I need to check the form results (user and pass) against the the database records. I've tried this with an if statement but it doesn't seem to want to know.Any help would be great, thanks in advance! =)Heres my poor n00b attempt:[code]<?php$nameresult = $_POST['name'];$passresult = $_POST['pass'];$con = mysql_connect("localhost","<dbnamehere>","<dbpasshere>");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("db_testing", $con);$result = mysql_query("SELECT * FROM info WHERE name='$nameresult' && pass='$passresult'");while($row = mysql_fetch_array($result)) { echo "Welcome ".$row['name'] . " - " . $row['email'] . " - " . $row['pass']; echo "<br />"; if ($nameresult != $row['name'] && $passresult != $row['pass']) echo "login Bad"; }mysql_close($con);?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted January 8, 2007 Share Posted January 8, 2007 [code=php:0]if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) { echo "Welcome ".$row['name'] . " - " . $row['email'] . " - " . $row['pass']; echo "<br />";} else { echo "login Bad";}[/code] Quote Link to comment Share on other sites More sharing options...
hvle Posted January 8, 2007 Share Posted January 8, 2007 if you just want to authenticate the user, ie. check to see if the un/pw is a valid pair:$sql = "select count(*) from info where name='$nameresult' and pass='$passresult'";$rs = mysql_query($sql);$row = mysql_fetch_row($rs);$exist = $row[0];if ($exist == 1){ // user is successfully authenticated.}else{ // failed to authenticate} Quote Link to comment Share on other sites More sharing options...
ajsuk Posted January 8, 2007 Author Share Posted January 8, 2007 Thank ya both v kindly. =) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.