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
Need help with a mail notify function
I was tasked with setting up a site that's been prewritten. The site is basically a form that captur
A Few Questions
Hi, I want to ask a few questions that I can't seem to find..
1) I'm creating a "shortcu
Extract text from string
Hi folks,
I have a string that looks like this:
aaaaaaaaaa:
bbbbbbbbbb (ccccccccc)
Paypal
Hi all,
I have an advanced basic knowledge of php
I want to try something new for a s
session checking in page load
hai all
I have a web site is www.Mryas.com in this my login page is Page1.aspx its co
want to add a break after a certain amount of characters
i was wondering how to add a break in a blog post after a certain amount of characters... any idea o
Php script to read msword file
hi,
I need to read a msword file and i want to print the contents in that word file.
i
PHP Search Issue
Hi, I am using the following code to search and return flights from a database. The user searches by
Question handling xml data
Hello,
I have sucessfull followed this tutorial
http://www.phpfreaks.com/tutorial/handlin
Binding 2 UDP sockets on same port, connected to different destinations, 1 receives
Hello,
My application wants to send/recv data to 2 different UDP ports on a remote computer, us