Viral
Joined: 10 Jun 2008 Posts: 8
|
Posted: Fri Jun 13, 2008 5:05 pm Post subject: HELP with GETTING information out of PHP to MYSQL |
|
|
Hello
I am trying to get a form together, still having some trouble
My current code is
| Code: |
<html>
<head>
<meta http-equiv="Content-Type" content="text/html"
charset="UTF-7">
<title>Getting Name and Phone Number</title>
</head>
<body>
<?php
#File used for connecting to the Mysql database
include("dbconnect.php");
#/home/virald/public_html/pear/PEAR
ini_set('include_path', "/home/virald/public_html/pear/PEAR:/usr/share/pear");
require_once "HTML/QuickForm.php";
#Using the tableless renderer
require_once "HTML/QuickForm/Renderer/Tableless.php";
require_once "HTML/QuickForm/Controller.php";
$form = new HTML_QuickForm('firsttest', 'post');
$renderer = new HTML_QuickForm_Renderer_Tableless('firsttest');
# Add all the necessary elements into the form
# Add rules for validation and required fields
$form->addelement ('header', 'header', 'Section I: Personal Information');
$form->addelement ('text','First_Name', 'First Name');
$form->addrule ('First_Name','Please enter your first name','required');
$form->addelement ('text','Middle_Name', 'Middle Name');
$form->addelement ('text','Last_Name', 'Last Name');
$form->addrule ('Last_Name','Please enter your last name','required');
// Create an element group of three textboxes for phone number
$form->addelement ('text','Birth_Date', 'Birth Date(mm/dd/yyyy)');
$form->addrule ('Birth_Date','Please Enter your Date of Birth','required');
$Gender = array(' ','Male','Female');
$form->addelement ('select','Gender', 'Gender: ', $Gender);
$form->addrule ('Gender','Please State your Gender','required');
$form->addelement ('text','SSN','SSN');
$form->addrule ('SSN','Please enter your Social Security Number(xxxxxxxxx)','required');
$form->addrule ('SSN','Please enter your Social Security Number(xxxxxxxxx)','numeric');
$form->addelement ('text','Stree_Address','Street Address');
$form->addelement ('text','City','City');
$form->addelement ('text','State','State');
$form->addelement ('text','Zip_Code','Zip Code');
$form->addelement ('text','Country','Country');
$form->addelement ('text','Home_Phone_Number', 'Home Phone Number');
$form->addrule ('Home_Phone_Number','Please enter a valid phone number (Ex. 1234567890)','numeric');
$form->addelement ('text','Cell_Phone_Number', 'Cell Phone Number');
$form->addrule ('Cell_Phone_Number','Please enter a valid phone number (Ex. 1234567890)','numeric');
$form->addelement ('text','Email','Email');
$form->addRule('Email','Please enter a valid email address (Ex. example@exam.com)', 'email');
$form->addRule('Email','Please enter a valid email address (Ex. example@exam.com)', 'required');
$US_Citizenship = array(' ','YES','NO');
$form->addelement ('select','US_Citizenship','US Citizenship: ',$US_Citizenship);
$form->addrule('US_Citizenship','Please State your Citizenship status','required');
$form->addelement ('header', 'header', 'Section II: Academic Record');
$form->addelement ('static', 'static', '', '<table><tr><td>
<td width=145>Name of Institution</td>
<td width=145>Location</td>
<td width=100>Attendance</br> From</td>
<td width=100>Attendance</br> To</td>
<td width=145>Degree Recieved</td>
<td width=100>Date</td>
<td width=145>Major</td>
</tr></table>
');
$School1[] = HTML_Quickform::createElement('text','School_1','School 1', array('style' => 'width: 145px;'));
$School1[] = HTML_Quickform::createElement('text','Location_1','Location 1', array('style' => 'width: 145px;'));
$School1[] = HTML_Quickform::createElement('text','Attendance_From_1','Attendance From 1', array('style' => 'width: 100px;'));
$School1[] = HTML_Quickform::createElement('text','Attendance_To_1','Attendance To 1', array('style' => 'width: 100px;'));
$School1[] = HTML_Quickform::createElement('text','Degree_1','Degree 1', array('style' => 'width: 145px;'));
$School1[] = HTML_Quickform::createElement('text','Degree_Date_1','Degree Date 1', array('style' => 'width: 100px;'));
$School1[] = HTML_Quickform::createElement('text','Major_1','Major 1', array('style' => 'width: 145px;'));
$form->addGroup ($School1,'school_1','1st');
$form->addelement ('submit', 'btnsubmit', 'Submit Entry');
# Trim all the unneccessary spaces on either side of the words
$form->applyfilter ('_ALL_','trim');
$form->removeattribute('name');
if ($form->validate())
{
# If the form validates then freeze the data
$form->freeze();
$form->process('SQLdatabase');
} else {
#Making a Tableless form output into the website
$form->display();
#$form->accept($renderer);
#echo $renderer->toHtml();
}
function SQLdatabase($data)
{
#Takes the informaiton entered above, and stores it into the variables below
$First_Name = $data["First_Name"];
$Middle_Name = $data["Middle_Name"];
$Last_Name = $data["Last_Name"];
$Birth_Date = $data["Birth_Date"];
$Gender = $data["Gender"];
$SSN = $data["SSN"];
$Street_Address = $data["Street_Address"];
$City = $data["City"];
$State = $data["State"];
$Zip_Code = $data["Zip_Code"];
$Country=$data["Country"];
$Home_Phone_Number = $data["Home_Phone_Number"];
$Cell_Phone_Number = $data["Cell_Phone_Number"];
$Email = $data["Email"];
$US_Citizenship = $data["US_Citizenship"];
$Date = time();
$School_1=$data["School1"][0];
|
As seen on the last line of code, I am trying to get the School_1 variable from the array $School1 which is part of the main $data array
I am having trouble with it, and seriously need some help, because all the only manuals dont really go in depth for multidimensional array
Anyhelp on how to do it????????????????
thanks a lot
Last edited by Viral on Mon Jun 16, 2008 1:08 pm; edited 1 time in total |
|