0

Hey everyone I was hoping if you can help me fix errors on a admin login form im using.

Heres the code

<?php

session_start();//works with session cookies, helps have persistant data i.e.  if user is not logged in there will be no session variable

if(isset($_SESSION["manager"])){//if it does not set session manager send it to the file location
	header("location:index.php");
	exit();
}

//parse the log in form if the user has filled out and pressed "Log in"

if(isset($_POST["username"])&&isset($_POST["password"]))
{
	
$manager = preg_replace('#[^A_Za-z0-9]#i',$_POST["username"]);//filter everything but numbers and letters  
$password = preg_replace('#[^A_Za-z0-9]#i',$_POST["password"]);//filter everything but numbers and letters
//connecting database

include_once '../store/connect.php';

$sql = mysql_query("SELECT id FROM admin WHERE username = '$manager' AND password ='$password' LIMIT1");//selecting data from databse
//...Double check if I entered user info in database.


$existCount = mysql_num_rows($sql);// count the row numbers

	if($existCount == 1)
	
	{//evaluates the count
		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 'the information is incorrect, try again<a href="index.php">Click here </a>';
			exit();
		}
		

}
		
  
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Store Admin page</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>

<div style="margin-left:24px; text-align:left;"><h2>Conten</h2></div>
<?php include_once'../template_header.php'  ?>

<body>
<div align="center" id="mainWrapper">
<div id="pageContent"><br />
<div style="margin-left:24px; text-align:left;"><h2>Log in </h2>

	<form id="form1" name ="form1" method="post" action="admin_login.php">	
	User Name<br />
	<input name ="username" type="text" id="username" size="40" />
     <br /> <br />
    password<br />
    
    <input name ="password" type="password" id="password" size="40" />
    <br />
    <br />
    <br />
   
    
     <input type ="submit" name="button" id="button" value="Log In" />
     
     
     </form>
     
     </div>
   </div>
    
	<?php include_once'../template_footer.php'  ?>


</body>
</html>

Error

Warning: preg_replace() expects at least 3 parameters, 2 given in F:\root\xampplite\htdocs\Ecomm\storeadmin\admin_login.php on line 15

Warning: preg_replace() expects at least 3 parameters, 2 given in F:\root\xampplite\htdocs\Ecomm\storeadmin\admin_login.php on line 16

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in F:\root\xampplite\htdocs\Ecomm\storeadmin\admin_login.php on line 25
the information is incorrect, try againClick here

I don't know why its happening but im following a tutorial

Heres the link on the 3rd part of the video

http://www.youtube.com/watch?v=dZrCNhp0t_w&feature=channel

I may have missed something but hopefully anyone can notice a simple error

Thanks

:)

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Imratzio
0

you have written the code wrongly

preg_replace takes 3 parameters - pattern,replacement,string

u have provided pattern and string but replacement is missing

0

The php function preg_replace has three parameters. You should write like this

preg_replace( $value-to-be-replaced, $new-value, $variable-to-be-updated);

0

Ah thanks for all your input. I didn't put the qoutes properly on the preg replace and I got rid of LIMIT 1 which I don't need and it worked :).

Thanks for your time :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.