Some thoughts:

a) Why is $firstname empty?

   It's empty because the PHP directive register_globals = off.  
   So, PHP will not create $firstname automatically.  This is 
   most likely the cause.

b) How do I access $firstname with register_globals = off then?

   Many ways.  Regardless of register_globals setting, the 
   information is available in many ways, like:

   // Worked since PHP 3
   print $HTTP_POST_VARS['firstname'];

   // Worked since PHP 4.1.0
   print $_POST['firstname'];

   Or, you can create $firstname (or something similar) with 
   either extract() or import_request_variables().  Like:

   import_request_variables('gpc', 'r_');
   print $r_firstname;

   print $firstname;

c) What is register_globals?

  A controversial PHP directive.  As of PHP 4.2.0, this directive 
  defaults to off.  Before this, it was on.  So, many books, articles, 
  tutorials, etc. rely on it on, which makes life interesting 
  in the PHP world today.

There are many predefined variables, such as $_GET, too.

Philip Olson

On Sat, 1 Jun 2002, Wei Wang wrote:

> I am not sure if this is the right place to ask this naive question.
> I got a simple form addform.html and add.php look like the following.
> But everytime I got empty value from firstname and lastname. It seems like
> the input value in the html page was not passed on to the php variable $firstname in 
>add.php. Anyone give me a hand on this naive question?
> Great thanks.
> Wei
> addform.html
> <html>
> <body>
> <form action="add.php" method="post">
> First Name : <input type="text" name="firstname" size="40" length="40" value=""><BR>
> Surname : <input type="text" name="surname" size="40" length="40" value=""><BR>
> <input type="submit" name="submit" value="Submit">
> <input type="reset" name="reset" value="Clear It">
> </form>
> </body>
> </html>
> add.php
> <html>
> <body>
> <?php
> $db = pg_connect("dbname=friends");
> $query = "INSERT INTO friends (id, firstname, surname) values 
>(nextval('friends_id_seq'), '$firstname', '$surname')";
> $result = pg_exec($db, $query);
> if (!$result) {
> printf ("ERROR");
> $errormessage = pg_errormessage($db);
> echo $errormessage;
> exit;
> }
> printf ("These values were inserted into the database - %s %s", $firstname, 
> pg_close();
> ?>
> </body>
> </html>
> -- 
> PHP General Mailing List (
> To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to