I'm pretty new to PHP and am trying to learn more in the area of making my forms secure so that my DB are more difficult to mess up via SQL injection and such. The current web programmer/php guy at our company quit with short notice so my boss has placed me in the php programmers position temporarily with only a single week of training under the previous programmer (I do lots of html and css work, but no php prior), until they can find a real replacement.
Anyways, I read that using mysql_query()
is a depreciated function and it should be avoided because that method is vulnerable. I see that my two options are to now use PDO or MySQLi. Being new to PHP, I'm having trouble figuring out what exactly I need to do to convert the code I am currently using (which sends info from a request a quote form on the site and stores it in the database incase of email troubles) into a more secure method of sending data to the database via PDO or MySQLi.
The current line of code I'm using is:
$query = mysql_query("insert into request_for_quote(rfq_company_name, rfq_name, rfq_email, rfq_phone, rfq_end_user) values ('$rfqCompanyName', '$rfqName', '$rfqEmail', '$rfqPhone', '$rfqEndUser')");
Which is mostly powered by $_POST variables.
$rfqName = mysql_real_escape_string($_POST['rfq_name']);
$rfqEmail = filter_var($_POST['rfq_email'], FILTER_VALIDATE_EMAIL);
$rfqPhone = mysql_real_escape_string($_POST['rfq_phone']);
$rfqCompanyName = mysql_real_escape_string($_POST['rfq_company_name']);
$rfqEndUser = mysql_real_escape_string($_POST['rfq_end_user']);
Now, my code does what I need it to, it just seems like it is extremely vulnerable to database attacks, and I want to learn how to fix that, but it seems all examples I'm finding online aren't using the setup of "insert X
,Y
, and Z
variables into the table Columns as values A
, B
, C
".
Are there any simple changes I do to make my database submission query more secure?