is this the proper use of mysql_real_escape_string() to prevent sql injections?
Posted on
16th Feb 2014 07:03 pm by
admin
i was wondering is this the proper use of mysql_real_escape_string() to prevent sql injections? any help greatly appreciated. thanks. derek
Code: <?php
include("connect1.php");
Did you know?Explore Trending and Topic pages for more stories like this.
session_start(); // this is the session declaration , one per page.
$u = trim($_POST['username']);
$p = trim($_POST['password']);
$logoff = $_GET['logoff'];
$hack = $_GET['hack'];
if($logoff){
unset($_SESSION['userid']);
//session_destroy(); //commented out gets rid of the having to login twice.
$message = "You have been logged off";
}
if($hack){
$message = "Naughty Naughty!"; // COOL
}
// escape username and password for use in SQL
$u = mysql_real_escape_string($u);
$p = mysql_real_escape_string($p);
// if fields username and password have contents, then...
if($u && $p){
$query = mysql_query("SELECT * FROM table2 WHERE username = '$u' AND password = '$p'");
$result = mysql_fetch_array($query); //creates array called result,//notice we dont need a while loop here.
if($result['username']){
$message = "You have been logged in";
$_SESSION['userid'] = $result['username'];
header("Location:old.mainsite.php");
exit;
}else{
$message = "You do not exist on the system";
}
}
?>
No comments posted yet
Your Answer:
Login to answer
259
53
Other forums
Displaying an image using echo command
I had done a query on my database, one of the fields being an image reference to a directory where a
Login Issue's
Code: <?php
$file = fopen('user.txt', 'r');
/* Set login to false initially */
Printing issues with xMII 11.5
For some reason, we have one report (and only one) that is giving us fits when trying to print. The
Stumped by Third Day of Month problem
I am trying to build an algorithm that will essentially do this:
Code: [Select]$this_month = Oct
help removing unwanted graphic
How do I remove the small elongated rectangular shape between the "Latest post" and "
Parse Error with doctype
I'm getting a parse error with this simple code. I don't get it. It worked one time then when I relo
getting a website's source code as a variable? How?
Hey guys, is there any way for me to get the source code of a website as a variable for me to work w
Operator precedence assistance.
I did a quick Google search and couldn't quite find the answer I wanted in terms I could understand,
browse folder only
hi,
is there a way i can browse or get the directory or folder only and not the file?
i just w
PHP and SMS
Hi all forum members. I am new here and am unsure what category shoild I post this in.
Moderator