Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

simple log in form issue

  • 26-08-2008 01:48PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    instead of $_POST try $_REQUEST

    edit:

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


  • Registered Users, Registered Users 2 Posts: 788 ✭✭✭sleepyescapade


    Got this sorted! Thanks for your reply


Advertisement