wwprnama Posted August 6, 2007 Share Posted August 6, 2007 I hope I don't get flamed for this, cause I figured this might be the forum to post this in. Anyways, I'm starting to learn php and I got this code I was testing : <body> <h1>Hi User</h1> <?php if (empty($userName)) { print " <form method=\"post\" action=\"one page form.php\"> Please enter your name : <input type = \"text\" name = \"userName\"><br> <input type = \"submit\"> </form>";} else { $userName = $_REQUEST["userName"]; print "<h3>Hi there, $userName!</h3>";}; ?> </body> Now as you can see, the attempt here is to get a form value on the same page with that empty function. So with that being said, any tips or pieces of advice one could offer me? Quote Link to comment https://forums.phpfreaks.com/topic/63594-newbie-code/ Share on other sites More sharing options...
lightningstrike Posted August 7, 2007 Share Posted August 7, 2007 First of all wrong forum use php code forum. beta test your stuff is for functional products that can be linked to for SQL injection, XSS, CSRF, and other vulnerability and functional testing. Secondly the code is poorly written. AVOID $_REQUEST which allows GET, POST, and COOKIE a real security threat. <?php if (empty($_POST["userName"])) { print " <form method=\"post\" action=\"one page form.php\"> Please enter your name : <input type = \"text\" name = \"userName\"> <input type = \"submit\"> </form>"; }else{ $userName = $_POST["userName"]; print "<h3>Hi there, $userName!</h3>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/63594-newbie-code/#findComment-317178 Share on other sites More sharing options...
wildteen88 Posted August 7, 2007 Share Posted August 7, 2007 YOu shoud use isset rather than empty: <?php if(isset($_POST['userName']) && !empty($_POST['userName'])) { $userName = $_POST['userName']; print "<h3>Hi there, $userName!</h3>"; } else { ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Please enter your name : <input type="text" name="userName"><br /> <input type="submit" value="Post Username"> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/63594-newbie-code/#findComment-317200 Share on other sites More sharing options...
wwprnama Posted August 7, 2007 Author Share Posted August 7, 2007 Thanks guys, I'm mainly learning from a book called PHP 5/MySQL Programming for the Absolute Beginner, written by Andy harris. I'm pretty sure that alot of the code that gets thrown at me through there is error after error of poorly written code, so I can only hope that i'll find enough poeple on here that wanna help. Quote Link to comment https://forums.phpfreaks.com/topic/63594-newbie-code/#findComment-317377 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.