Web Hosting Talk







View Full Version : Very annoying php bug


Studio64
09-12-2002, 02:42 AM
Essentially I'm attempting to quasi mimic the effect of phpMyAdmin. When you activate the checkbox after you click submit it will return to the previous page to re-enter another item

Input Page

<center>
<form action="secured.php">
<input type="hidden" name="loc" value="cars">
<input type="hidden" name="sloc" value="choose_model">
<input type="hidden" name="s2loc" value="create_model">
<input type="hidden" name="manu" value="<?echo $manu?>">
<input type="text" name="new_model" class="form"><br>

<div class="main">Insert New Model After Insert

<input type="checkbox" name="insertnew" <?echo $insert_again?> value="setnew" class="form">

</div>
<input type="submit" value="Create New Model" class="button_nowidth">
</form>
</center>


And.. The result page. It enters the information into the DB then determines if the checkbox was checked then includes a "meta" tag to refresh back to the previous page... But, php refuses to accept the information passed to it in the check box... I didn't want to clean up my debugging code b/c it shows what I have already tried to get the variable to show up in the second page

$sql = "INSERT INTO `car_model` VALUES ('', '$manu', '$new_model')";
//$res = mysql_query($sql);


echo "<br>"."--".$insertnew."--";


if (isset($insertnew))
{
?><META HTTP-EQUIV=Refresh CONTENT="0; URL=secured.php?loc=cars&sloc=choose_model&manu=$manu&insert_again=checked"><?
}
if ($insertnew == true)
echo "testing";
if ($insertnew)
echo "boolean";
if ($insertnew == "on")
echo "on";

if ($insertnew == "setnew")
echo "setnew";


When run... Nothing is echoed by the if statements and $insertnew echo's blank...
The page output at the echo "--".$insertnew."--" prints out as "----"....


Anyone have any clues about to why this isn't working?
I can provide for enviroment details about whats going on if need be...

RackNine
09-12-2002, 04:26 AM
Simple stuff first, you did extract($_POST) first, correct? Set the form's method="POST".

-Matt

Rich2k
09-12-2002, 04:27 AM
Depending on what version of PHP you are using and whether register_globals is off in php.ini.

However you should be using the super global arrays for form variables.

i.e. call $_POST['insertnew'] rather than $insertnew (and if your form is a get form use $_GET['insertnew']

Studio64
09-12-2002, 04:50 AM
echo "--".$_GET["insertnew"]."--"; will display the results...

What is the difference btwn GET and POST?
Why would the variables register differently?
What is the different syntax b/twn GET & POST in the <form> tag?

Rich2k
09-12-2002, 07:13 AM
A GET post is the protocol you use whenever you call a normal webpage like this. You will see lots of queries on the URL of the page. This is a GET

A post hides this information so that it doesn't appear in the URL. This is most certainly the best way when you are submitting usernames and passwords as the URL can't be copied and pasted.

However you should really define the method in your form to make good HTML. either add

method="get" or method="post" to your form tag

Studio64
09-12-2002, 04:14 PM
Thank you...