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
word wrap in emails help needed
Hello, I understand how wordwrap works in php and have used it well before. However when I used wor
Share admin accross websites
I'm using .net memberships and roles in one of my sites, but I need to be able to share logins and p
styling a RadioButtonList
HiI need to have a radio button and close to it, its lable, then a space then another set of those.
Take info from one coloum and move to another
Hi all,
I have this:
Code: [Select]$array = "SELECT stock_id FROM stocks WHERE stock_
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
Help on code output
My CODE:
Code: [Select] echo "<phone>".$line["phone"].&qu
Problem in String replace program's output
Hi all,
I was trying to make a program which accepts a string and replaces it with another stri
Database 'Validation'
Hi everyone,
I'm trying to validate the password entered by the user with the password in the dat
pspell
using pspell, is it possible to get words that would be best in the current phrase?
For examp
Multipe Dynamic Controls & AutoPostback Issue
I currently have a need to create many dynamic controls (Example Textboxes) that need to do a PostBa