PHP Login Script
<?php
$con = mysql_connect('localhost', 'root', '');
$db_select = mysql_select_db('db_name', $con);
if(!db_select){
die("Error: No DataBase Selected.\n");
}
if(!$con){
die("Error: ".mysql_error()."\n");
}
?>
<form action='./login.php' method='POST'>
<table border='0' align='center'>
<tr><td>Username </td><td><input type='text' name='user'></td></tr>
<tr><td>Password </td><td><input type='password' name='pass'></td></tr>
<tr><td colspan='2' align='right'><input type='submit' name='login' value='Login'></td></tr>
</table>
</form>
<?php
$u = $_POST['user'];
$p = $_POST['pass'];
$log = $_POST['login'];
if($log){
$sql = mysql_query("SELECT count(id) FROM `users` WHERE `username` = '$u' AND `password` = '$p'");
$result = mysql_result(sql, 0);
if($result!=1){
die("Invalid Login Information\n");
}else{
echo "Welcome ".$u."! You are now logged in.\n";
}
}
?>
vijaysankarbhat 0 Newbie Poster
somedude3488 228 Nearly a Posting Virtuoso
phong1040572 0 Newbie Poster
sureronald 0 Junior Poster
ayesha789 7 Posting Pro in Training
leviathan185 14 Junior Poster
somedude3488 228 Nearly a Posting Virtuoso
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
jalaladdin 0 Newbie Poster
j_limboo 0 Junior Poster in Training
eltin_gee 0 Newbie Poster
rajpathak2000 0 Newbie Poster
manzarr 1 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.