Sir I have following codes
<?php
// Connection variables
$host = "localhost";
$username = "root";
$password = "";
$db_name = "phonebook";
$con = mysql_connect($host, $username, $password, $db_name);
if (!$con) {
echo ('<script type="text/javascript">alert("Error Connecting to database")' . mysql_connect_error($con) . '</script>');
}
$result = "";
$username = "";
$password = "";
function clean($str)
{
$cstr = trim($str);
$cstr = addslashes($str);
$cstr = htmlspecialchars($str);
return $cstr;
}
if (isset($_POST['login'])) {
session_start();
$myusername = clean($_POST['username']);
$mypassword = clean($_POST['password']);
if (empty($myusername) || empty($mypassword)) {
echo '<script>alert("User name or password must not be empty")</script>';
} else {
$query = "SELECT * FROM admin where username ='" . $myusername . "' and password='" . $mypassword . " ' ";
$result = mysql_query($query) or die(mysql_error());
}
if (!$result) {
echo ('<script type="text/javascript">alert("username, password query is not working")' . mysql_error($con) . '</script>');
}
$count = mysql_num_rows($result);
if ($count == 1) {
session_register("myusername");
$_SESSION['myusername'] = $myusername;
header("location: welcome.php");
} else {
$error = "Your Login Name or Password is invalid";
}
}
?>
Code says:
No database is selected.
Database image is as follows:
[IMG]http://i43.tinypic.com/2j1rdco.jpg[/IMG]