$data[1];

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

$data[1];

Post by melindaSA »

Hi,

Help Needed!! What does the [0] and [1] do/mean in the following piece of code?

Code: Select all

$data = explode('|', $HTTP_POST_VARS['position_apply']);
  $title = $data[0];
  $depID = $data[1];
Thank you,


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

they are elements of an array..

for example, add this to your code

print_r($data);

It will give the layout of your array as it is..
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

Thank you!

I thought maybe this was causing whitespace to be added to the database. What would cause whitespace to be added to the dep_id in the database in the following code:

Code: Select all

$data = explode('|', $HTTP_POST_VARS['position_apply']);
  $title = $data[0];
  $depID = $data[1];
  
  // create short variable names
  $first_name = $HTTP_POST_VARS['first_name'];
  $middle_name = $HTTP_POST_VARS['middle_name'];
  $last_name = $HTTP_POST_VARS['last_name'];
  $address = $HTTP_POST_VARS['address'];
  $address2 = $HTTP_POST_VARS['address2'];
  $city = $HTTP_POST_VARS['city'];
  $state = $HTTP_POST_VARS['state'];
  $zip = $HTTP_POST_VARS['zip'];
  $h_telephone = $HTTP_POST_VARS['h_telephone'];
  $b_telephone = $HTTP_POST_VARS['b_telephone'];
  $ssn = $HTTP_POST_VARS['ssn'];
  $contact_work = $HTTP_POST_VARS['contact_work'];
  $date_avail = $HTTP_POST_VARS['date_avail'];
  $full_time = $HTTP_POST_VARS['full_time'];
  $part_time = $HTTP_POST_VARS['part_time'];
  $prn = $HTTP_POST_VARS['prn'];
  $monday_from = $HTTP_POST_VARS['monday_from'];
  $monday_to = $HTTP_POST_VARS['monday_to'];
  $tuesday_from = $HTTP_POST_VARS['tuesday_from'];
  $tuesday_to = $HTTP_POST_VARS['tuesday_to'];
  $wednesday_from = $HTTP_POST_VARS['wednesday_from'];
  $wednesday_to = $HTTP_POST_VARS['wednesday_to'];
  $thursday_from = $HTTP_POST_VARS['thursday_from'];
  $thursday_to = $HTTP_POST_VARS['thursday_to'];
  $friday_from = $HTTP_POST_VARS['friday_from'];
  $friday_to = $HTTP_POST_VARS['friday_to'];
  $saturday_from = $HTTP_POST_VARS['saturday_from'];
  $saturday_to = $HTTP_POST_VARS['saturday_to'];
  $sunday_from = $HTTP_POST_VARS['sunday_from'];
  $sunday_to = $HTTP_POST_VARS['sunday_to'];
  $shift = $HTTP_POST_VARS['shift'];
  $employed_bjrh = $HTTP_POST_VARS['employed_bjrh'];
  $application_bjrh = $HTTP_POST_VARS['application_bjrh'];
  $what_name = $HTTP_POST_VARS['what_name'];
  $date_birth = $HTTP_POST_VARS['date_birth'];
  $eligibility = $HTTP_POST_VARS['eligibility'];
  $referred = $HTTP_POST_VARS['referred'];
  $emergency_name = $HTTP_POST_VARS['emergency_name'];
  $emergency_phone = $HTTP_POST_VARS['emergency_phone'];
  $m_branch = $HTTP_POST_VARS['m_branch'];
  $m_special = $HTTP_POST_VARS['m_special'];
  $rank = $HTTP_POST_VARS['rank'];
  $us_citizen = $HTTP_POST_VARS['us_citizen'];
  $legal_right = $HTTP_POST_VARS['legal_right'];
  $hs_name = $HTTP_POST_VARS['hs_name'];
  $hs_address = $HTTP_POST_VARS['hs_address'];
  $hs_city = $HTTP_POST_VARS['hs_city'];
  $hs_state = $HTTP_POST_VARS['hs_state'];
  $hs_zip = $HTTP_POST_VARS['hs_zip'];
  $hs_degree = $HTTP_POST_VARS['hs_degree'];
  $hs_years = $HTTP_POST_VARS['hs_years'];
  $hs_graduated = $HTTP_POST_VARS['hs_graduated'];
  $college_name = $HTTP_POST_VARS['college_name'];
  $college_address = $HTTP_POST_VARS['college_address'];
  $college_city = $HTTP_POST_VARS['college_city'];
  $college_state = $HTTP_POST_VARS['college_state'];
  $college_zip = $HTTP_POST_VARS['college_zip'];
  $college_degree = $HTTP_POST_VARS['college_degree'];
  $college_years = $HTTP_POST_VARS['college_years'];
  $college_graduated = $HTTP_POST_VARS['college_graduated'];
  $gradschool_name = $HTTP_POST_VARS['gradschool_name'];
  $gradschool_address = $HTTP_POST_VARS['gradschool_address'];
  $gradschool_city = $HTTP_POST_VARS['gradschool_city'];
  $gradschool_state = $HTTP_POST_VARS['gradschool_state'];
  $gradschool_zip = $HTTP_POST_VARS['gradschool_zip'];
  $gradschool_degree = $HTTP_POST_VARS['gradschool_degree'];
  $gradschool_years = $HTTP_POST_VARS['gradschool_years'];
  $gradschool_graduated = $HTTP_POST_VARS['gradschool_graduated'];
  $techschool_name = $HTTP_POST_VARS['techschool_name'];
  $techschool_address = $HTTP_POST_VARS['techschool_address'];
  $techschool_city = $HTTP_POST_VARS['techschool_city'];
  $techschool_state = $HTTP_POST_VARS['techschool_state'];
  $techschool_zip = $HTTP_POST_VARS['techschool_zip'];
  $techschool_degree = $HTTP_POST_VARS['techschool_degree'];
  $techschool_years = $HTTP_POST_VARS['techschool_years'];
  $techschool_graduated = $HTTP_POST_VARS['techschool_graduated'];
  $typing_speed = $HTTP_POST_VARS['typing_speed'];
  $shorthand_speed = $HTTP_POST_VARS['shorthand_speed'];
  $crt_speed = $HTTP_POST_VARS['crt_speed'];
  $language = $HTTP_POST_VARS['language'];
  $language_type = $HTTP_POST_VARS['language_type'];
  $sign = $HTTP_POST_VARS['sign'];
  $affiliations = $HTTP_POST_VARS['affiliations'];
  $licence1_state = $HTTP_POST_VARS['licence1_state'];
  $licence2_state = $HTTP_POST_VARS['licence2_state'];
  $licence1_reg = $HTTP_POST_VARS['licence1_reg'];
  $licence2_reg = $HTTP_POST_VARS['licence2_reg'];
  $licence1_date = $HTTP_POST_VARS['licence1_date'];
  $licence2_date = $HTTP_POST_VARS['licence2_date'];
  $licence1_specialty = $HTTP_POST_VARS['licence1_specialty'];
  $licence2_specialty = $HTTP_POST_VARS['licence2_specialty'];
  $discharged = $HTTP_POST_VARS['discharged'];
  $discharge_company1 = $HTTP_POST_VARS['discharge_company1'];
  $discharge_company2 = $HTTP_POST_VARS['discharge_company2'];
  $discharge_reason1 = $HTTP_POST_VARS['discharge_reason1'];
  $discharge_reason2 = $HTTP_POST_VARS['discharge_reason2'];
  $felony = $HTTP_POST_VARS['felony'];
  $contact_pemploy = $HTTP_POST_VARS['contact_pemploy'];
  $contact_oemploy = $HTTP_POST_VARS['contact_oemploy'];
  $position1_start = $HTTP_POST_VARS['position1_start'];
  $position1_end = $HTTP_POST_VARS['position1_end'];
  $position1_name = $HTTP_POST_VARS['position1_name'];
  $position1_address = $HTTP_POST_VARS['position1_address'];
  $position1_city = $HTTP_POST_VARS['position1_city'];
  $position1_state = $HTTP_POST_VARS['position1_state'];
  $position1_zip = $HTTP_POST_VARS['position1_zip'];
  $position1_phone = $HTTP_POST_VARS['position1_phone'];
  $position1_job = $HTTP_POST_VARS['position1_job'];
  $position1_supervisor = $HTTP_POST_VARS['position1_supervisor'];
  $position1_responsbties = $HTTP_POST_VARS['position1_responsbties'];
  $position1_ssalary = $HTTP_POST_VARS['position1_ssalary'];
  $position1_fsalary = $HTTP_POST_VARS['position1_fsalary'];
  $position1_reason = $HTTP_POST_VARS['position1_reason'];
  $position1_difname = $HTTP_POST_VARS['position1_difname'];
  $position2_start = $HTTP_POST_VARS['position2_start'];
  $position2_end = $HTTP_POST_VARS['position2_end'];
  $position2_name = $HTTP_POST_VARS['position2_name'];
  $position2_address = $HTTP_POST_VARS['position2_address'];
  $position2_city = $HTTP_POST_VARS['position2_city'];
  $position2_state = $HTTP_POST_VARS['position2_state'];
  $position2_zip = $HTTP_POST_VARS['position2_zip'];
  $position2_phone = $HTTP_POST_VARS['position2_phone'];
  $position2_job = $HTTP_POST_VARS['position2_job'];
  $position2_supervisor = $HTTP_POST_VARS['position2_supervisor'];
  $position2_responsbties = $HTTP_POST_VARS['position2_responsbties'];
  $position2_ssalary = $HTTP_POST_VARS['position2_ssalary'];
  $position2_fsalary = $HTTP_POST_VARS['position2_fsalary'];
  $position2_reason = $HTTP_POST_VARS['position2_reason'];
  $position2_difname = $HTTP_POST_VARS['position2_difname'];
  $position3_start = $HTTP_POST_VARS['position3_start'];
  $position3_end = $HTTP_POST_VARS['position3_end'];
  $position3_name = $HTTP_POST_VARS['position3_name'];
  $position3_address = $HTTP_POST_VARS['position3_address'];
  $position3_city = $HTTP_POST_VARS['position3_city'];
  $position3_state = $HTTP_POST_VARS['position3_state'];
  $position3_zip = $HTTP_POST_VARS['position3_zip'];
  $position3_phone = $HTTP_POST_VARS['position3_phone'];
  $position3_job = $HTTP_POST_VARS['position3_job'];
  $position3_supervisor = $HTTP_POST_VARS['position3_supervisor'];
  $position3_responsbties = $HTTP_POST_VARS['position3_responsbties'];
  $position3_ssalary = $HTTP_POST_VARS['position3_ssalary'];
  $position3_fsalary = $HTTP_POST_VARS['position3_fsalary'];
  $position3_reason = $HTTP_POST_VARS['position3_reason'];
  $position3_difname = $HTTP_POST_VARS['position3_difname'];
  $position4_start = $HTTP_POST_VARS['position4_start'];
  $position4_end = $HTTP_POST_VARS['position4_end'];
  $position4_name = $HTTP_POST_VARS['position4_name'];
  $position4_address = $HTTP_POST_VARS['position4_address'];
  $position4_city = $HTTP_POST_VARS['position4_city'];
  $position4_state = $HTTP_POST_VARS['position4_state'];
  $position4_zip = $HTTP_POST_VARS['position4_zip'];
  $position4_phone = $HTTP_POST_VARS['position4_phone'];
  $position4_job = $HTTP_POST_VARS['position4_job'];
  $position4_supervisor = $HTTP_POST_VARS['position4_supervisor'];
  $position4_responsbties = $HTTP_POST_VARS['position4_responsbties'];
  $position4_ssalary = $HTTP_POST_VARS['position4_ssalary'];
  $position4_fsalary = $HTTP_POST_VARS['position4_fsalary'];
  $position4_reason = $HTTP_POST_VARS['position4_reason'];
  $position4_difname = $HTTP_POST_VARS['position4_difname'];
  $other_name = $HTTP_POST_VARS['other_name'];
  $other_address = $HTTP_POST_VARS['other_address'];
  $other_city = $HTTP_POST_VARS['other_city'];
  $other_state = $HTTP_POST_VARS['other_state'];
  $other_zip = $HTTP_POST_VARS['other_zip'];
  $other_phone = $HTTP_POST_VARS['other_phone'];
  $other_supervisor = $HTTP_POST_VARS['other_supervisor'];
  $other_from = $HTTP_POST_VARS['other_from'];
  $other_to = $HTTP_POST_VARS['other_to'];
  $ref1_name = $HTTP_POST_VARS['ref1_name'];
  $ref1_address = $HTTP_POST_VARS['ref1_address'];
  $ref1_city = $HTTP_POST_VARS['ref1_city'];
  $ref1_state = $HTTP_POST_VARS['ref1_state'];
  $ref1_zip = $HTTP_POST_VARS['ref1_zip'];
  $ref1_telephone = $HTTP_POST_VARS['ref1_telephone'];
  $ref1_years = $HTTP_POST_VARS['ref1_years'];
  $ref1_difname = $HTTP_POST_VARS['ref1_difname'];
  $ref2_name = $HTTP_POST_VARS['ref2_name'];
  $ref2_address = $HTTP_POST_VARS['ref2_address'];
  $ref2_city = $HTTP_POST_VARS['ref2_city'];
  $ref2_state = $HTTP_POST_VARS['ref2_state'];
  $ref2_zip = $HTTP_POST_VARS['ref2_zip'];
  $ref2_telephone = $HTTP_POST_VARS['ref2_telephone'];
  $ref2_years = $HTTP_POST_VARS['ref2_years'];
  $ref2_difname = $HTTP_POST_VARS['ref2_difname'];
  $ref3_name = $HTTP_POST_VARS['ref3_name'];
  $ref3_address = $HTTP_POST_VARS['ref3_address'];
  $ref3_city = $HTTP_POST_VARS['ref3_city'];
  $ref3_state = $HTTP_POST_VARS['ref3_state'];
  $ref3_zip = $HTTP_POST_VARS['ref3_zip'];
  $ref3_telephone = $HTTP_POST_VARS['ref3_telephone'];
  $ref3_years = $HTTP_POST_VARS['ref3_years'];
  $ref3_difname = $HTTP_POST_VARS['ref3_difname'];
  $other_information = $HTTP_POST_VARS['other_information'];
  $capable = $HTTP_POST_VARS['capable'];
  $accept = $HTTP_POST_VARS['accept'];
  $date = $HTTP_POST_VARS['date'];

  if (!$first_name || !$last_name || !$address || !$city || !$state || !$zip || !$h_telephone || !$ssn || !$contact_work ||
  !$position_apply || !$employed_bjrh || !$application_bjrh || !$eligibility || !$us_citizen ||
  !$hs_name || !$hs_address || !$hs_city || !$hs_state || !$hs_zip || !$hs_degree || !$hs_years || !$hs_graduated ||
  !$discharged || !$felony || !$ref1_name || !$ref1_address || !$ref1_city || !$ref1_state || !$ref1_zip || !$ref1_telephone ||
  !$ref1_years ||  !$ref2_name || !$ref2_address || !$ref2_city || !$ref2_state || !$ref2_zip || !$ref2_telephone ||
  !$ref2_years || !$accept)
  {
    echo 'You have not entered all the required information.<br />Required Information is marked with a <font color="#FF0000">*</font><br>'
         .'Please go <a href="javascript:history.back()">back</a> and try again.';
    exit;
  }
$conn = db_connect();

$query = "INSERT into application values
('".$appID."',
'".$first_name."',
'".$middle_name."',
'".$last_name."',
'".$address."',
'".$address2."',
'".$city."',
'".$state."',
'".$zip."',
'".$h_telephone."',
'".$b_telephone."',
'".$ssn."',
'".$contact_work."',
'".$title."',
'".$depID."',
'".$date_avail."',
'".$full_time."',
'".$part_time."',
'".$prn."',
'".$monday_from."',
'".$monday_to."',
'".$tuesday_from."',
'".$tuesday_to."',
'".$wednesday_from."',
'".$wednesday_to."',
'".$thursday_from."',
'".$thursday_to."',
'".$friday_from."',
'".$friday_to."',
'".$saturday_from."',
'".$saturday_to."',
'".$sunday_from."',
'".$sunday_to."',
'".$shift."',
'".$employed_bjrh."',
'".$application_bjrh."',
'".$what_name."',
'".$date_birth."',
'".$eligibility."',
'".$referred."',
'".$emergency_name."',
'".$emergency_phone."',
'".$m_branch."',
'".$m_special."',
'".$rank."',
'".$us_citizen."',
'".$legal_right."',
'".$hs_name."',
'".$hs_address."',
'".$hs_city."',
'".$hs_state."',
'".$hs_zip."',
'".$hs_degree."',
'".$hs_years."',
'".$hs_graduated."',
'".$college_name."',
'".$college_address."',
'".$college_city."',
'".$college_state."',
'".$college_zip."',
'".$college_degree."',
'".$college_years."',
'".$college_graduated."',
'".$gradschool_name."',
'".$gradschool_address."',
'".$gradschool_city."',
'".$gradschool_state."',
'".$gradschool_zip."',
'".$gradschool_degree."',
'".$gradschool_years."',
'".$gradschool_graduated."',
'".$techschool_name."',
'".$techschool_address."',
'".$techschool_city."',
'".$techschool_state."',
'".$techschool_zip."',
'".$techschool_degree."',
'".$techschool_years."',
'".$techschool_graduated."',
'".$typing_speed."',
'".$shorthand_speed."',
'".$crt_speed."',
'".$language."',
'".$language_type."',
'".$sign."',
'".$affiliations."',
'".$licence1_state."',
'".$licence2_state."',
'".$licence1_reg."',
'".$licence2_reg."',
'".$licence1_date."',
'".$licence2_date."',
'".$licence1_specialty."',
'".$licence2_specialty."',
'".$discharged."',
'".$discharge_company1."',
'".$discharge_company2."',
'".$discharge_reason1."',
'".$discharge_reason2."',
'".$felony."',
'".$contact_pemploy."',
'".$contact_oemploy."',
'".$position1_start."',
'".$position1_end."',
'".$position1_name."',
'".$position1_address."',
'".$position1_city."',
'".$position1_state."',
'".$position1_zip."',
'".$position1_phone."',
'".$position1_job."',
'".$position1_supervisor."',
'".$position1_responsbties."',
'".$position1_ssalary."',
'".$position1_fsalary."',
'".$position1_reason."',
'".$position1_difname."',
'".$position2_start."',
'".$position2_end."',
'".$position2_name."',
'".$position2_address."',
'".$position2_city."',
'".$position2_state."',
'".$position2_zip."',
'".$position2_phone."',
'".$position2_job."',
'".$position2_supervisor."',
'".$position2_responsbties."',
'".$position2_ssalary."',
'".$position2_fsalary."',
'".$position2_reason."',
'".$position2_difname."',
'".$position3_start."',
'".$position3_end."',
'".$position3_name."',
'".$position3_address."',
'".$position3_city."',
'".$position3_state."',
'".$position3_zip."',
'".$position3_phone."',
'".$position3_job."',
'".$position3_supervisor."',
'".$position3_responsbties."',
'".$position3_ssalary."',
'".$position3_fsalary."',
'".$position3_reason."',
'".$position3_difname."',
'".$position4_start."',
'".$position4_end."',
'".$position4_name."',
'".$position4_address."',
'".$position4_city."',
'".$position4_state."',
'".$position4_zip."',
'".$position4_phone."',
'".$position4_job."',
'".$position4_supervisor."',
'".$position4_responsbties."',
'".$position4_ssalary."',
'".$position4_fsalary."',
'".$position4_reason."',
'".$position4_difname."',
'".$other_name."',
'".$other_address."',
'".$other_city."',
'".$other_state."',
'".$other_zip."',
'".$other_phone."',
'".$other_supervisor."',
'".$other_from."',
'".$other_to."',
'".$ref1_name."',
'".$ref1_address."',
'".$ref1_city."',
'".$ref1_state."',
'".$ref1_zip."',
'".$ref1_telephone."',
'".$ref1_years."',
'".$ref1_difname."',
'".$ref2_name."',
'".$ref2_address."',
'".$ref2_city."',
'".$ref2_state."',
'".$ref2_zip."',
'".$ref2_telephone."',
'".$ref2_years."',
'".$ref2_difname."',
'".$ref3_name."',
'".$ref3_address."',
'".$ref3_city."',
'".$ref3_state."',
'".$ref3_zip."',
'".$ref3_telephone."',
'".$ref3_years."',
'".$ref3_difname."',
'".$other_information."',
'".$capable."',
'".$accept."',
'".$date."',
'".$read."')";
             

 $result = mysql_query($query)
        or die (mysql_errno() . ": " . mysql_error(). "\n");

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<? $HTTP_POST_VARS = array_map('trim', $HTTP_POST_VARS );
?>
that should trim the whitespaces at the beginning and end of all your form variables
Last edited by John Cartwright on Thu Mar 17, 2005 4:06 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the string you are exploding may have spaces in it around the pipe (|) .. you can use trim() to remove spaces around the resulting variables ($data[0], $data[1])
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

Thank you, I found my problem: have spaces in dropdown ' | ':

Code: Select all

<?php
echo '<option value="' . $row['title'] . ' | ' . $row['depID'] . '">' . $row[title] . '</option>';
?>
Also, I did use the code tag! :?:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

melindaSA wrote:Also, I did use the code tag! :?:
yes, you did.. but you're posting PHP code. PHP is highlighted when you use

Code: Select all

, not when you use

Code: Select all

.
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

Oh I see...sorry :oops:
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

imho the database might need some redesign... and the query generation might become far more simpler/clearer with a simple loop... instead of writing it completely..

my €0.02
Post Reply