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
There was a problem with the request. (Code: 0)
Any Idea what could cause this? I get it randomly at best. But with both IE and FF. It derives from
Cache PHP Objects/Classes?
Does anyone have ideas about caching PHP objects using something like: http://memcached.org/
Character increment
Hi,
I am facing a scenario like above,but in my case i want to show up like Col A,Col B etc..
How to set pass login name from htaccess to php
When the user logs into my members page via htaccess, I'd like to retain the username so that I can
data type in column definition
Hi,
I create a table with column called "Direction of Travel code ".
The travel codes in t
How do I create a 2D game "camera" to follow player?
In J2ME programming I'm targeting MIDP 2.0 devices.
I'm using gamecanvas and I was thinking t
Variables and Include
Code: [Select]<?php
$header = $_COOKIE['mss']['header'];
$body = $_COOKIE['mss']['b
array_map() probably obvious mistake
The code below is part of a class to escape strings, but should also accept an array, using array_ma
Performance impact of cookies
Hi, I was just wondering what impact there would be in terms of performance if you where to set then
mod_rewrite.c on windows ??
why it's not working on windows while it's working on other hosts???
this is the code i got