View Single Post
Old 12-15-2012, 10:27 PM   PM User | #22
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,500
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by doubledee View Post
But technically that is true of anything passed through a Form, right?
Yes it is. Thats why you need to do your checks at your end.

Quote:
Originally Posted by doubledee View Post
Since I am just passing back a listing of all PM ID's to the same script so it knows which Messages need to be updated, and since the "pmID" is an Integer, then as long as I sanitize things by casting to an Integer, and using Prepared Statements - which is actually the only way I know how to do database stuff - then I assume that I will be okay from a security standpoint?!
Yes. Just remember in your SQL where clause don't just do where pmid='<the PMs ID>' also do a members user id too so that they can only delete their own messages - eg:

delete from messages where pmID='$pmID' and userID='$userID'

That would mean that the user can only delete their own messages / mark as read etc. It'll be slightly different using prepared statements but that should give you an idea of what I'm saying.

Also, not sure if you do this but you're best off constructing one long SQL statement EG:

delete from messages where (pmID='52' or pmID='51' or pmID='50') and userId='$userID'

That will let you do the entire thing in one SQL query rather than 30 or 40 seperate queries. To make it (very basic - you'll need to do your own checks)..
PHP Code:
foreach ($_POST['testArray'] as $Key => $Value)
   {
   
$Array[] = "pmID='$Value'";
   }

$IDs implode(' or '$Array); // "pmID='52' or pmID='51' or pmID='50'"

$SQL "delete from messages where ($IDs) and userId='$userID'" 
Again you'll need to change that for prepared statements but it should point you in the right direction.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.

Last edited by tangoforce; 12-15-2012 at 10:50 PM..
tangoforce is offline   Reply With Quote