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.

Please help php coding

  • 13-11-2012 11: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,991 ✭✭✭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,475 ✭✭✭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