Re: authenticating users with php&mysql

From: Date: Wed, 26 Jan 2005 13:26:34 +0000
Subject: Re: authenticating users with php&mysql
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-38357@lists.php.net to get a copy of this message
On Wed, 2005-01-26 at 12:44 +0200, it clown wrote: > $db_user = $_POST["txt_name"]; > $db_password = $_POST["txt_password"]; > $db_name = "data"; > $connection = @mysql_connect ($db_host, $db_user, > $db_password) or die ("error connecting"); > echo "connection successful!"; > ?> Replace this line - $connection = @mysql_connect ($db_host, $db_user, $db_password) or die ("error connecting"); - with this one - $connection = @mysql_connect($db_host, $db_user, $db_password) or die ("Error connecting : " .mysql_error()); - so you can debug better. However take a look here www.php.net/mysql_connect . $db_user and $db_password are the username and password to log on the MYSQL DATABASE. You probably want to login from a database table which will contain a password and username field. Here's an example : $dbHandle = mysql_connect($host, $user, $pass) or die (mysql_error()); mysql_select_db($db_name); $sql = "SELECT * FROM table_name WHERE user_field = '" . $_POST["txt_name"] . "' AND pass_field = '" . md5($_POST["txt_password"]) . "' LIMIT 1"; $result = mysql_query($sql, $dbHandle); if(mysql_num_rows($result)!=0) /* Logged on */ else /* Invalid Username/Password */ There're lots of tutorials out there, google's your friend. P.S. This is my first message on this maillist so I want to say hello to everyone ;-) -- Josip Dzolonga, dzolonga at mt dot net dot mk

« previous php.db (#38357) next »