• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Script not working (PHP)

wickedgenius

New Member
Hi can anyone say why this script is not working:

PHP:
<?php
session_start();

function doDB() {
	global $mysqli;

	//connect to server and select database; you may need it
	$mysqli = mysql_connect("localhost", "aurillia_wicked", "maisie") or die(mysql_error());
	mysql_select_db("aurillia_clandb") or die(mysql_error());
}


if (!$_SESSION["loggedin"]){
	if ($_POST["invalid"] = "pass"){
		$display_block = "
			<font color=\"#FF0000\">
			Invalid Password!
			</font><br />";
	} else if ($_POST["invalid"] = "username"){
		$display_block = "
			<font color=\"#FF0000\">
			No Such User!
			</font><br />";
	}
	$display_block .= "
		Please Log in!<br /><br />

		<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
		<p><stong>Username:</strong><input type=\"text\" name=\"user\">

		<p><strong>Password:</strong><input type=\"password\" name=\"pass\">

		<p><input type=\"submit\" name=\"submit\" value=\"Login\"></form>";

	$_SESSION["loggedin"] = "1";

} else if ($_SESSION["loggedin"] = "1"){
	doDB();

	$username = $_POST["username"];
	$check_sql = "SELECT id FROM administrators WHERE username = '".$username."'";
	$check_res = "mysql_query($check_sql, $mysqli) or die(mysql_error());

	if (mysql_num_rows($check_res) < 1) {
		session_destroy();
		$_POST["invalid"] = "username";
		header("Location: $_SERVER['PHP_SELF']");
	} else {
		$check_pass = "SELECT password FROM administrators WHERE username = '".$username."'";
		$check_pass_res = "mysql_query($check_pass, $mysqli) or die(mysql_error());
		$info = mysql_fetch_array($check_pass_res);
		if ($info["password"] = $_POST["pass"]){
			$_SESSION["loggedin"] = "2";
		} else {
		$_POST["invalid"] = "pass";
		header("Location: $_SERVER['PHP_SELF']");
		}
	}
} else if ($_SESSION["loggedin"] = "2"){
	$display_block = "
		Welcome to the Admin Area. At the minute theres not alot here but<br />
		when the site has been launched it will be jam-packed with things<br />
		to do.";
} else {
	session_destroy();
	header("Location: $_SERVER['PHP_SELF']");
}
?>

<html>
<head>
<title> :: Aurillian Remnent :: </title>
</head>
<body link="#ffffff" alink="#ffffff" vlink="#ffffff" >
<div align="center">
	<img src="titlebanner.jpg" border=1 bordercolor="#ffffff" width="600">
</div>
<br />
<table cellpadding="10" width="100%">
	<tr>
		<td width="5%">
			<?php include("nav.php"); ?>
		</td>
		<td>
			<font color="#ffffff" face="comic sans ms">
			<div align="center">
			<?php echo "$display_block"; ?>

Any help is appretiated.
 
Here try this code

PHP:
<?php
session_start();

function doDB() {
    global $mysqli;

    //connect to server and select database; you may need it
    $mysqli = mysql_connect("localhost", "aurillia_wicked", "maisie") or die(mysql_error());
    mysql_select_db("aurillia_clandb") or die(mysql_error());
}


if (!$_SESSION["loggedin"]){
    if ($_POST["invalid"] = "pass"){
        $display_block = "
            <font color=\"#FF0000\">
            Invalid Password!
            </font><br />";
    } else if ($_POST["invalid"] = "username"){
        $display_block = "
            <font color=\"#FF0000\">
            No Such User!
            </font><br />";
    }
    $display_block .= "
        Please Log in!<br /><br />

        <form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
        <p><stong>Username:</strong><input type=\"text\" name=\"user\">

        <p><strong>Password:</strong><input type=\"password\" name=\"pass\">

        <p><input type=\"submit\" name=\"submit\" value=\"Login\"></form>";

    $_SESSION["loggedin"] = "1";

} else if ($_SESSION["loggedin"] = "1"){
    doDB();

    $username = $_POST["username"];
    $check_sql = "SELECT id FROM administrators WHERE username = '".$username."'";
    $check_res = mysql_query($check_sql, $mysqli) or die(mysql_error());

    if (mysql_num_rows($check_res) < 1) {
        session_destroy();
        $_POST["invalid"] = "username";
        header("Location: $_SERVER['PHP_SELF']");
    } else {
        $check_pass = "SELECT password FROM administrators WHERE username = '".$username."'";
        $check_pass_res = mysql_query($check_pass, $mysqli) or die(mysql_error());
        $info = mysql_fetch_array($check_pass_res);
        if ($info["password"] = $_POST["pass"]){
            $_SESSION["loggedin"] = "2";
        } else {
        $_POST["invalid"] = "pass";
        header("Location: $_SERVER['PHP_SELF']");
        }
    }
} else if ($_SESSION["loggedin"] = "2"){
    $display_block = "
        Welcome to the Admin Area. At the minute theres not alot here but<br />
        when the site has been launched it will be jam-packed with things<br />
        to do.";
} else {
    session_destroy();
    header("Location: $_SERVER['PHP_SELF']");
}
?>

<html>
<head>
<title> :: Aurillian Remnent :: </title>
</head>
<body link="#ffffff" alink="#ffffff" vlink="#ffffff" >
<div align="center">
    <img src="titlebanner.jpg" border=1 bordercolor="#ffffff" width="600">
</div>
<br />
<table cellpadding="10" width="100%">
    <tr>
        <td width="5%">
            <?php include("nav.php"); ?>
        </td>
        <td>
            <font color="#ffffff" face="comic sans ms">
            <div align="center">
            <?php echo "$display_block"; ?>
 
Super Wolves out of interest have you just taken the " out of the following line

PHP:
$check_pass_res = "mysql_query($check_pass, $mysqli) or die(mysql_error());

I can see that now but there is still a problem I get the following error:

Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/aurillia/public_html/admin_index.php on line 46

The scrip is a login script which goes through and checks if the session variable is set to nothing (not logged in), set to 1 (logging in) or set to 2 (logged in).

Oh yea ignore any comments its sort of got a couple of copied bits of code in it. The copied bits work in the other pages.
 
remove it "
PHP:
$check_pass_res = mysql_query($check_pass, $mysqli) or die(mysql_error());
Super Wolves out of interest have you just taken the " out of the following line

PHP:
$check_pass_res = "mysql_query($check_pass, $mysqli) or die(mysql_error());

I can see that now but there is still a problem I get the following error:



The scrip is a login script which goes through and checks if the session variable is set to nothing (not logged in), set to 1 (logging in) or set to 2 (logged in).

Oh yea ignore any comments its sort of got a couple of copied bits of code in it. The copied bits work in the other pages.
 
I have got one that I'm using temperarily but if this one can't be sorted i'll continue to use the temparary one as a permanent one. So if anyone can fix the one in this topic fair enough but its no big problem now.
 
Back
Top