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
List/Menu Box
On an edit page when you want something to select what a user has previously selected from the datab
TabControl Inside ListView Not Editing
Hello everybodyI have a ListView on my page. Inside the ListView I put a TabControl, cuz I want to p
Dynamic memory problem
Hey,
At the beginning of my code, I have this line:
Shape* gShape = 0;
PHP error. Need help urgently
Hi,
I am programming a php site and have a problem that i just cant find out how to fix. When
help with multi-update
Now sure how to ask this really....
10g database if that matters.
I have a customer
Guixt issue
Hello all,
We are experiencing the following problem with Guixt:
Some transact
Variable passed to each() is not an array or object
Hi,
This is a email a friend type of form, and it isn't working anymore.
<?
Random Number Generation And Probability
Hello, I am working on a function which has to insert data into a SQL table.
we have to suppl
mysql_real_escape_string
Let me preface this that I am very much a PHP noob, but I have some SQL training (not necessarily My
Why doesn't this work? (SSH2)
This is my script:
Code: <?php
$connection = ssh2_connect('213.251.167.109', 22);