i've been trying forever to figure out a way to use a regular text
link in place of a submit button at the bottom of this. can't get it.
i'm just starting to learn php, so i'm stuck. any help at all would be
amazing.
<?php # Script 12.7 - login.php
// This is the login page for the site.
// Include the configuration file for error management and such.
require_once ('includes/config.inc');
// Set the page title and include the HTML header.
$page_title = 'Login';
include ('includes/header.html');
if (isset($_POST['submit'])) { // Check if the form has been
submitted.
require_once ('../../mysql_connect.p hp'); // Connect to the database.
if (empty($_POST['username'])) { // Validate the username.
$u = FALSE;
echo '<p><font color="red" size="+1">You forgot to enter your
username!</font></p>';
} else {
$u = escape_data($_P OST['username']);
}
if (empty($_POST['password'])) { // Validate the password.
$p = FALSE;
echo '<p><font color="red" size="+1">You forgot to enter your
password!</font></p>';
} else {
$p = escape_data($_P OST['password']);
}
if ($u && $p) { // If everything's OK.
// Query the database.
$query = "SELECT user_id, first_name, last_name, username FROM users
WHERE username='$u' AND password=PASSWO RD('$p')";
$result = @mysql_query ($query);
$row = mysql_fetch_arr ay ($result, MYSQL_NUM);
if ($row) { // A match was made.
// Start the session, register the values & redirect.
$_SESSION['username'] = $row[3];
$_SESSION['first_name'] = $row[1];
$_SESSION['user_id'] = $row[0];
ob_end_clean(); // Delete the buffer.
header ("Location: http://" . $_SERVER['HTTP_HOST'] .
dirname($_SERVE R['PHP_SELF']) . "/view_profile.ph p");
exit();
} else { // No match was made.
echo '<p><font color="red" size="+1">The username and password
entered do not match those on file.</font></p>';
}
mysql_close(); // Close the database connection.
} else { // If everything wasn't OK.
echo '<p><font color="red" size="+1">Pleas e try again.</font></p>';
}
} // End of SUBMIT conditional.
?>
<div id="Content">
<h1>Login</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myForm"
method="post">
<p><b>User Name:</b><br> <input type="text" name="username" size="10"
maxlength="20" value="<?php if (isset($_POST['username'])) echo
$_POST['username']; ?>" /></p>
<p><b>Password: </b><br> <input type="password" name="password"
size="20" maxlength="20" /></p>
<div align="left"><i nput type="submit" name="submit" value="Login"
/></div>
</div>
</form><!-- End of Form -->
<?php // Include the HTML footer.
include ('includes/footer.html');
?>
link in place of a submit button at the bottom of this. can't get it.
i'm just starting to learn php, so i'm stuck. any help at all would be
amazing.
<?php # Script 12.7 - login.php
// This is the login page for the site.
// Include the configuration file for error management and such.
require_once ('includes/config.inc');
// Set the page title and include the HTML header.
$page_title = 'Login';
include ('includes/header.html');
if (isset($_POST['submit'])) { // Check if the form has been
submitted.
require_once ('../../mysql_connect.p hp'); // Connect to the database.
if (empty($_POST['username'])) { // Validate the username.
$u = FALSE;
echo '<p><font color="red" size="+1">You forgot to enter your
username!</font></p>';
} else {
$u = escape_data($_P OST['username']);
}
if (empty($_POST['password'])) { // Validate the password.
$p = FALSE;
echo '<p><font color="red" size="+1">You forgot to enter your
password!</font></p>';
} else {
$p = escape_data($_P OST['password']);
}
if ($u && $p) { // If everything's OK.
// Query the database.
$query = "SELECT user_id, first_name, last_name, username FROM users
WHERE username='$u' AND password=PASSWO RD('$p')";
$result = @mysql_query ($query);
$row = mysql_fetch_arr ay ($result, MYSQL_NUM);
if ($row) { // A match was made.
// Start the session, register the values & redirect.
$_SESSION['username'] = $row[3];
$_SESSION['first_name'] = $row[1];
$_SESSION['user_id'] = $row[0];
ob_end_clean(); // Delete the buffer.
header ("Location: http://" . $_SERVER['HTTP_HOST'] .
dirname($_SERVE R['PHP_SELF']) . "/view_profile.ph p");
exit();
} else { // No match was made.
echo '<p><font color="red" size="+1">The username and password
entered do not match those on file.</font></p>';
}
mysql_close(); // Close the database connection.
} else { // If everything wasn't OK.
echo '<p><font color="red" size="+1">Pleas e try again.</font></p>';
}
} // End of SUBMIT conditional.
?>
<div id="Content">
<h1>Login</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myForm"
method="post">
<p><b>User Name:</b><br> <input type="text" name="username" size="10"
maxlength="20" value="<?php if (isset($_POST['username'])) echo
$_POST['username']; ?>" /></p>
<p><b>Password: </b><br> <input type="password" name="password"
size="20" maxlength="20" /></p>
<div align="left"><i nput type="submit" name="submit" value="Login"
/></div>
</div>
</form><!-- End of Form -->
<?php // Include the HTML footer.
include ('includes/footer.html');
?>
Comment