hey guys so im getting

Notice: Undefined index: spouse-salutations in D:\Xampp\htdocs\EMS2\add_contact_process.php on line 18

Notice: Undefined index: spouse-state in D:\Xampp\htdocs\EMS2\add_contact_process.php on line 24uoted Text Here

Notice: Undefined index: child-salutations in D:\Xampp\htdocs\EMS2\add_contact_process.php on line 30

Notice: Undefined index: child-state in D:\Xampp\htdocs\EMS2\add_contact_process.php on line 36

and its really frustrating because

$spousesalutations = mysql_real_escape_string($_POST['spouse-salutations']);
$spousestate = mysql_real_escape_string($_POST['spouse-state']);
$childsalutations = mysql_real_escape_string($_POST['child-salutations']);
$childstate = mysql_real_escape_string($_POST['child-state']);

I think it has something to do with how my page works. my page is a contact form page that has all the general : name email etc and two radio buttons one with label "Spouse ?" and the other "Children ?" and each has their yes or no option. when the yes option is clicked a form appears for each respectively(spouse form and child form) they are hidden in css and displayed using js. there is only one submit button at the bottom of the form. the php works like this:

require "connection.php";
$add = mysql_query("INSERT INTO contact VALUES('','".$salutations."','$fname','$lname','','','$houseno','$street','$postcode','$city','".$state."','$country','$tel','$off','$email')") or die(mysql_error());

if($spouse == "Yes")
{
require "connection.php";
$add1 = mysql_query("INSERT INTO contact VALUES('','".$salutations."','$fname','$lname','$spousesalutations $spousefname $spouselname','','$houseno','$street','$postcode','$city','".$state."','$country','$tel','$off','$email')") or die(mysql_error());
$add2 = mysql_query("INSERT INTO dependents VALUES('$spousefname','$spouselname','$spousehouseno','$spousestreet','$spousepostcode','$spousecity','".$spousestate."','$spousecountry','$spouseemail','$spousetel','$spouseoff','".$spousesalutations."','')") or die(mysql_error());

}                   
if($child == "Yes")
{
require "connection.php";
$add4 = mysql_query("INSERT INTO contact VALUES('','".$salutations."','$fname','$lname','','$childsalutations $childfname $childlname','$houseno','$street','$postcode','$city','".$state."','$country','$tel','$off','$email')") or die(mysql_error());
$add5 = mysql_query("INSERT INTO dependents VALUES('$childfname','$childlname','$childhouseno','$childstreet','$childpostcode','$childcity','".$childstate."','$childcountry','$childemail','$childtel','$childoff','".$childsalutations."','')") or die(mysql_error());
}

the above notice happens when i click "no" for both "spouse ?" and "children ?". when its no for "children ?" i get this:

Notice: Undefined index: child-salutations in D:\Xampp\htdocs\EMS2\add_contact_process.php on line 30

Notice: Undefined index: child-state in D:\Xampp\htdocs\EMS2\add_contact_process.php on line 36

if no for "spouse ?" i get the same notice but for spouse-salutations and spouse-city

my form just incase:

<form method="post" action="add_contact_process.php" class="add-contact-form">
            <fieldset>
                <legend>Add Contact</legend>
                <table class="primeC">
                    <tr>
                        <td>Salutation :</td> 
                        <td><select name="salutations"  >
                            <option value="" disabled selected>Choose</option>
                            <option value="Datin">Datin</option>
                            <option value="Datin Paduka">Datin Paduka</option>
                        </select></td>
                    </tr>
                        <tr><td colspan="2"><label class="label">*If a person has many salutations, choose the highest form of salutation</label></td></tr>
                        <tr><td>First Name :</td><td><input type="text" name="fname" id="fname"  /></td>
                                <td>Last Name :</td><td><input type="text" name="lname" id="lname"  /></td></tr>
                        <tr><td>House No.  :</td><td><input type="text" name="houseno" id="houseno"  /></td></td>
                        <tr><td>State :</td>
                        <td><select name="state" id="state" >
                            <option value="" disabled selected>Choose</option>
                            <option value="Johor">Johor</option>
                            <option value="Kedah">Kedah</option>
                        </select></td>
                        <tr><td>Spouse ? </td><td><input type="radio" name="spouse" id="spouse-yes" value="Yes" onclick="FillSpouse()"/>Yes<input type="radio" value="No" name="spouse" id="spouse-no"/>No</td></tr>
                        <tr><td colspan="2"><label class="label">If divorced/widowed,No</label></td></tr>
                    </table>
                    <div class="add-spouse-wrap" id="add-spouse-wrap">
                        <fieldset>
                        <legend>Add Spouse</legend>
                        <table>
                            <tr>
                                <td>Salutation :</td> 
                                <td><select name="spouse-salutations" id="spouse-salutations">
                                <option value="" disabled selected>Choose</option>
                                <option value="Datin">Datin</option>
                                <option value="Datuk">Datuk</option>
                                </select></td>
                            </tr>
                            <tr><td colspan="2"><label class="label">*If a person has many salutations, choose the highest form of salutation</label></td></tr>
                            <tr><td>First Name :</td><td><input type="text" name="spouse-fname" id="spouse-fname"  /></td>
                                    <td>Last Name :</td><td><input type="text" name="spouse-lname" id="spouse-lname"  /></td></tr>
                            <tr><td>House No.  :</td><td><input type="text" name="spouse-houseno" id="spouse-houseno"  /></td>
                            <tr><td>State :</td>
                            <td><select name="spouse-state" id="spouse-state">
                                <option value="" disabled selected>Choose</option>
                                <option value="Johor">Johor</option>
                                <option value="Kedah">Kedah</option>
                                <option value="Kelantan">Kelantan</option>
                            </select></td>
                        </table>
                        </fieldset>
                    </div>
                    Children ? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="child" id="child-yes" value="Yes"/>Yes<input type="radio" value="No" name="child" id="child-no"/>No
                    <div class="add-child-wrap" id="add-child-wrap">
                        <fieldset>
                        <legend>Add Children</legend>
                        <table>
                            <tr>
                                <td>Salutation :</td> 
                                <td><select name="child-salutations" id="child-salutations">
                                <option value="" disabled selected>Choose</option>
                                <option value="Datin">Datin</option>
                                <option value="Datin Paduka">Datin Paduka</option>
                                <option value="Dato Paduka">Dato Paduka</option>
                                <option value="Dato'">Dato'</option>
                                </select></td>
                            </tr>
                            <tr><td colspan="2"><label class="label">*If a person has many salutations, choose the highest form of salutation</label></td></tr>
                            <tr><td>First Name :</td><td><input type="text" name="child-fname" id="child-fname"  /></td>
                                    <td>Last Name :</td><td><input type="text" name="child-lname" id="child-lname"  /></td></tr>
                                    <tr><td>Where do they live ?</td><td colspan="3"><input type="radio" name="living" id="living-me"/>With Me<input type="radio" name="living" id="living-other"/>With Other Parent<input type="radio" name="living" id="living-own"/>Own</td></tr>
                            <tr><td>House No.  :</td><td><input type="text" name="child-houseno" id="child-houseno" class="child"  /></td>
                                    <td>City :</td><td><input type="text" name="child-city" id="child-city" class="child"  /></td></tr>
                            <tr><td>State :</td>
                            <td><select name="child-state" id="child-state" class="child">
                                <option value="" disabled selected>Choose</option>
                                <option value="Johor">Johor</option>
                                <option value="Kedah">Kedah</option>
                                <option value="Kelantan">Kelantan</option>
                            </select></td>
                        </table>
                        </fieldset>
                    </div>
                    <br>
                    <input type="submit" name="submitC" value="Submit"/ ><a href="contact_data.php"><input type="submit" name="cancel" value="Cancel" /><a/>
            </fieldset>
        </form>

if i input for all, no notice appears.
i really don't know what to do.
any help is appreciated.

Recommended Answers

All 2 Replies

Well you have writtent too much lines of code but this problem is due to defining of variable it only occurs as a notice with new php versions. You can simply turn notices off and it is not harmful or you can define any initial value to them before

$spousesalutations = mysql_real_escape_string($_POST['spouse-salutations']);
$spousestate = mysql_real_escape_string($_POST['spouse-state']);
$childsalutations = mysql_real_escape_string($_POST['child-salutations']);
$childstate = mysql_real_escape_string($_POST['child-state']);

But still better is to turn notices off by putting error_reporting(E_ERROR | E_WARNING | E_PARSE); at start of your php page where error is coming up

Thank you faisal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.