Can anyone please help here I have a form that i wish the user to select a product from a drop down box and then query it in a mysql then i would like to the user to input a number in the next field the press the submit button, then the form should do some simple maths and display it in the next field. now 3 things my code does not do 1/ the math and display it 2/the user input and the product i would like to remain after the form has been submitted 3/ also can anyone give some idea of how to get the form to calculate without a submitt button. here is my code:
<form action="scdc_selfcompletion.php" method="post">
<select name="bap10">
<option selected="selected">Select One</option>
<option value="Energy Efficient Cooking">Energy Efficient Cooking</option>
<option value="Re-Usable Bags">Re-Usable Bags</option>
<option value="Keep Fridge/Freezer Ice Free">Keep Fridge/Freezer Ice Free</option>
<option value="No Stand By">No Stand By</option>
<option value="Use Energy Meter">Use Energy Meter</option>
<option value="Use Radio Other Than TV">Use Radio Other Than TV</option>
<option value="Recycling">Recycling</option>
<option value="Stop Junk Mail">Stop Junk Mail</option>
</select>
</td>
<td width="19%">
<input name="pledging" type="text" id="pledging" maxlength="5" />
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan = '3'>Total Savings and Expenditure</td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="Submit" name="select" value="select">
</form>
<?php
$select = $_POST['select'];
// if something has been chosen
if (!empty($select)) {
// get the chosen value
$bap1 = $_POST['bap1'];
$bappledging1 = $_POST['pledging1'];
$bap2 = $_POST['bap1'];
$bappledging2 = $_POST['pledging1'];
$bap3 = $_POST['bap1'];
$bappledging3 = $_POST['pledging1'];
$bap4 = $_POST['bap1'];
$bappledging4 = $_POST['pledging1'];
$bap5 = $_POST['bap1'];
$bappledging5 = $_POST['pledging1'];
$bap6 = $_POST['bap1'];
$bappledging6 = $_POST['pledging1'];
$bap7 = $_POST['bap1'];
$bappledging7 = $_POST['pledging1'];
$bap8 = $_POST['bap1'];
$bappledging8 = $_POST['pledging1'];
$bap9 = $_POST['bap1'];
$bappledging9 = $_POST['pledging1'];
$bap10 = $_POST['bap1'];
$bappledging10 = $_POST['pledging1'];
// select the type from the database
// database connection details (change to whatever you need)
$HOST = 'localhost';
$DATABASE = '';
$USER = '';
$PASSWORD = '';
}
// connect to database
if(!$conn=mysql_connect('','','')) {
echo("<li>Can't connect to $HOST as $USER");
echo("<li>mysql Error: ".mysql_error());
die;
}
// select database
if (!mysql_select_db($DATABASE,$conn)) {
echo("<li>We were unable to select database $DATABASE");
die;
}
// if everything successful create query
// this selects all rows where the type is the one you chose in the dropdown
// * means that it will select all columns, ie name and type as i said above
$bap1_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap1'";
$bap2_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap2'";
$bap3_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap3'";
$bap4_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap4'";
$bap5_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap5'";
$bap6_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap6'";
$bap7_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap7'";
$bap8_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap8'";
$bap9_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap9'";
$bap10_sql_query = "SELECT * FROM Behaviour WHERE Product LIKE '$bap10'";
//product 1 sum
$result = mysql_query($bap1_sql_query,$conn) or die('Invalid query: ' . mysql_error());
$details = mysql_fetch_array($result);
$bap1units = $bappledging1 = $_POST['pledging1'];
$bap1mes = $details['mesurements'];
$bapanswer1 = $bap1mes*$bap1units;
?>
i have only one row for lenth of thread perposes but all the php is there thanks in advance anyone