hey guys so im trying to insert data from my contact form into database depending on radio button.
as u can c i have 2 radio button both under "spouse ?" and another under "child ?" now when user clicks on "yes" another form pops up for each title respectively(form for spouse and form for child). my issue is inserting the data into database, for the primary form it has its own database table and for spouse and child its own database table. so say the user only clicks on yes for spouse so there is only data for spouse and the primary form or if only they click on yes for child instead of spouse so theres only data for child and the primary form or they have data for all three forms or maybe just data for the primary form. how can i code the if else statement in php for those conditions?
this is a very very simplified version.
<form method="post" action="add_contact.php">
name : <input type="text" name="name">
house address : <input type="text" name="home">
spouse ? <input type="radio" name="spouse" value="Yes">Yes<input type="radio" name="spouse">No
child ? <input type="radio" name="child" value="Yes">Yes<input type="radio" name="child">No
<div>
name : <input type="text" name="spousename">
house address : <input type="text" name="spousehome">
</div>
<div>
name : <input type="text" name="childname">
house address : <input type="text" name="childhome">
</div>
</form>
this is what i tried, using AND
and &&
(i read somewhere theres a small difference between the two) but then again i dont think the way i coded is the right or best way.
<?php
$name = mysql_real_escape_string($_POST['name']);
$house = mysql_real_escape_string($_POST['house']);
$spouse = mysql_real_escape_string($_POST['spouse']);
$child = mysql_real_escape_string($_POST['child']);
$childname = mysql_real_escape_string($_POST['childname']);
$childhouse = mysql_real_escape_string($_POST['childhouse']);
$spousename = mysql_real_escape_string($_POST['spousename']);
$spousehouse =mysql_real_escape_string($_POST['spousehouse']);
if($spouse AND $child == "Yes")
{
require "connection.php";
$add = mysql_query("INSERT INTO contacts VALUES('$name','$house')");
$add2 = mysql_query("INSERT INTO dependents VALUES('$spousename','$spousehouse')");
$add3 = mysql_query("INSERT INTO dependentd VALUES('childname','childhouse')");
}
if(($spouse == "Yes") AND ($child == "No"))
{
$addC = mysql_query("INSERT INTO contacts VALUES('$name','$house')");
$addc = mysql_query("INSERT INTO dependents VALUES('$spousename','$spousehouse')");
}
and so on
?>
any help/ideas/suggestions is much appreciated.