need help fixing sql injection problem

Started on the old forum in August 2018 · view the original in the archive · old links redirect here

4 replies · 120 views · started 8 years ago · 1 min read

3 participants
rajveer Developer · 104 posts #1

hello everyone back with another problem

so i was using ezsql for parsing my database queries but found it is hack able pretty easily because it doesn't use prepared statements

here is demo code which give problems

$message =  isset($_POST['message']) ? $db->escape($_POST['message']) : "";

$db->query(insert message into database);
<form>
<textarea name="message"></textarea>
<button>submit</button>
</form>

so if is type in text area

<script>alert('hacked');</script>

it shows alert in browser also query is inserted in database

now it is fixable with pdo or mysqli prepared statements but i have some other questions

prepared statements are good for query update or delete stuff but when using count(*) its quite useless because have to count all rows after query every row from database

can anybody guide me what im doing wrong here ??

first i used that database class and i know real_escape_string is useless

second i want to use prepared statements but they are overloading for some stuff

what is good way to sanitize _POST data before inserting it into database ??

tupac Developer · 95 posts #2

This ought to do the trick $db->mysqli_real_escape_sting($_POST['message']). Suppose to work fine if you're using php version 7.

something else Fellow · 2,296 posts #4

mysql_real_escape_string ( ) and mysqli_real_escape_string ( ) etc... All require a default character set to work correctly. eg: UTF8 They also do not escape html characters like htmlspecialchars ( ) .

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close