Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Quote your damn SQL inputs!, Paging Bobby Tables!

views
     
TSangch
post Nov 3 2014, 08:26 PM, updated 12y ago

On my way
****
Junior Member
636 posts

Joined: Jul 2006
Sigh, have enough of seeing bad code passing by here, and people replying and fixing the wrong (IMHO) things. Topic is closed, so didn't manage to post proper reply to the original post.

Read these:

http://en.wikipedia.org/wiki/SQL_injection

http://php.net/manual/en/mysqli-stmt.bind-param.php

http://php.net/manual/en/security.database.sql-injection.php

TL/DR:

Don't do this:
CODE
$mysqli->query("UPDATE table Foo set body= '".$_POST['body']."' where id= '".$_POST['id']."'");


Do this (well, a *better* version of this):
CODE
$stmt = mysqli_prepare($link, "UPDATE table Foo set body = ? where id= ?");
mysqli_stmt_bind_param($stmt, 'sd', $_POST['body'], $_POST['id']);
mysqli_stmt_execute($stmt);


This post has been edited by angch: Nov 3 2014, 08:28 PM

 

Change to:
| Lo-Fi Version
0.0151sec    0.66    6 queries    GZIP Disabled
Time is now: 21st December 2025 - 08:02 PM