/    Sign up×
Community /Pin to ProfileBookmark

sql injections problem

i am trying to protect my login form being sql injected now i tried to do it myself and got it stuck this is what my problem is

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /home/william2/public_html/clansite/login.php on line 8
SELECT * FROM members WHERE username=”

on line 8 i have this

$cQuery=”SELECT * FROM members WHERE username='”.mysqli_real_escape_string(stripslashes(trim($_POST[‘username’]))).”‘”;

and on line 9 i have to define the link to my connection:
$con;

What i am missing?

this is the whole code

[code=php]
<?php
session_start();
include(“dbconnect.php”);
$msg_pass=””;
$msg_user=””;
if($_POST[‘username’] && $_POST[‘password’])
{
$cQuery=”SELECT * FROM members WHERE username='”.mysqli_real_escape_string(stripslashes(trim($_POST[‘username’]))).”‘”;
$con;
echo $cQuery;
$rs=mysqli_query($con,$cQuery);
if(!$rs)
{
echo “Unable to excute the query:”.mysqli_error($con);
}
else
{
$count=mysqli_num_rows($rs);
if($count>0)
{
$data=mysqli_fetch_assoc($rs);
if($data[‘password’]=$password)
{
$_SESSION[‘user’]=$_POST[‘username’];
include(“consoleincludes/console.inc.php”);
}
else
{
$msg_pass=”Wrong Password,Please Try again<br>n”;
include(“includes/attemptloginfailed.inc.php”);
}
}
else
{
$msg_user=”Wrong Username,Please Try again<br>n”;
include(“includes/attemptloginfailed.inc.php”);
}
}
if(!$_SESSION[‘user’])
{
include(“includes/header.inc.php”);?>
<fieldset>
<legend><font color=”#FFFFFF”>Please Login</font></legend>
<form name=”login” method=”post” action=””>
<?
echo ($msg_user)?”<br/>”.$msg_user.”<br/>”:””;
?>
<font color=”#FFFFFF”>Username:</font><input type=”text” name=”username” maxlength=”14″/><br/>
<?
echo($msg_pass)?”<br/>”.$msg_pass.”<br/>”:””;
?>
<font color=”#FFFFFF”>Password:</font><input type=”password” name=”password” maxlength=”12″/><br/>
<input type=”submit” name=”login” value=”login”/>
</form></fieldset><?php
}
}
?>
[/code]

Does anyone know how i can i fix this?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 10.2006 — The error message means exactly what it says: the [url=http://www.php.net/mysqli_real_escape_string]mysqli_real_escape_string()[/url] function requires two arguments when used in a procedural mode as in your example: a mysqli link and the string to be escaped. You are only providing the second of those two. (If you use it in an object-oriented style, it only requires the one string argument.)
×

Success!

Help @william232 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...