satrianixxx Posted November 18, 2012 Share Posted November 18, 2012 hello! I'm learning to php now and I have got various problems. One of them: I want to maka a basic program. When I type anything in a form, program will show these things at the same page. I did it and it was working but I've got error: "Notice: Undefined index: buton1 in C:\xampp\htdocs\deneme\same.php on line 6" Codes: <form name="form1" action="" method="post"> <input type="textbox" name="x"> <input type="submit" name="buton1" value="submit"> </form> <?PHP if($_POST["buton1"]){ $data = $_POST["x"]; echo $data; } ?> How can I solve this problem? Quote Link to comment Share on other sites More sharing options...
thara Posted November 18, 2012 Share Posted November 18, 2012 (edited) try with single quotes if (isset($_POST['buton1'])){ $data = $_POST['x']; echo $data; } Edited November 18, 2012 by thara Quote Link to comment Share on other sites More sharing options...
Andy123 Posted November 18, 2012 Share Posted November 18, 2012 try with single quotes if (isset($_POST['buton1'])){ $data = $_POST['x']; echo $data; } Why would it matter if single or double quotes are used? But as you wrote in your code, make use of the isset function to check if there was a submitted value for the buton1 element (i.e. if the button was clicked) instead of trying to access the value directly. If the page request is not a postback, then it won't exist. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted November 18, 2012 Share Posted November 18, 2012 A side note, relying on a submit button value being passed with the form upon submission is unreliable. There are certain situations in certain browsers where the submit button value will not be passed when the form is submitted. I recommend either using $_SERVER['REQUEST_METHOD'] == 'POST' or a hidden input to check whether a form has been submitted. Quote Link to comment Share on other sites More sharing options...
satrianixxx Posted November 18, 2012 Author Share Posted November 18, 2012 The problem is solved. Thanks for your advices! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.