note 49382 added to function.unset
| From: | bouguerra at gmail dot com | Date: | Wed, 26 Jan 2005 09:12:36 +0000 |
| Subject: | note 49382 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84010@lists.php.net to get a copy of this message | ||
This is driving me crazy can anybody please help me and save my life!!!!
the problem is that everytime I refresh the page the variable $categories_input is always set
eventhough I unset it :((
and it get gets into the database!!!!
here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<h1>Update your Categories</h1>
<?
session_start();
function foo()
{
unset($GLOBALS['categories_input']);
}
?>
<body>
<form method="GET" action="<?php echo $PHP_SELF; ?>" >
<?
//connect to the database
mysql_connect("localhost", "", "") or die(mysql_error());
//select or connect to the table
mysql_select_db("") or die(mysql_error());
//if the button insert is clicked
if(isset ($categories_input ) && $categories_input != "default" ) {
$categ = addslashes($categories_input);
$query ="insert into categories_num (category) values ('".$categ."')
";
$result = mysql_query($query);
foo();
}
$query ="select * from categories_num";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
//echo "<p> The number of categories in the database is " .$num_results.
"</p>";
echo "<table border='0'>";
for ($i =0, $j = 1; $i<$num_results; $i++, $j++)
{
$row = mysql_fetch_array($result);
$the_id = $row["catid"] ;
echo "<tr><td>";
print "<input type=radio name=catid value= $the_id >";
echo "</td><td>";
echo htmlspecialchars(stripslashes($row["category"]));
echo "</td></tr>";
}
echo "</table>";
?>
<br> Add a new category </br>
<input type="text" name="categories_input" value="default"
size="40" > <br>
<input type="submit" name="add" value="submit">
</form>
</body>
</html>
----
Manual Page -- http://www.php.net/manual/en/function.unset.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49382
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49382&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49382&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49382&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49382&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49382&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49382&report=yes
Search -- http://master.php.net/manage/user-notes.php