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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Please help php coding

  • 13-11-2012 10:54pm
    #1
    Registered Users, Registered Users 2 Posts: 1,298 ✭✭✭


    <?php
    session_start();
    if(isset($_SESSION["manager"]))
    {
    header("location:index.php");
    exit();
    }

    ?>
    <?php
    if(isset($_POST["username"])&& isset($_POST["password"]));
    {
    $manager = preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]);
    $password = preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]);
    include"../storescripts/connect_to_mysql.php";
    $sql = mysql_query("SELECT id FROM admin WHERE
    username='$manager' AND
    password='$password' LIMIT 1");

    $existCount = mysql_num_rows($sql);
    if ($existCount == 1)
    {
    while ($row = mysql_fetch_array($sql)){
    $id = $row["id"];
    }
    $_SESSION["id"] = $id;
    $_SESSION["manager"] = $manager;
    $_SESSION["password"] = $password;
    header("location:index.php");
    exit();
    }
    else {echo 'That Information is incorrect, try again
    <a href="index.php">Click Here</a>';
    exit();
    }
    }


    its ment to be a login to a inventory management section of a website but it keeps skipping past the html form and straight to the echo that is in the last part of the script. Any help would be amazing.


Comments

  • Registered Users, Registered Users 2 Posts: 1,987 ✭✭✭Ziycon


    Not sure were your form is but try this code below.
    <?php
    session_start();
    if(isset($_SESSION["manager"])) {
    	header("location:index.php");
    	exit();
    }
    ?>
    <?php
    if(isset($_POST["username"])&& isset($_POST["password"])) {
    	$manager = preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]);
    	$password = preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]);
    	include"../storescripts/connect_to_mysql.php";
    	$sql = mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1");
    
    	$existCount = mysql_num_rows($sql);
    	if ($existCount == 1) {
    		while ($row = mysql_fetch_array($sql)) {
    			$id = $row["id"];
    		}
    		$_SESSION["id"] = $id;
    		$_SESSION["manager"] = $manager;
    		$_SESSION["password"] = $password;
    		header("location:index.php");
    		exit();
    	} else {
    		echo 'That Information is incorrect, try again <a href="index.php">Click Here</a>';
    		exit();
    	}
    }
    ?>
    


  • Registered Users, Registered Users 2 Posts: 1,298 ✭✭✭off.the.walls


    Its working, What did you do different in your code?


  • Registered Users, Registered Users 2 Posts: 6,465 ✭✭✭MOH


    You had a stray semi-colon in the first if:
    if(isset($_POST["username"])&& isset($_POST["password"]))[B];[/B]
    


  • Registered Users, Registered Users 2 Posts: 1,298 ✭✭✭off.the.walls


    thank you guys so much that was wrecking my head!


Advertisement