How to Parameterise SQL Query in PHP
The below code is working based on the WHERE clause.
Now, rather than specify the Gender, State, etc. I want to enter Female and the State name into textboxes, and then query the database based on those values.
How do I parameterise the below code?
function select()
{
echo "The select function is called.";
$connect = mysql_connect("localhost","root","cft108");
if (!$connect) {
die("MySQL could not connect!");
}
$DB = mysql_select_db('g05');
if(!$DB) {
die("MySQL could not select Database!");
}
$ward_list = mysql_query("SELECT DISTINCT (((Deaths / Population) * 100) * 1000) * 1.12 as 'myResult', Population FROM Mortality WHERE Gender = 'Female' AND State = 'Alabama' AND Age_Group = '1-4 years'");
while ($row = mysql_fetch_array($ward_list)){
echo '<br>';
echo 'Premium:' . '<option value="'. $row['value'] .'">'. $row['myResult'] .'</option>';
}
}
Thanks a lot.
Subject
Written By
Posted
How to Parameterise SQL Query in PHP
August 22, 2017 09:43AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.