Here is a slice of code that I have adapted a little from Kevin Yanks tutorial. I seem to get a ( Warning undefined variable cat2 ) in C: ect... I think the cat2 relates to the ID of paticular catagory in my catagory table. Everything despite these errors does work correctly I have done a bit of testing. However if I change ($$var) to ($var) I automaticly have ID's from all my catagories entered into my lookup table and if I only have one catagory in my catagory table eveything works fine i.e. no Warnings and no unsual behaviour.
//--------
$aid = mysql_insert_id();
$cats = mysql_query("SELECT ID, Name FROM ad_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 ad_lookup " .
"SET AID=$aid, CID=$cid";
$ok = mysql_query($sql);
if ($ok) {
echo("<P>Avertisment added to category: $cname</P>");
} else {
echo("<P>Error inserting advert into category $cname:" .
mysql_error() . "</P>");
}
} // end of if ($$var)
} // end of while loop
?>
//--------
There is also another problem that I have and I think could be very simple, athough I cant seem to solve It..
I get a Undifined variable on every page in the tutorial that has an if ($submit) argument ("argument" is that the right terminology)
The error is as follows..... Warning: Undefined Variable submit C: etc...
a sample of code that's giving me grief.
//------
<!-- editcat.php -->
<HTML>
<HEAD>
<TITLE> Edit Category </TITLE>
</HEAD>
<BODY>
<?php
$dbcnx = @mysql_connect("localhost", "root", "mypass");
mysql_select_db("forces_web");
if ($submit): // The category's details have
// been updated.
$sql = "UPDATE ad_categories SET " .
"Name='$name' " .
"WHERE ID=$id";
if (mysql_query($sql)) {
echo("<P>Category details updated.</P>");
} else {
echo("<P>Error updating category details: " .
mysql_error() . "</P>");
}
?>
<P><A HREF="cats.php">Return to Category list</A></P>
<?php
else: // Allow the user to edit the category
// with ID=$id
$cat=mysql_query("SELECT Name " .
"FROM ad_categories " .
"WHERE ID=$id");
if (!$cat) {
echo("<P>Error fetching category details: " .
mysql_error() . "</P>");
exit();
}
$cat = mysql_fetch_array($cat);
$name = $cat["Name"];
// Add slashes to database
// value for use as HTML attribute
$name = addslashes($name);
?>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Edit the categoryBR>
Name: <INPUT TYPE=TEXT NAME="name" VALUE="<?php echo($name); ?>" SIZE=20 MAXLENGTH=100><BR>
<INPUT TYPE=HIDDEN NAME="id" VALUE="<?php echo($id); ?>">
<INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>
</FORM>
<?php endif; ?>
</BODY>
</HTML>
//----------
Thank you to anyone offering help ( I need it ),
Thank you again,
Cas


BR>


Bookmarks