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
Filtering Tables
Hello Thanks for any help any one can give Im very new to PHP..
I need to pull data for clien
using file_get_contents??
okay how would i create a script using file_get_contents() in php have it grab search pages 1-20 and
SAP Logon Failed
I tried to login to SAP through MMC.
When i click start and give password.
it
Auto install
Hi I have a directory lets say "apps" that I then have more folders ie "email",
Display data returned from Ajaxservices!!
I have a question about displaying results using ajax. I have part of the code below.
$.ajax({
Simpler method of getting variables from mysql
Hi Guys,
I'm trying to streamline my CMS's code and as I was writing a new page it occured to
Email Form Syntax Issue
I need the TO: in email to display To: CEO instead of To: abc@mail.com
How to alter the scri
Typedef struct vs just struct
Anyone know the rationale for using typedef for structs when a struct is itself a typedef? I have s
Check premium expire
Hi,
I am making a simple file hosting site and want to check if users premium subscriptions h
Using unserialize()
Hi there.
I have some data in my database that is serialized.
e.g.
a:2:{i:0