Newbie help - Forms and $PHP_SELF

Hi All,

I am brand new to PHP/MySQL/Apache…here is a question. I’m learning PHP from examples found in several books. A current issue has me vexed. The script with the form in it is called add.php. The form action handler calls itself with the method=“get” action=“add.php” statement . The form submit button is type=“submit” name=“add” value=“Submit” There are two simple text entry box’s that capture 2 variables.

The only error I get when I click the submit button button is “…error add unassigned variable…” I haven’t had much luck using $PHP_SELF either…So can a script call itself and if so does anyone have a suggestion for a fix??

I’m running Apache2.x, Php 4.x, Mysql 4.x on winXP prof.

In such a case, a posting of the code would be your best bet.

OK…here is the code…

Add rows using a form Quote:&nbsp
Author:

<?php if($add){ mysql_connect("localhost","phpuser", "phpuser1"); mysql_select_db("testdb"); $query="insert into quotes(quote, author)"; $query.=" values('$quote', '$author')"; $result=mysql_query($query); if ($result) echo "added one row successfully."; }

?>

And here are the error messages:

  1. Undefined variable: add in C:\Program Files\Apache Group\Apache2\htdocs\PHP_Testing\add.php on line 12
  2. Undefined variable: add in C:\Program Files\Apache Group\Apache2\htdocs\PHP_Testing\add.php on line 12, referer: http://localhost/php_testing/add.php[/code]

Your register_globals is off so you need to access the variables from the form with $_GET[‘variableName’] since that is your form method. There are many strings that deal with this issue or you can check out the manual if you have more questions.

Lig,

About 10 minutes after I posted the code I thought to really pour over the php.ini file to see if it offered any clues. I found a section at the top that said exactly what you have said. I changed
if($add)… to … if($_Request[“add”])

and the script started to work.

Thanks for the help.

Sponsor our Newsletter | Privacy Policy | Terms of Service