Hi, still a beginner here.
I got everything to work until I got too confident and added a couple radio buttons at the end and it all went to custard. I'm still trying to understand the logic but got totally lost here can anyone help.
Thanks
<?
if ($_POST) {
$msg = "";
foreach($_POST as $k => $v) {
$v = trim($v) ;
$$k =$v ;
if ($v=="") {
$msg = "Please fill in both fields Bec!";
}
}
if ($msg=="") {
$insert = "INSERT INTO Invoices
(company,invoice_number,amount,due_date,type,recurring)
VALUES ('$co','$inv','$amt','$dd','$tp','$rec')";
$link =
mysqli_connect('localhost','digitalp_rec','6Xl0T@ZB,{~f','digitalp_receivables');
if (!mysqli_query($link, $insert)) {
$msg = "Error inserting data";
} Else {
$msg = "Record successfully added";
$co = $inv = $amt = $dd = $tp = "" ;
}
mysqli_close($link);
}
echo "<div class=\"error\">$msg</div>";
} else {
$co = $inv = $amt = $due_date = $tp = $rec = "" ;
}
?>
<FORM METHOD="post" ACTION="<? echo
$_SERVER['PHP_SELF']?>">
<TABLE BORDER="1" CELLPADDING="5">
<TR>
<TH>Company</TH>
<TH>Invoice</TH>
<TH>Amount</TH>
<TH>Due</TH>
<TH>Type</TH>
<TH>Recurring</TH>
</TR>
<TR>
<TD><INPUT TYPE="text" NAME="co" VALUE="<?
echo $co ?>" /></TD>
<TD><INPUT TYPE= "text" NAME="inv" VALUE="<?
echo $inv ?>" /></TD>
<TD><INPUT TYPE= "text" NAME="amt" VALUE="<?
echo $amt ?>" /></TD>
<TD><INPUT TYPE= "text" NAME="dd" VALUE="<?
echo $dd ?>" /></TD>
<TD>
<input type="radio" name="type" value= 'tp1'<? echo $pers ?>; />Personal <br>
<input type="radio" name="type" value= 'tp2' <? echo $biz ?>; />Business <br>
</TD>
<?
$pers = 'unchecked';
$biz = 'unchecked';
if (isset($_POST['SUBMIT'])){
$selected_type = $_POST['type'];
if ($selected_type == 'tp1');{
$pers = 'checked';}
else if ($selected_type == 'tp2'); {
$biz = 'checked';
}
}
$tp = ($pers, $biz);
?>
<TD>
<input type="radio" name="type" value= 'rec'<? echo $rec ?>; />Recurring <br>
</TD>
</TR>
</TABLE>
<BR/>
<INPUT TYPE= "SUBMIT" VALUE= "Add Invoice"/>
<INPUT TYPE= "RESET" VALUE="Cancel"/>
</FORM>
</body>


