I have a php page that i want to be able to add news into a database. I used to have this working on my old computer but it won't work now.
Each time I load the page it gives me the following error:
Notice: Undefined variable: submit in C:\Program Files\Apache Group\Apache2\htdocs\admin\addnews.php on line 9
I copied everything inside the body tags on the page. I realisze its a bit long, but I figured you might need to see it all.
<?php
if ($submit): // news has been entered
// using the form.
if ($aid == "") {
echo("<P>You must choose an author " .
"for the news. Click 'Back' " .
"and try again.</P>");
exit();
}
$dbcnx = @mysql_connect("localhost", "Tyler Waterhouse", "");
mysql_select_db("alpha");
$sql = "INSERT INTO TechNews SET " .
"NewsText='$newstext', " .
"AID='$aid'";
if (mysql_query($sql)) {
echo("<P>News added</P>");
} else {
echo("<P>Error adding news: " .
mysql_error() . "</P>");
}
$nid = mysql_insert_id();
$cats = mysql_query("SELECT ID, Name FROM Categories");
while ($cat = mysql_fetch_array($cats)) {
$cid = $cat["ID"];
$cname = $cat["Name"];
$var = "cat$cid"; // The name of the variable
if ($$var) { // The checkbox is checked
$sql = "INSERT IGNORE INTO NewsLookup " .
"SET NID=$nid, CID=$cid";
$ok = mysql_query($sql);
if ($ok) {
echo("<P>News added to category: $cname</P>");
} else {
echo("<P>Error inserting news into category $cname:" .
mysql_error() . "</P>");
}
} // end of if ($$var)
} // end of while loop
?>
<P><A HREF="<?php echo($PHP_SELF); ?>">Add More News</A></P>
<P><A HREF="news.php">Return to News Search</A></P>
<?php
else: // Allow the user to enter a new category
$dbcnx = @mysql_connect("localhost", "Tyler Waterhouse", "");
mysql_select_db("alpha");
$authors = mysql_query("SELECT ID, Name FROM Authors");
$cats = mysql_query("SELECT ID, Name FROM Categories");
?>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Enter the news:<BR>
<TEXTAREA NAME="newstext" ROWS=15 COLS=65 WRAP>
</TEXTAREA>
<P>Author:
<SELECT NAME="aid" SIZE=1>
<OPTION SELECTED VALUE="">Select One
<OPTION VALUE="">---------
<?php
while ($author = mysql_fetch_array($authors)) {
$aid = $author["ID"];
$aname = $author["Name"];
echo("<OPTION VALUE='$aid'>$aname\n");
}
?>
</SELECT></P>
<P>Place in category:<BR>
<?php
while ($cat = mysql_fetch_array($cats)) {
$cid = $cat["ID"];
$cname = $cat["Name"];
echo("<INPUT TYPE=CHECKBOX NAME='cat$cid'>$cname<BR>\n");
}
?>
</P>
<P><INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>
</FORM>
<?php endif; ?>
I'm running apache 2.039, mysql 4.01alpha, and php 4.2.1
Any help would be great. Thanks