Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Notice: Undefined variable driving me crazy...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Notice: Undefined variable driving me crazy...

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

Code is...

if ($add== "yes"){

require ("config.inc");

mysql_connect($bb_news_hostname,$bb_news_mysqluser,$bb_news_mysqlpassword)
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>"<?
}

else{
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">
</form><P>
';
}

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

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

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.
Skeletor
New php-forum User
New php-forum User
 
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio

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")

or

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

one of those should do the trick.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.