Jump to content

[SOLVED] Using isset to run some php when form is submitted.


dprichard

Recommended Posts

I am trying to modify the login script one of the moderators here pointed me to.  It looks like it is working for me but I need it to only run after someone submits the form.  I tried adding isset, but when I did it just post back and does perform the query.

 

Here is my php

 

<?php 
session_start();
require_once('../Connections/prbc.php');

if(isset($_POST['login'])){
$username = '';
$password = '';

if (isset ($_POST['username']) && $_POST['username'] != '')

$username = $_POST['username'];

if(isset ($_POST['password']) && $_POST['password'] != '')

$password = $_POST['password'];

$username = mysql_real_escape_string( $username );
$password = mysql_real_escape_string( $password );

$db_password = md5($password);

mysql_select_db('prbcweb') or die(mysql_error());
$login = mysql_query("SELECT * FROM prbc_user WHERE `user_name` = '$username' AND `user_pass` = '$db_password'");
$row_login = mysql_fetch_array($login);
$row_login_total = mysql_num_rows($login);

if ($row_login_total == 1) {
$_SESSION['MM_Username'] = $row_login['user_name'];
$_SESSION['UID'] = $row_login['user_id'];
header("Location: approver.php");

} elseif ($row_login_total <> 1) {
header("Location: login_2.php");
}
}
?> 

 

And here is my form.  I am not sure what I am doing wrong.  Any assistance would be greatly appreciated.

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" name="login" id="login">
              <p>Username: <br>
                <input name="username" type="text" id="username">
</p>
              <p>Password:<br>
                <input name="password" type="password" id="password"> 
</p>
              <p>
                <input type="image" name="submit" src="../images/button_login.gif" width="100" height="26">
</p>
              </form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.