user2975787
user2975787

Reputation: 83

PHP $_GET not giving me required result

I am writing a PHP code in Adobe Dreamweaver. My code is as shown below. I am expecting my code to output two boxes, into which I write something. And when I click on the submit button, I expect to see the two separate things that I entered into the box to be concatenated. But I'm not getting a concatenation. In fact, NOTHING happens when I click on submit. I am confused. Is this code not something I should be using Dreamweaver for? I am relatively new to PHP and I do not understand all the bits. My suspicion is that Dreamweaver does not recognize "twoFieldForm.php". Can someone please tell me how I can overcome this issue?

<!DOCTYPE html>
<html>
<head> </head>
<body>
<h1>Form Filler</h1>

    <?php

    function joined($s1, $s2) {
        return array($s1.$s2, strlen($s1.$s2));
    }

    $first = $_GET[fieldOne];
    $second = $_GET[fieldTwo];
    $answer = joined($first, $second);
      echo "The concatenated string is \"{$answer[0]}\" 
      and its length is \"{$answer[1]}\";
    ?>

    <form action = "twoFieldForm.php" method = "get">
    Field 1 : <input type = "text" name = "fieldOne"/>
    Field 2 : <input type = "text" name = "fieldTwo"/>
      <input type = "submit">
    </form>
  </body>
</html>

Upvotes: 2

Views: 218

Answers (3)

Sanjaya
Sanjaya

Reputation: 156

$answer=$_GET['fieldOne'].$_GET['fieldTwo'];
echo "concatenated string is:".$answer;

try this...

Upvotes: 0

xate
xate

Reputation: 6379

<!DOCTYPE html>
<html>
<head> </head>
<body>
<h1>Form Filler</h1>

<?php

    function joined($s1, $s2) {
        return array($s1.$s2, strlen($s1.$s2));
    }

    $first = $_GET['fieldOne'];
    $second = $_GET['fieldTwo'];
    $answer = joined($first, $second);
    echo "The concatenated string is \"{$answer[0]}\" 
    and its length is \"{$answer[1]}\"";
?>

<form action="" method="GET">
    Field 1 : <input type="text" name="fieldOne"/>
    Field 2 : <input type="text" name="fieldTwo"/>
    <input type="submit">
</form>

</body>
</html>

Explanation: You have to add quotes in $_GET['']. Remember indention please, always when I see people using adobe dreamweaver, their code is horrible... If you are refering to the same file, you don't have to use an action="somewhat.php". Just leave it empty. Aswell you have missed a " after your echo statement. This will work now. Please start using a good IDE then you won't have those basic mistakes because the IDE will show you your mistakes already...

Upvotes: 7

stepozer
stepozer

Reputation: 1191

Try add quotes:

  $first = $_GET['fieldOne'];
  $second = $_GET['fieldTwo'];

Upvotes: 2

Related Questions