Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2005-02-24, 01:04 PM   #1
Barron
You tried your best and you failed miserably. The lesson is 'never try'
 
Join Date: Oct 2004
Posts: 166
He wasnt trying to log anyone in. I changed the code to fetch the info for the user.

Ramster, there isnt any error checking, you must put that in. Malformed input from a webpage can really screw things up : )
Barron is offline   Reply With Quote
Old 2005-02-24, 01:50 PM   #2
codemonkey
WHO IS FONZY!?! Don't they teach you anything at school?
 
Join Date: Oct 2004
Posts: 44
Send a message via ICQ to codemonkey Send a message via Yahoo to codemonkey
Yup anytime you have a database query that can be changed by the user - when using $_GET $_POST $_REQUEST $_COOKIE etc always check the input..

Use the mysql_real_escape_string function in php to clean the input before you put it into the database. This will help to prevent SQL injection attacks by quoting out special characters.

so when inserting selecting etc always do this..

PHP Code:
$query "SELECT * FROM table WHERE user='"mysql_real_escape_string($user) ."'"
i got fed up of typing that so i made a little function to make less typing - what can i say i'm a lazy coder

PHP Code:
//Escape the string for the database and add single quotes

function quote($value){
    
$value "'" .mysql_real_escape_string($value) ."'";
    return 
$value

So your code is now...

PHP Code:
$query "SELECT * FROM table WHERE user="quote($user); 
Hope this helps someone out
__________________
BBW modelling competitions
codemonkey is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:01 AM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc