i have been searching a solution for days and i have tried ajax/jquery methods posted online but it just wouldnt work. I have a drop down list which gets its value from the database. On selecting any value apart from "Select", i want to display a value which is called upon by a php file:
here's my code for the form:
<tr>
<fieldset id="Date">
<td class="select"><label><span class="text_9">Date:</span></label></td>
<td><select name="date" id="date">
<option value="">Select</option>
<?php include_once "selectdate.php"?></td>
</select>
</tr>
</fieldset>
</table>
and here's the php to run on selection of the drop down (called retrieve.php)
<?php
include_once "connect.php";
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$form=$_GET;
$trade=$form['tradetype'];
$metal=$form['metal'];
$amount=$form['amount'];
$date=$form['date'];
$stmt = $conn->query("SELECT Discount FROM Contracts WHERE Trade='$trade' AND Metal='$metal' AND Amount='$amount' AND ExpiryDate='$date'");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo ($row['Discount']);
}
?>
As you can see, the php to be run uses the value from multiple form elements...
I am very new to jquery/ajax... any help is appreciated as i want the result to be displayed on the same page as the form is. Thank you!
$form? You are open to SQL injections with this code. Use parameterized prepared statements. php.net/manual/en/pdo.prepared-statements.phptrandfieldsetopen and close tags do not match. Just FYI.