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
textfield unchanged
hi,
i want my form to know whether its textbox is unchange or not.
if($textbox == 'unchang
Adding post count
How would I make it so everytime someone clicks submit on my form, their row in the database for the
Java API in PHP?
I have an application that we use internally here at the office.
The software company provide
Select Rows as Columns..
is there a way to select COLUMN_NAME from user_tab_columns where table_name='TABLENAME';
and ha
array help
Does anyone know how to require 10 text fields for individual grades and output class average? (10 p
what business processes?
Hi,
A general question. What business processes (like OTC - Order to Cach, P2P, R2R etc)
Hit counter updating once per IP - IP HIT COUNTER
I have a hit counter, for the amount of views on a tutorial.
It'll do the query and then do..
newbie question
Hi out thereIm totaly new in this forum and to .net and vb so here is a totaly newbie question.I wan
Is it possible to stop reservation creation in PM Order?
Hi All,
Is it possible to stop reservation creation in PM Order?
Thanks in adv
update post issues
I am trying to create an update to a post function, while the update does occur, the page routing an