Hello. I have a general understand of PHP, but not of its security. I recently began reading about SQL Injection and such. My code excerpt follows:
After the user submits the form, this script is called up.
if($formMethod == "post") { $semname = $_POST['semname']; }
else { $semname = $_GET['semname']; }
$semname = addslashes(rtrim(ltrim(strip_tags($semname))));
if (mysql_query("INSERT INTO $mySQLtable (semname) VALUES ('$semname')")) {
echo "Success"; }
I cut out all other information that had nothing to do with sanitizing for security (stuff such as checking for empty input and creating error messages). Also, each variable my form has goes through the same process as $semname does.
My problem is I don't know if this is enough. I have heard of using addslashes, mysql_escape_string, and 1 or 2 others I don't recall. I don't know if I should use them all, or just use some, or what. I've been reading up on this, but so far it hasn't quite clicked for me which to use. If you can help me, that would be very appriciated. Is what I have enough or do I need to add another one?
Also, is rtime(ltrim()) just repetition? I have seen some use trim, is that a combination of the two, or slightly different? I'll be reading the manual in the meantime, but Thank You to all who can clarify this.