Undefined variable: submit in C
Posted by: emick (183.171.173.---)
Date: March 25, 2013 11:57AM

please help me, i have no idea about undefined variable. here is the code.


<html>
<body>
<?php
if ($submit) {
// process form
$db = mysql_connect("localhost", "root"winking smiley;
mysql_select_db("mydb",$db);
$sql = "INSERT INTO employees (first,last,address,position) VALUES
('$first','$last','$address','$position')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
} else{
// display form
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?> ">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Address:<input type="Text" name="address"><br>
Position:<input type="Text" name="position"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
} // end if
?>
</body>
</html>

Options: ReplyQuote
Re: Undefined variable: submit in C
Posted by: RiggsFolly (---.as13285.net)
Date: March 25, 2013 01:09PM

<?php
if ($submit) {
// process form

when the form first loads there is no $submit as it is only created by pressing the submit button and posting the form data back to the php.

you need to use if ( isset($submit) ) or if ( array_key_exists('submit', $_POST ) )

Options: ReplyQuote
Re: Undefined variable: submit in C
Posted by: emick (183.171.164.---)
Date: March 25, 2013 02:28PM

now it become

Notice: Undefined variable: name in C:\wamp\www\test\hi.php on line 9

Notice: Undefined variable: submit in C:\wamp\www\test\hi.php on line 9
Thank you! Information entered.

this is my coding

<html>
<body>
<?php
if ( array_key_exists('submit', $_POST ) ) {
// process form
$db = mysql_connect("localhost", "root"winking smiley;
mysql_select_db("aku",$db);
$sql = "INSERT INTO kau (name, submit) VALUES
('$name','$submit')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
} else{
// display form
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<input type="text" name="name">
<input type="submit" name="submit">
</form>

<?php
}
?>
</body>
</html>

Options: ReplyQuote
Re: Undefined variable: submit in C
Posted by: RiggsFolly (---.as13285.net)
Date: March 25, 2013 02:47PM

You need to read some tutorials on PHP programming.

This is not the site for PHP programming help.

Options: ReplyQuote
Re: Undefined variable: submit in C
Posted by: emick (183.171.164.---)
Date: March 25, 2013 03:02PM

oh, okey. btw thank you smiling smiley

Options: ReplyQuote


Sorry, only registered users may post in this forum.