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
pagination - need help on passing of search query.
Hi, i have been trying for days but couldn't get this sorted out. Would like some professional help
rdns with php
I am trying to build a script that will show all of the different domains that are hosted on the sam
Greek characters in php
Hi,
I'm making a script and I m using for first time greek characters.
I started to write
Count number of records in all the tables with a querry URGENT PLEASE...
I downloaded ORACLE 9I DATA DUMP into my comp. There are number of tables. I need to find out the
EU VAT Package 2010
Does any one know whether SAP will be developing new reporting functionality due the new VAT rules t
cstdatomic (c++0x std::atomic) / g++ 4.4
Hello,
I'm trying to use cstdatomic (std::atomic in the upcoming c++0x standard) in g++
Format timestamp from mysql
When I tried this:
Code: date("m/d/Y H:i A", $row['timestamp'])
I got 12/31/1969 18:
Retrieving the 25 most recently added entries from all tables in a MySQL databas
Hello,
The code below works great. It creates a table that shows the 25 most recently added t
admin with my register system?
Hey i wana make it so i can make a admin level on my register system , I'm kinda new to php to im no
Concatenate two strings ???
I have string one $string1 and another $string2.
How to concatenate (add) both of them $str