Jump to content

One glitch away from completion


webdevdea
Go to solution Solved by kicken,

Recommended Posts

<!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

Link to comment
Share on other sites

  • Solution

 

  $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");
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.