webdevdea Posted June 11, 2013 Share Posted June 11, 2013 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Hi User</title> </head> <body> <h1>Hi User</h1> <?php if (filter_has_var(INPUT_POST, "userName") && filter_has_var(INPUT_POST, "bName")){ // the form exists, so work with it $userName = filter_input(INPUT_POST, "userName") && $bName = filter_input(INPUT_POST, "bName"); print "<h2>Hi there, $userName $bName </h2> \n"; } else { //there's no input. Create the form print <<< HERE <form action = "" method = "post"> <fieldset> <label>Please enter your name</label> <input type = "text" name = "userName" /> <label>Please enter your name</label> <input type = "text" name = "bName" /> <button type = "submit"> submit </button> </fieldset> </form> HERE; } // end 'value exists' if ?> </body> </html> It is supposed to have two fields where you enter your name and when you submit it, a form with hi and those two name on it.. well when you hit submit it says (hi 1)????? Help Quote Link to comment https://forums.phpfreaks.com/topic/279019-one-glitch-away-from-completion/ Share on other sites More sharing options...
Solution kicken Posted June 11, 2013 Solution Share Posted June 11, 2013 $userName = filter_input(INPUT_POST, "userName") && $bName = filter_input(INPUT_POST, "bName"); That is going to be evaluated as: $userName = (filter_input(INPUT_POST, "userName") && $bName = filter_input(INPUT_POST, "bName")); $userName is going to be assigned the result of the && operation which is going to be either true or false depending on the arguments. Rather than trying to do both assignments on the same statement, just separate them into two statements. $userName = filter_input(INPUT_POST, "userName"); $bName = filter_input(INPUT_POST, "bName"); Quote Link to comment https://forums.phpfreaks.com/topic/279019-one-glitch-away-from-completion/#findComment-1435250 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.