Forum Moderators: coopster
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="password"; // Mysql password
$db_name="test"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
session_start();
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
if ($userid && $password){
/////////////////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM users WHERE username='$userid' and password='$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
/////////////////////////////////////////////////////////////////////////
}
if ($rowAccount){
$_SESSION['id'] = $rowAccount['username'];
header("location:welcome.php");
exit;
}elseif($submitted){
echo "You dont exist in the system so your not getting in";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<table width="80%" border="0" align="center">
<tr>
<td colspan="4">Welcome to the website</td>
</tr>
<tr>
<td colspan="2"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="20%"><strong>Menu</strong></td>
<td colspan="2" rowspan="6" valign="top" width="60%">
<h2>Are you looking to rent Orlando Villas or Disney Villas for your next Florida Holiday/Vacation? You are!</h2>
<p>
Our experienced Orlando villa owners are here to help you with a straight forward uncomplicated booking process. All our Orlando villas and Disney area villas are individually owned by people just like you.</p>
<p>
They came :they saw and they bought so that you could enjoy Florida just as they had done before. You can rest assured that no owners registered with use intermediaries or agents:you deal only with the owner of your chosen property. All our villa owners are carefully selected to advertise on our site: this is why we do not advertise hundreds of villas. We select the best Orlando villa owners and reject the rest thereby ensuring only quality villas are offered.</p>
</p>
</td>
<td width="220" rowspan="4">
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELP'];?>">
<table width="20%" border="1">
<tr>
<td>User ID</td>
<td><input type="text" name="userid" id="userid" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" id="password" /></td>
</tr>
<tr>
<td> </td>
<td><label>
<input name="submitted" type="hidden" id="submitted" value="1" />
<input type="submit" name="button" id="button" value="Submit" />
</label></td>
</tr>
</table>
</form> </td>
</tr>
<tr>
<td>Search for a villa</td>
</tr>
<tr>
<td>Advertise a villa</td>
</tr>
<tr>
<td>About us</td>
</tr>
<tr>
<td>Contact</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="4">Footer</td>
</tr>
</table>
</body>
</html>
// Connect to server and select database.
$conn =mysql_connect($host, $username, $password)or die("Connection Error:".mysql_error());
mysql_select_db($db_name, $conn)or die("Database Selection Error:".mysql_error());
$result = @mysql_query($query);//<--Remove the @ symbol
$rowAccount = @mysql_fetch_array($result);//<--Remove the @ symbol
$userid = strip_tags(mysql_real_escape_string(trim($_POST['userid'])));
$password = strip_tags(mysql_real_escape_string(trim($_POST['password'])));
$submitted = strip_tags(mysql_real_escape_string(trim($_POST['submitted'])));
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELP'];?>">
$errmsg = '';
$userid = $_POST['userid'];
} elseif($submitted) {
$errmsg = "You dont exist in the system so your not getting in";
} <tr>
<td> </td>
<td><label>
<input name="submitted" type="hidden" id="submitted" value="1" />
<input type="submit" name="button" id="button" value="Submit" />
</label></td>
</tr>
<tr><td> </td><td><?php echo $errmsg; ?></td></tr>
function check_data($tbl) {
$errors=null;
// Note you need to check for POST first, otherwise you
// may get "undefined index: userid" ... etc. errors
if (! isset($_POST['submitted']) or (isset($_POST['submitted']) and empty($_POST['submitted'])) {
$errors .="<li>Please use the form to log in.</li>";
}
// If submitted is not present, no need to continue.
if ($errors) { return $errors; }
if (! isset($_POST['userid']) or (isset($_POST['userid']) and empty($_POST['userid'])) {
$errors .="<li>Please enter your user name.</li>";
}
if (! isset($_POST['password']) or (isset($_POST['password']) and empty($_POST['password'])) {
$errors .="<li>Please enter your password.</li>";
}
// If u and p not present, no need to continue.
if ($errors) { return $errors; }
// Otherwise, OK to set.
$userid = $_POST['userid'];
$password = $_POST['password'];
$query = sprintf("SELECT * FROM $tbl WHERE username='$userid' and password='$password'");
$result = mysql_query($query) or (return "could not check database for user.");
if ($rowAccount = mysql_fetch_array($result)) { $_SESSION['id'] = $rowAccount['username']; }
// Errors should be null.
return $errors;
}