By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

Undefined index. script works, why is this error occuring?

cassbiz
100+
P: 202
Here are the errors that are coming up in my error_log

Expand|Select|Wrap|Line Numbers
  1. Notice: Undefined index: andatum in /zipcode.php on line 11
  2. Notice: Undefined index: andatum in /zipcode.php on line 12
  3. Notice: Undefined index: abdatum in /zipcode.php on line 13
  4. Notice: Undefined index: zimmer in /zipcode.php on line 14
  5. Notice: Undefined index: city in /zipcode.php on line 39
  6. Notice: Undefined index: state in /zipcode.php on line 41
  7.  
Here is the script

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $include_path=dirname(__FILE__) ."/includes/";
  3.  
  4.         include $include_path."cust_kopf.php";
  5.         include $include_path."links.php";
  6.         include $include_path."en.php";
  7.         include $include_path."zip_con.php";
  8.  
  9.         $andatum = $_GET['andatum'];
  10.         $andatum2 = $_GET['andatum'];
  11.         $abdatum = $_GET['abdatum'];
  12.         $zimmer = $_GET['zimmer'];
  13.         $andatum=$_POST['andatum'];
  14.         $abdatum=$_POST['abdatum'];
  15.         $zimmer=$_POST['zimmer']; 
  16.  
  17. ?>
  18. <div align="center">
  19. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  20. <?php
  21.  
  22. while (list($name, $value) = each($_GET))
  23.   {
  24.    echo "<input type=\"hidden\" value=\"$value\" name=\"$name\">\n";
  25.   }
  26.  
  27. ?>
  28. </p></label><br />
  29.  
  30.  
  31. <?php
  32.  
  33.      $zip = $_POST['zip'];
  34.         $city = $_POST['city'];
  35.         $plz = $_POST['zip'];
  36.         $stadt = $_POST['state'];
  37.  
  38. $sql = ("SELECT zip, city, state FROM zip WHERE zip='$zip'");
  39.  
  40.  
  41.  // Request Zip Code Information
  42.  $result = @mysql_query($sql);
  43.  if (!$result) {
  44.    echo('<p>Error performing query: ' .   mysql_error() . '</p>');
  45.    echo $sql;
  46.    exit();
  47.  
  48.  }
  49.  
  50.  // Display the text of zip in a paragraph
  51.  while ($row = mysql_fetch_array($result)) {
  52.  if ($zip == 0) {
  53.  echo "<label><p id=p2>Please enter your Zip Code:<br />
  54. <input type='text' name='zip' />
  55. <input type='submit' value='Retrieve my city and state' /></form>
  56. <p id=p2>Click on \"Retrieve my city and state\"</p>";
  57.         }
  58.     else {
  59.     echo "<p id=p3> Your Zip Code is <font color=#c0c0ff><b>{$row['zip']}</b></font> which is located in";
  60.     echo "<b><font color=#c0c0ff>{$row['city']},   {$row['state']}</font></b>.<br />";
  61.     echo "Please press the continue button to enter your address information.</p>";
  62.         $city = $row['city'];
  63.         $state = $row['state'];
  64.         $stadt = $state;
  65.  
  66.     $row['zip'] = $plz;
  67.      echo '<table border="1" width="30%" ><tr id="tr3"><td align="center">';
  68.     echo '<a href="cust_cdata.php?andatum='.$andatum.'&abdatum='.$abdatum.'&plz='.$plz.'&ort='.$city.'&stadt='.$state.'&zimmer='.$zimmer.'&eingabe=1'.'">Continue to enter address</a>';
  69.     echo '</td></tr></table>';
  70.     }
  71. }
  72. ?>
  73. </div>
  74.  
Mar 6 '07 #1
Share this Question
Share on Google+
3 Replies


ronverdonk
Expert 2.5K+
P: 4,258
This is not an error, it is a NOTICE, as the message already said.

Theoratically you should check existence, define or initialize variables before using them. When you have full error notification on, you also get the notices.

Ronald :cool:
Mar 6 '07 #2

cassbiz
100+
P: 202
This is not an error, it is a NOTICE, as the message already said.

Theoratically you should check existence, define or initialize variables before using them. When you have full error notification on, you also get the notices.

Ronald :cool:
Thanks Ronald

When you say "define or initialize variables" what exactly do you mean?

I am a little slow this morning. Took too many stupid pills :)
Mar 6 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
By defining/initializing I mean
[php]$var1 = NULL; // defining
$var2 = 'Hello'; // initializing
[/php]
just a question of semantics. Some people call it defining, some initializing, as long as you give it a value or a null, it exists.
A variable is considered to be NULL if

- it has been assigned the constant NULL.
- it has not been set to any value yet.
- it has been unset().
Ronald :cool:
Mar 6 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.