Jump to content

[SOLVED] Undefined index


jim.davidson

Recommended Posts

I'm using php 5.0 mySql 4.1.21 and dreamweaver 8

 

I'm getting the following errors

 

Undefined index: contact_areacode

Undefined index: contact_phone_prefix

Undefined index: contact_first_name

Undefined index: contact_last_name

 

Here's the section of code

 

$contact_phone = $_POST['contact_areacode'];

  $contact_phone = $contact_phone.'-';

  $contact_phone = $contact_phone.$_POST['contact_phone_prefix'];

  $contact_phone = $contact_phone.'-';

  $contact_phone = $contact_phone.$_POST['contact_phone_last4'];

$contact_name = $_POST['contact_first_name'];

  $contact_name = $contact_name.' ';

  $contact_name = $contact_name.$_POST['contact_last_name']; 

 

Any idea what's wrong with it or what the error means?

Link to comment
https://forums.phpfreaks.com/topic/47611-solved-undefined-index/
Share on other sites

The error means that the array indexes 'contact_Areacode' have not beenset/have no value.

 

It is generally good practice to do an isset statement IE:

 

$contact_phone = isset($_POST['contact_areacode'])?$_POST['contact_areacode']:'';

 

Basically if the index contact_areacode in array post isset/has a value than set the variable to that array index if not set the variable to nothing.

 

This will prevent that error.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.