dprichard Posted June 18, 2007 Share Posted June 18, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/56033-solved-using-isset-to-run-some-php-when-form-is-submitted/ Share on other sites More sharing options...
soycharliente Posted June 18, 2007 Share Posted June 18, 2007 Try changing the image button to type submit, use CSS to get the right width/height/bg-image, and change the isset test from $_POST["login"] to $_POST["whatever_name_you_call_the_submit_button"]. Quote Link to comment https://forums.phpfreaks.com/topic/56033-solved-using-isset-to-run-some-php-when-form-is-submitted/#findComment-276737 Share on other sites More sharing options...
dprichard Posted June 18, 2007 Author Share Posted June 18, 2007 Okay, it works if I change the input type to submit. Is there no way to use an image for the submit button and still do this? Quote Link to comment https://forums.phpfreaks.com/topic/56033-solved-using-isset-to-run-some-php-when-form-is-submitted/#findComment-276760 Share on other sites More sharing options...
dprichard Posted June 18, 2007 Author Share Posted June 18, 2007 Nevermind found an answer. Read your post again and saw the part about css. Quote Link to comment https://forums.phpfreaks.com/topic/56033-solved-using-isset-to-run-some-php-when-form-is-submitted/#findComment-276768 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.