Notice: Undefined variable driving me crazy...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Wed Dec 11, 2002 1:48 pm
Location: Cincinnati

Notice: Undefined variable driving me crazy...

Postby baazil1 » Wed Feb 12, 2003 11:41 am

Code is...

if ($add== "yes"){

require ("");

or die ("Problem connecting to DataBase");

$query = "insert into news values ('$id','$subject',now())";
$result = mysql_db_query($bb_news_db, $query);

echo "Data inserted. new table:<br>";
?><a href="bb_news_admin.php3">Press here to go back to the input page</a>"<?

echo '
<font face="Arial, Helvetica, sans-serif" size="4"><b><font color="#0066FF">
News Entry Form</font></b></font></p>

<form method="post" name="form1" action="bb_news_admin.php3">
<INPUT NAME="id" TYPE=Hidden Value="0000" Size="">
<INPUT NAME="date" TYPE=Hidden Value=" " Size="">
<INPUT NAME="add" TYPE=Hidden Value="yes" Size="">
<font face="Arial, Helvetica, sans-serif">Subject:
<input type="text" name="subject"><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">

Problem is:
Notice: Undefined variable: add in F:\Inetpub\wwwroot\Clay\bb_news_admin.php3 on line 35

Please advise

New php-forum User
New php-forum User
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio

Postby Skeletor » Wed Feb 12, 2003 12:14 pm

you test if $add == "yes", but where does add get set? Seems like if it's an undefined variable, it is not getting set above the code you put into the msg.

perhaps make your if something like:

if(!empty($add) && $add == "yes") {

that will test to make sure it is set, is not empty and is equal to yes.

New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Postby pootergeist » Thu Feb 13, 2003 2:24 am

if you have register_globals set to OFF (as you really should do) in your ini file, you will not be able to address passed variables except through their array collective.

if($_POST['add'] == "yes")


if($HTTP_POST_VARS['add'] == "yes")

one of those should do the trick.

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 12 guests