Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

simple log in form issue

Options
  • 26-08-2008 2:48pm
    #1
    Registered Users Posts: 788 ✭✭✭


    This is my form implemented on an index.html site page
    <div class="enter">
    <form name="form" action="checkLogin.php" method="post">
    <fieldset>
    
    <h5>Trade corner</h5>
    <div class="login">
    <label for="nameField">Name:</label>
    	<input type="text" name="username" id="nameField"
    		   value="log in"
    		   size="10" maxlength="10" /> </div>
    <div class="login"><label for="passwordField">Password:</label>
    	<input type="password" name="password" id="passwordField"
    		   size="10" maxlength="10" value="password" /><input type="image" src="images/txt/button.png" class="button" name="submitted"/> </a></div></fieldset> </form>
    	 <?php
    	 // Output each error message, if any
    	 foreach ($errors as $error)
    	 {
    		echo "<p>ERROR: {$error}</p>";
    	 }
    	?>
    		   </div>
    

    this is my checkLogin.php
    <?
     require("shop/admin/conf.php");
     function clean($str)
     {
    	return mysql_real_escape_string(trim($str));
     }
    
     $username = '';
     $passwd = '';
     $errors = array();
     if ( isset($_POST['submitted']) )
     {
    	$username = clean($_POST['username']);
    	if ( $username == '' )
    	{
    	   $errors[] = 'The user name must not be blank';
    	}
    	$passwd = clean($_POST['password']);
    	if ( $passwd == '' )
    	{
    	   $errors[] = 'The password must not be blank';
    	}
    	// Check whether this username and password match one in the database
    	 mysql_connect("$DBHost","$DBUser","$DBPass");
    	$sql = mysql("$DBName", "SELECT * FROM wine_login
    			 WHERE username = '$username'
    			   AND  password = '$passwd'");
    	$dbresult = mysql_query($sql);
    	if (mysql_num_rows($dbresult) != 1)
    	{
    	   $errors[] = "User name or password not known";
    	}
    	if ( count($errors) == 0 )
    	{
    	   // All is well with this user
    	   // Store his/her name in the session store and redirect to the protected content!
    	   session_start();
    	   $_SESSION['authenticated'] = 'yes';
    	   $_SESSION['username'] = $username;
    	   header('Location: tradecorner.html');
    	}
     }
     ?>
    

    and lastly, this is the page i want it to direct to when you log in:
    <?
      require("shop/admin/conf.php");
    include('header.inc');
     session_start();
     if ( ! isset($_SESSION['authenticated']) )
     {
    	die("You do not have permission to access this page");
     }
    ?>
    

    When i submit the log in details, my checkLogin comes up blank and so doesnt carry on to my redirection page? :( I discovered that the submitted button was not sending via POST. But i dont know why :(


Comments

  • Registered Users Posts: 3,594 ✭✭✭forbairt


    instead of $_POST try $_REQUEST

    edit:

    also whats the </a> for
    name="submitted"/> </a>


  • Registered Users Posts: 788 ✭✭✭sleepyescapade


    Got this sorted! Thanks for your reply


Advertisement