Gruzin Posted July 28, 2006 Share Posted July 28, 2006 hi,I'am tyring to make a simple login form. username and password is saved in db, I want to check if the inputed information from form is the same saved in db. here is my code, hope someone can help me..... thanks.<?php$link = "http://www.3d.caucasus.net/test/";$linkShow = "Invalid username or password"; $con = mysql_connect("localhost","3d","password"); // connect to dbif(!$con) { die('Could not connect:'.mysql_error()); // error if not connected}mysql_select_db("$3d",$con); //select db$result = mysql_query("SELECT * FROM password"); // select data form "password"while($row = mysql_fetch_array($result)) //select data from db and store it in $row{ if($row == '[user]'&&'[pass]'){ header( 'Location: http://www.3d.caucasus.net/test/admin.php' ) ; // correct redirect}else echo "<a href='".$link."'>".$linkshow;}if(!mysql_query($con,$result)) { die('Could not connect:'.mysql_error());}mysql_close($con); // close connection?> Quote Link to comment https://forums.phpfreaks.com/topic/15886-mysql-help-needed/ Share on other sites More sharing options...
ToonMariner Posted July 28, 2006 Share Posted July 28, 2006 $user = mysql_escape_string($_POST['user']);$pwrd= mysql_escape_string ($_POST['pwrd']);$query = "SELECT * FROM `users` WHERE `username` = '$user' AND `password` = '$pwrd''";$query = mysql_query($qry);if (mysql_num_rows($query) == 0){ echo "Not recognized";}if (mysql_num_rows($query) > 1){ echo "Duplicate detection"; // write some code to alert aite admin of problem;}if (mysql_num_rows($query) == 1){ header( 'Location: http://www.3d.caucasus.net/test/admin.php' ) ;}you could make that nicer with a switch statement but I couldn't be arsed today! Quote Link to comment https://forums.phpfreaks.com/topic/15886-mysql-help-needed/#findComment-65165 Share on other sites More sharing options...
Gruzin Posted July 28, 2006 Author Share Posted July 28, 2006 ok, thanks, I'll try that:) Quote Link to comment https://forums.phpfreaks.com/topic/15886-mysql-help-needed/#findComment-65173 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.