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

Heres the code


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

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

$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;
			echo 'the information is incorrect, try again<a href="index.php">Click here </a>';


<!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">
<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" />

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

<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" />
	<?php include_once'../template_footer.php'  ?>



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


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



Recommended Answers

All 4 Replies

you have written the code wrongly

preg_replace takes 3 parameters - pattern,replacement,string

u have provided pattern and string but replacement is missing

preg_replace() requires 3 parameters given to it like the error displays. Here is the PHP manual which shows an example of this http://php.net/manual/en/function.preg-replace.php

In line 21 for the mysql_query the LIMIT1 should actually be LIMIT 1 with a space between.

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);

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.