medicatedsquid
06-29-2007, 10:44 PM
Hi. I'm trying to learn PHP, and I have a good idea on what to do on some things, but this one I have absolutely no idea. So, please go easy on me.
Anyways, I'm using a MySQL table called 'manager_users' with three columns. One column is the user name column (user_name), the second is the password column (password), and the third is the e-mail address column (e-mail_address). My code is set up like this, the form is on a page (?page=) and my action for the form on the page is like this (?action=log_in). So, I think I have the log in down, but I'm not sure. I need a way to make sure it's actually logging in, and I need a way to make sure it's logging out. Also, I don't know how I would, but I need it to check the forms so that when a form is left blank, it notifies the user.
Here's the code:
<?php
session_start();
mysql_connect('mysql.medicatedsquid.com', 'medicatedsquid', '18e1ns');
mysql_select_db('medicatedsquid');
switch($_GET['page']) {
/* Home Page/Log In */
case '';
if($_SESSION ['logged_in'] = 'false') {
echo 'welcome. <a href="?action=log_out">log out</a>';
} else {
echo '<form method="post" action="?action=log_in">
<table align="center" border="0" cellspacing="10" cellpadding="0">
<tr>
<td>User Name:</td>
<td><input type="text" name="user_name" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="text" name="password" />
</tr>
<tr>
<td></td>
<td><input type="submit" name="log_in" value="Log In" /></td>
</tr>
</table>
</form>';
}
break;
}
switch($_GET['action']) {
/* Log In Action */
case 'log_in';
$user_name = $_POST['user_name'];
$user_name = $_SESSION['user_name'];
$password = $_POST['password'];
$query1 = mysql_query("SELECT * FROM manager_users WHERE user_name = '$user_name' and password = '$password'");
$num_rows1 = mysql_num_rows($query1);
if($num_rows > 0) {
$_SESSION['logged_in'] = 'true';
} else {
$_SESSION['logged_in'] = 'false';
}
break;
/* Log Out Action */
case 'log_out';
$_SESSION['logged_in'] = 'false';
session_destroy();
break;
}
?>
(Yes, I know, I didn't tab my code.) Thanks in advance!
Anyways, I'm using a MySQL table called 'manager_users' with three columns. One column is the user name column (user_name), the second is the password column (password), and the third is the e-mail address column (e-mail_address). My code is set up like this, the form is on a page (?page=) and my action for the form on the page is like this (?action=log_in). So, I think I have the log in down, but I'm not sure. I need a way to make sure it's actually logging in, and I need a way to make sure it's logging out. Also, I don't know how I would, but I need it to check the forms so that when a form is left blank, it notifies the user.
Here's the code:
<?php
session_start();
mysql_connect('mysql.medicatedsquid.com', 'medicatedsquid', '18e1ns');
mysql_select_db('medicatedsquid');
switch($_GET['page']) {
/* Home Page/Log In */
case '';
if($_SESSION ['logged_in'] = 'false') {
echo 'welcome. <a href="?action=log_out">log out</a>';
} else {
echo '<form method="post" action="?action=log_in">
<table align="center" border="0" cellspacing="10" cellpadding="0">
<tr>
<td>User Name:</td>
<td><input type="text" name="user_name" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="text" name="password" />
</tr>
<tr>
<td></td>
<td><input type="submit" name="log_in" value="Log In" /></td>
</tr>
</table>
</form>';
}
break;
}
switch($_GET['action']) {
/* Log In Action */
case 'log_in';
$user_name = $_POST['user_name'];
$user_name = $_SESSION['user_name'];
$password = $_POST['password'];
$query1 = mysql_query("SELECT * FROM manager_users WHERE user_name = '$user_name' and password = '$password'");
$num_rows1 = mysql_num_rows($query1);
if($num_rows > 0) {
$_SESSION['logged_in'] = 'true';
} else {
$_SESSION['logged_in'] = 'false';
}
break;
/* Log Out Action */
case 'log_out';
$_SESSION['logged_in'] = 'false';
session_destroy();
break;
}
?>
(Yes, I know, I didn't tab my code.) Thanks in advance!