Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem in inserting multiple regisration forms

    Hi guys. im creating a website that has a multiple registration forms but the thing is, it always says undefined index. here is my code btw.. im new to php so i cant figure out whats wrong with my problem.

    for the first form
    Code:
    <?php
    
    session_start();
    ?>
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="style/style.css" rel="stylesheet" type="text/css" />
    </head>
    
    <body>
    <div id="regdiv2">
      <h3>Medical Record</h3>
      <form id="form1" name="form1" method="post" action = "reg2.php">
        <p>First Name
          <input type="text" name="fname"/>
          Last Name
          <input type="text" name="Lastname"/>
          MI
          <input type="text" name="mname"/>
        </p>
        <p>Date Of Birth
          <input type="text" name="DoB"/>
    Age
    <input type="text" name="age"size = "5"/>
    Civil Status
    <input type="text" name="CivilStatus"/>
        </p>
        <p>Baguio Address
          <input type="text" name="BagAddress"size = "80"/>
        </p>
        <p>&nbsp;</p>
        <p>Designation: Student
          <input type="checkbox" name="Designation"/>
    Faculty
    <input type="checkbox" name="Designation"/>
    Ants
    <input type="checkbox" name="Designation"/>
        Dependent
        <input type="checkbox" name="Designation"/>
        </p>
        <p>Department
          <input type="text" name="department" size = "50"/>
        </p>
        <p>If Student: Course
          <input type="text" name="course"/>
        Year:
        <input type="text" name="year"/>
        </p>
        <p>Contact Persion in case of emergency:</p>
        <p>A. Name
          <input type="text" name="Ename"/> 
          B. 
          <input type="text" name="emName"/>
    </p>
        <p>Adress
          <input type="text" name="eaddress"/> 
          <input type="text" name="emAddress"/>
        </p>
        <p>Tell No.
          <input type="text" name="eTellNo"/>
          <input type="text" name="emTellNo"/>
        </p>
        <p>Relationship
          <input type="text" name="eRelationship"  />
          <input type="text" name="emRelationship" />
        </p>
        <p>
          <input type="submit" name="next" value="      Next      "/>
    </p>
      </form>
      </div>
    <div id="regdiv1">
    <img src="image/register.jpg"/></div>
    </body>
    </html>
    here is the second
    Code:
    <?php
    
    session_start();
    $_SESSION['fname'];
    
    ?>
    
    
    
    <html>
    <head>
    <title></title>
    <link href="style/style.css" rel="stylesheet" type="text/css" />
    </style>
    </head>
    
    <body>
    <div id="regdiv2">
      <h3>Medical Record</h3>
      <p>Medical History:</p>
      <form id="form1" name="form1" method="post" action="insertdata.php">
      <p>A. Allergy to drugs: 
        <input type="radio"  name="Allergy" value="Yes" />
        Yes
        <input type="radio" name="Allergy" value="No" />
        No  </p>
      <p>If yes, state the name(s) of drug(s) you are allergic to:
        <input type="text" name="allergy1" />
      </p>
      <p>B. Asthma 
        <input type="radio" name="Asthma" value="Yes" />
    Yes
    <input type="radio" name="Asthma" value="No" />
    No </p>
      <p>C. Seizures/Comvulsion/Epilepsy 
        <input type="radio" name="seizure" value="Yes" />
    Yes
    <input type="radio" name="seizure" value="No" />
    No </p>
      <p>D. Heastdisease 
        <input type="radio" name="Heast" value="Yes" />
    Yes
    <input type="radio" name="Heast" value="No" />
    No </p>
      <p>E. Diabetese 
        <input type="radio" name="Diabetese" value="Yes" />
    Yes
    <input type="radio" name="Diabetese" value="No" />
    No </p>
      <p>Vital Sign: BP
        <input type="text" name="BP" size = "5" />
        MMHG Temp
        <input type="text" name="temp" size = "5" />
         Height
         <input type="text" name="height" size = "5"/>
         ft.
       weight
      <input type="text" name="weight" size = "5"/>
      lbs</p>
      <p>Blood Type: 
        <input type="radio" name="Bloodtype" value="bloodtypeA" />
        A 
        <input type="radio" name="BloodType" value="bloodTypeB" />
        B 
        <input type="radio" name="BloodType" value="bloodTypeAB" />
        AB 
        <input type="radio" name="BloodType" value="bloodTypeO" />
        O</p>
      <p>ID Number
        <input type="text" name="IdNum" >
      </p>
      <p>
        <input type="submit" name="RegSubmit" value="Submit" />
      </p>
      </form>
    </div>
    <div id="regdiv1"><img src="image/register.jpg" width="900" height="1000" /></div>
    </body>
    </html>
    and finally
    Code:
    <?php
    mysql_connect("localhost","root","");
    
    mysql_select_db("softeng");
    
    ?>
    <?php
    session_start();
            $_SESSION['fname'] = $_POST['lname'];
    	$_SESSION['lname'] = $_POST['lname'];
    	$_SESSION['mname'] = $_POST['$mname'];
    	$_SESSION['DoB'] = $_POST['DoB'];
    	$_SESSION['age'] = $_POST['age'];
    	$_SESSION['CivilStatus'] =$_POST['CivilStatus'];
    	$_SESSION['BagAddress'] = $_POST['BagAddress'];
    	$_SESSION['Designation'] =$_POST['Designation'];
    	$_SESSION['department'] = $_POST['department'];
    	$_SESSION['course'] = $_POST['course'];
    	$_SESSION['year'] = $_POST['year'];
    	$_SESSION['Ename'] = $_POST['Ename'];
    	$_SESSION['eaddress'] = $_POST['eaddress'];
    	$_SESSION['emAddress'] =$_POST['emAddress'];
    	$_SESSION['eTellNo'] =$_POST['eTellNo'];
    	$_SESSION['emTellNo'] = $_POST['emTellNo'];
    	$_SESSION['eRelationship'] = $_POST['eRelationship'];
    	$_SESSION['emRelationship'] = $_POST['emRelationship'];
    	$_SESSION['Allergy'] = $_POST['Allergy'];
    	$_SESSION['Allergy1'] = 'Allergy1';
    	$_SESSION['Asthma'] = $_POST['Asthma'];
    	$_SESSION['seizure'] = $_POST['seizure'];
    	$_SESSION['Heast'] = $_POST['Heast'];
    	$_SESSION['Diabetese'] = $_POST['Diabetese'];
    	$_SESSION['BP'] = $_POST['BP'];
    	$_SESSION['temp'] = $_POST['temp'];
    	$_SESSION['height'] = $_POST['height'];
    	$_SESSION['weight'] = $_POST['weight'];
    	$_SESSION['Bloodtype'] = $_POST['Bloodtype'];
    	$_SESSION['IdNum'] = $_POST['IdNum'];
    
    ?>
    <?php
    //let's start our session, so we have access to stored data
    //let's create the query
      if(isset($_REQUEST['submit']))
      {
    $query = "insert into stud (fname, lname, mname, DoB, age, CivilStatus, BagAddress, Designation, department, course, year, Ename, eaddress, emAddress, eTellNo, emTellNo, eRelationship, emRelationship, Allergy, Allergy1, Asthma, seizure, Heast, Diabetese, BP, temp, height, weight, Bloodtype, Idnum ) values ('$fname', '$lname', '$mname', '$DoB', '$age', '$CivilStatus', '$BagAddress', '$Designation', '$department', '$course', '$year', '$Ename', '$eaddress',   '$emAddress', '$eTellNo', '$emTellNo', '$eRelationship', '$emRelationship', '$Allergy', '$Allergy1', '$Asthma', '$seizure', '$Heast', '$Diabetese', '$BP', '$temp', '$height', '$weight', '$Bloodtype', '$IdNum')";
    mysql_query($query);
    }
    ?>
    any help would be appreciated.

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    Why are you using sessions for all of that.. your query won't work. In your insert query you're referencing variables that don't even exist. Also, you need to encase your $_POST information in the mysql_escape_string(); function.

    Also, since your form is using the POST method, change your if(isset($_REQUEST['submit'])) to if(isset($_POST['submit']))

  • #3
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi. Thanks for the reply

    Quote Originally Posted by Adee View Post
    Why are you using sessions for all of that..
    oh im sorry.. i thought that if i use that, i can get the variables that i have inputted on the reg1.php
    so how can i get the variables that i have inputted on the first page or in second?


    your query won't work. In your insert query you're referencing variables that don't even exist.
    uhmm.. i dont quite get it..

    im so sorry, im really new to this.

  • #4
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    PHP Code:
    $query "insert into stud (fname, lname, mname, DoB, age, CivilStatus, BagAddress, Designation, department, course, year, Ename, eaddress, emAddress, eTellNo, emTellNo, eRelationship, emRelationship, Allergy, Allergy1, Asthma, seizure, Heast, Diabetese, BP, temp, height, weight, Bloodtype, Idnum ) values ('$fname', '$lname', '$mname', '$DoB', '$age', '$CivilStatus', '$BagAddress', '$Designation', '$department', '$course', '$year', '$Ename', '$eaddress',   '$emAddress', '$eTellNo', '$emTellNo', '$eRelationship', '$emRelationship', '$Allergy', '$Allergy1', '$Asthma', '$seizure', '$Heast', '$Diabetese', '$BP', '$temp', '$height', '$weight', '$Bloodtype', '$IdNum')"
    All of the words with $ in front of them are variables and you haven't declared them anywhere.

    To get access to the information on a second page, you need to declare your variables like this:

    PHP Code:
    $fname mysql_escape_string($_POST['fname']);
    $lname mysql_escape_string($_POST['lname']);
    $mname mysql_escape_string($_POST['mname']); 
    Then you can use them in your insert query.

  • #5
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the help, but it seems that, it only clears the radio button not the text field. it says undefined index but for the ID number, it says undefined variable.

  • #6
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    paste the error message here bro. and we need to know your table structure to analys this issue.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •