hi djjjozsi. Thanks again for the script. I've been able to make a few changes to it and it works exactly how I would like it to!
<?
//set IE read from page only not read from cache
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
//set database
require_once('./includes/dbc_connect.php');
if($_POST['submitted']){
$errors=array();
if(empty($_POST['vegetables'])){
$errors[]="You need to select a vegetable";
} else {
$veg=$_POST['vegetables'];
}
if(empty($_POST['vegtype'])){
$errors[]="You need to select a vegetable type";
} else {
$vegtype=$_POST['vegetype'];
}
if(empty($errors)){
$query="INSERT INTO sowings (vegetable_fk, name_fk, user_fk) VALUES ('$veg', $vegtype, '7')";
$result=mysqli_query($dbc, $query) or die('there was a problem'. mysqli_error($dbc));
if($result){
echo "info added to db";
} else {
echo "there was a problem with the query: $query";
}
}
}
if ($data=='vegetables') { // first dropdown
echo "<select name='vegetables' onChange=\"dochange('vegtype', this.value)\">\n";
echo "<option value='0'>==== choose veg ====</option>\n";
$query="SELECT vegetable_pk, vegetable_type FROM vegetables";
$result=mysqli_query($dbc,$query);
while($row=mysqli_fetch_array($result)){
echo "<option value=\"$row[vegetable_pk]\" >$row[vegetable_type]</option> \n" ;
}
} else if ($data=='vegtype') { // second dropdown
echo "<select name='vegtype' >\n";
echo "<option value='0'>====choose veg type ====</option>\n";
$query="SELECT name_pk, name FROM names WHERE vegetable_pk= '$val'";
$result=mysqli_query($dbc,$query);
while($row=mysqli_fetch_array($result)){
echo "<option value=\"$row[name_pk]\" >$row[name]</option> \n" ;
}
}
echo "</select>\n";
echo '<input type="submit" name="submit" value="add details!" />
<input type="hidden" name="submitted" value="TRUE" />
</form>';
?>
Apart from getting two 'submit' buttons :p I am having a problem getting the selected values from the two dropboxes into a db. I know I'm using POST on my validation whereas the script seems to be using GET, but even changing this doesn't seem to help.
Can you (or anyone) offer any advice about how to get the values submitted to db??
Many thanks!