Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1622 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

what is "Undefined index" error

Thread title: what is "Undefined index" error
Reply    
    Thread tools Search this thread Display Modes  
07-01-2009, 06:35 PM
#1
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old  what is "Undefined index" error

can anyone tell me what is Undefined index error mean if i have this simple code

PHP Code:
<?php
    
//defining the databse
    
define("DB_SERVER""localhost"); 
    
define("DB_USER""root"); 
    
define("DB_NAME""rms");
    
    
//connecting to that database
    
$connection mysql_connect(DB_SERVER,DB_USER)
        or die(
'error were found while connection to the db ' mysql_error()) ;
    
//selectin the database
    
$db_select mysql_select_db(DB_NAME $connection)
        or die(
'error were found while selecting the database ' .mysql_error()) ;
?>
<?php
    $first_name 
$_POST['f_name'];
    
$last_name $_POST['l_name'];
    
$sex $_POST['sex'];
    
$city $_POST['city'];
?>
<?php
    $processing 
mysql_query("INSERT INTO form( first_name,last_name,sex,city )
                               VALUES('
{$first_name}','{$last_name}','{$sex}','{$city}'");
                               
    if(
$processing){
        echo 
"you information was successfully created to our database if you want to see the list of our members click here"    ;
    }else{
        echo 
"adding your informaion have been failed .Try Again";
    }
?>

<title>Form</title>

    <form action="index.php" method="post">
        <h2>Please fill this form to add your information to our database</h2>
        <label> Frist Name: <input type="text" name="f_name"></label><br /><br />
        <label> Last Name: <input type="text" name="l_name"></label><br /><br />
        <label> Sex: <input type="text" name="sex"></label><br /><br />
        <label> city: <input type="text" name="city"></label><br /><br />
        <input type="submit" name="submit" value="add">
    </form>
this is very simple im just kinda doing a test for me. and there is a four froms that going to put information to the database it's very simple

i got this errors

it's beacuse of

PHP Code:
<?php
    $first_name 
$_POST['f_name'];
    
$last_name $_POST['l_name'];
    
$sex $_POST['sex'];
    
$city $_POST['city'];
?>
why this message is print out and what it means?

Reply With Quote
07-01-2009, 06:48 PM
#2
46Bit is offline 46Bit
Status: Member
Join date: Mar 2009
Location: Yorkshire
Expertise: Web Development
Software:
 
Posts: 275
iTrader: 10 / 100%
 

46Bit is on a distinguished road

Send a message via MSN to 46Bit Send a message via Skype™ to 46Bit

  Old

Undefined index is an error given when you try to get an element of an array that doesn't actually exist.

In your case, none of those elements actually exist in $_POST.

Reply With Quote
07-01-2009, 07:06 PM
#3
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

what can i do to make it exists?
isn't the name of the 4 inputs makeing it exists

Reply With Quote
07-01-2009, 07:50 PM
#4
46Bit is offline 46Bit
Status: Member
Join date: Mar 2009
Location: Yorkshire
Expertise: Web Development
Software:
 
Posts: 275
iTrader: 10 / 100%
 

46Bit is on a distinguished road

Send a message via MSN to 46Bit Send a message via Skype™ to 46Bit

  Old

Originally Posted by free-designer View Post
what can i do to make it exists?
isn't the name of the 4 inputs makeing it exists
Yes, but only when the form has already been submitted, so you'll get those errors when first loading the form. Just put array_key_exists('submit', $_POST) in an if statement surrounding the whole query & $_POST block.

Reply With Quote
07-01-2009, 08:05 PM
#5
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

ohh man thank you so mush it's working now very well
thanks you are the best ;-)

Reply With Quote
07-05-2009, 10:47 PM
#6
Faceless is offline Faceless
Status: Junior Member
Join date: Mar 2007
Location:
Expertise:
Software:
 
Posts: 66
iTrader: 2 / 100%
 

Faceless is on a distinguished road

Send a message via MSN to Faceless

  Old

You could also check to see if the form was submitted by using
isset($_POST['submit']) in an if statement wrapped around the whole php code. Works pretty much the same way as 46bit's method.

Reply With Quote
07-06-2009, 02:27 AM
#7
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

great thanks faceless

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed