Undefined variable - help

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
ansa1
Forum Newbie
Posts: 16
Joined: Sat Mar 27, 2004 9:19 am
Location: Ontario, Canada

Undefined variable - help

Post by ansa1 »

Hi everyone

First off al I want to say it is my first PHP “project “ – in my life - so newbie I am (LOL) all postings on this forum - seems to me like “magician world”(LOL) – people are talking and I don’t know what about …
but somewhere have to be … the first step … very go !

I made a page with a data - where client should write its information (add- user-record.php) and after submit - button - data is stored - and this page should recall other page (continue updating information - $insertGoTo = "booking_details.php?email=$email")booking_details.pht .

All what I got is an error - what is wrong ? ( I know me LOL)

Notice: Undefined variable: email in c:\inetpub\wwwroot\dreamweaverhotel\booking\add_user_record.php on line 50

Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\dreamweaverhotel\booking\add_user_record.php:50) in c:\inetpub\wwwroot\dreamweaverhotel\booking\add_user_record.php on line 55

Code: Select all

<?php require_once('../Connections/phpbook.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
&#123;
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) &#123;
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  &#125;
  return $theValue;
&#125;

$editFormAction = $_SERVER&#1111;'PHP_SELF'];
if (isset($_SERVER&#1111;'QUERY_STRING'])) &#123;
  $editFormAction .= "?" . htmlentities($_SERVER&#1111;'QUERY_STRING']);
&#125;

if ((isset($_POST&#1111;"MM_insert"])) && ($_POST&#1111;"MM_insert"] == "userform")) &#123;
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, province, country, postCode, telephone, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST&#1111;'title'], "text"),
                       GetSQLValueString($_POST&#1111;'firstName'], "text"),
                       GetSQLValueString($_POST&#1111;'lastName'], "text"),
                       GetSQLValueString($_POST&#1111;'address1'], "text"),
                       GetSQLValueString($_POST&#1111;'address2'], "text"),
                       GetSQLValueString($_POST&#1111;'town'], "text"),
                       GetSQLValueString($_POST&#1111;'province'], "text"),
                       GetSQLValueString($_POST&#1111;'country'], "text"),
                       GetSQLValueString($_POST&#1111;'postCode'], "text"),
                       GetSQLValueString($_POST&#1111;'telephone'], "int"),
                       GetSQLValueString($_POST&#1111;'email'], "text"));

  mysql_select_db($database_phpbook, $phpbook);
  $Result1 = mysql_query($insertSQL, $phpbook) or die(mysql_error());

  $insertGoTo = "booking_details.php?email=$email";
  if (isset($_SERVER&#1111;'QUERY_STRING'])) &#123;
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER&#1111;'QUERY_STRING'];
  &#125;
  header(sprintf("Location: %s", $insertGoTo));
&#125;
?>
any help ?

Thanks
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post by Goowe »

Code: Select all

<?php
  $insertGoTo = "booking_details.php?email=$email";
?>
The part saying the variable is undefined is line 50. It's just an E_NOTICE not a big warning. I'm not sure why it's picking up as not being defined :roll: someone else should have an answer for ya :wink:

Code: Select all

<?php
header(sprintf("Location: %s", $insertGoTo)); 
?>
On line 55 you're trying to redirect the site to booking_details.php?email=$email? One problem, is that the header() function needs to be above HTML, blank lines, and HTML... so for the redirect to work it needs to be at the top of the page.
php.net wrote: Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
I think, also, if the variable on line 50 isn't being set then the header redirect wouldn't work... :roll:
ansa1
Forum Newbie
Posts: 16
Joined: Sat Mar 27, 2004 9:19 am
Location: Ontario, Canada

Post by ansa1 »

Thank you – for this helpful information.

ansa1
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Welcome to the forum! Glad to see another Canadian in the community. ;)

Make sure to read the first link in my signature.

Regards.
Post Reply