I have two checkboxes
<form action="" method="post" enctype="multipart/form-data">
<input type="checkbox" name="file_type" value="1"> Filer<br />
<input type="checkbox" name="file_type" value="1"> Statistik
</form>
and i have two rows on my database table das_custermer_files.
row 1 = files row 2 = statistic
how can i check one of them an put the value into my rows.
i have try with this code
if($_POST['file_type'] == 1){
mysql_query("INSERT INTO das_custermer_files (url, das_file_categories_id, das_custermers_id, name)
VALUE('$fileurl', 1, $user_custermers_id, '$name')"
) or die(mysql_error());
}
elseif($_POST['statistik_type'] == 1){
mysql_query("INSERT INTO das_custermer_files (url, das_custermer_upload_id, das_custermers_id, name)
VALUE('$fileurl', 1, $user_custermers_id, '$name')"
) or die(mysql_error());
}
else{
echo "no choices";
}
But if i only check one of them it stil put value 1 in both of my rows.
Hope people understand. If not. ask
i have done it.
the finel code:
html
<form action="" method="post" enctype="multipart/form-data">
<input type="radio" name="file_type" value="1"> Filer<br />
<input type="radio" name="file_type" value="2"> Statistik
</form>
PHP
$field = false;
switch($_POST['file_type'])
{
case 1:
$field = 'das_file_categories_id';
break;
case 2:
$field = 'das_custermer_upload_id';
break;
default:
$field = false;
}
if($field)
{
mysql_query("INSERT INTO das_custermer_files (url, $field, das_custermers_id, name)
VALUE('$fileurl', 1, $user_custermers_id, '$name')"
) or die(mysql_error());
}