Hi, I am trying to add data to a mysql db from an html form using text boxes, a textarea and radio buttons.
I have already got another page working using just text boxes, but when I add the radio buttons, it doesnt submit the data and returns my exception error 'Error, insert query failed' (php code that doesnt work is preceded by // - value txtssl)
Also, I want to combine values from two sets of drop down boxes to make two decimal fields of (2,1) and (2,2) respectively. (code only returns 9.9 or 9.0 no matter what value I select from the drop down box, also preceded by // - values txtHeight and txtAge
I cant find any exampes on the web specifically for my issues, so if anyone can help it would be appreciated.
Code im using is:
PHP code:
<?php
if(isset($_POST['btnRegister']) || $errmsg != '')
{
include 'config.php';
include 'opendb.php';
$txtHorseName = $_POST['txtHorseName'];
//$txtHeight = $_POST['HeightH']+$_POST['HeightI'];
$txtBreed = $_POST['Breed'];
$txtPrice = $_POST['txtPrice'];
$txtColour = $_POST['Colour'];
//$txtAge = $_POST['txtAddressLine1']+$_POST['txtAddressLine1'];
$txtSex = $_POST['Sex'];
$txtDescription = $_POST['txtAreaDesc'];
$txtlocation = $_POST['Location'];
//$txtSSL = $_POST['SSL'];
$query = "INSERT INTO horse (name, height, breed, price, colour, age, sex, description, location, createDate, sSl) VALUES ('$txtHorseName', '$txtHeight', '$txtBreed', '$txtPrice', '$txtColour', '$txtAge', '$txtSex', '$txtDescription', '$txtLocation', NOW(), $txtSSL)";
mysql_query($query) or die('Error, insert query failed');
$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');
include 'closedb.php';
echo "<p class ='text2'>Your user details have been added.</p>";
}
else
{
?>
Form HTML code:
<form method="post" name="frmRegister" id="frmRegister">
<table width="300" align="left" cellspacing = "7">
<tr>
<td width="150"><p class="text3">Horse Name</p></td>
<td><input name="txtHorseName" type="text" id="txtHorseName"></td>
</tr>
<tr>
<td width="150"><p class="text3">Height:</p></td>
</tr>
<tr>
<td width="150"><p class="text3">Hands*</p></td>
<td><select name="HeightH">
<option value=""></option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</td>
</tr>
<tr>
<td width="150"><p class="text3">Inches*</p></td>
<td><select name="HeightI">
<option value=""></option>
<option value=".0">0</option>
<option value=".1">1</option>
</select>
</td>
</tr>
<tr>
<td width="150"><p class="text3">Breed*</p></td>
<td><select name="Breed">
<option value=""></option>
<option value="Akhal Teke">Akhal Teke</option>
<option value="Andalusian">Andalusian</option>
<option value="Anglo Arab">Anglo Arab</option>
<option value="Appaloosa">Appaloosa</option>
<option value="Arab">Arab</option>
<option value="Belgian Warmblood">Belgian Warmblood</option>
</select>
</td>
</tr>
<tr>
<td width="150"><p class="text3">Price* £</p></td>
<td><input name="txtPrice" type="text" id="txtPrice"></td>
</tr>
<tr>
<td width="150"><p class="text3">Colour*</p></td>
<td><select name="Colour">
<option value=""></option>
<option value="Appaloosa">Appaloosa</option>
<option value="Bay">Bay</option>
<option value="Bay Roan">Bay Roan</option>
<option value="Black">Black</option>
</select>
</td>
</tr>
<tr>
<td width="150"><p class="text3">Age:</p></td>
</tr>
<tr>
<td width="150"><p class="text3">Years*</p></td>
<td><select name="AgeY">
<option value=""></option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
</tr>
<tr>
<td width="150"><p class="text3">Months*</p></td>
<td><select name="AgeM">
<option value=""></option>
<option value="0.0">0</option>
<option value="0.1">1</option>
<option value="0.2">2</option>
</select>
</td>
</tr>
<tr>
<td width="150"><p class="text3">Sex*</p></td>
<td><select name="Sex">
<option value=""></option>
<option value="Mare">Mare</option>
<option value="Gelding">Gelding</option>
<option value="Stallion">Stallion</option>
<option value="Filly">Filly</option>
<option value="Colt">Colt</option>
</select>
</td>
</tr>
<tr>
<td width="150"><p class="text3">Description</p></td>
<td><textarea cols="20" rows="6" name="txtAreaDesc" wrap="HARD"></textarea></td>
</tr>
<tr>
<td width="150"><p class="text3">Location</p></td>
<td><select name="Location">
<option value=""></option>
<option value="Greater London">Greater London</option>
<option value="South West England">South West England</option>
<option value="South East England">South East England</option>
<option value="The Midlands">The Midlands</option>
<option value="North East England">North East England</option>
<option value="North West England">North West England</option>
<option value="East Anglia">East Anglia</option>
<option value="Scotland">Scotland</option>
<option value="Northern Ireland">Northern Ireland</option>
<option value="Wales">Wales</option>
</select>
</td>
</tr>
<tr>
<td width="150"><p class="text3">This horse is for*:</p></td>
</tr>
<tr>
<td width="150">
<p class="text3">Sale</p><input type="radio" name="SSL" value="Sale">
</td>
</tr>
<tr>
<td width="150">
<p class="text3">Share</p><input type="radio" name="SSL" value="Share">
</td>
</tr>
<tr>
<td width="150">
<p class="text3">Loan</p><input type="radio" name="SSL" value="Loan">
</td>
</tr>
<tr>
<td width="150"> </td>
<td><input type="submit" id="btnRegister" name="btnRegister" value="Register"></td>
</tr>
</table>
</form>
<p class ="text2">Fields with a * are mandatory</p>
<?php
}
?>