-1

It's only a simple file but the PHP echo is not showing up.

This is the code:

<!DOCTYPE HTML>
<html>
<body>

Welcome <?php echo $_GET['firstname']; ?><br>
Your new Account is: <?php echo $_GET['accountname']; ?>

<h4>Please clarify that the information below is correct</h4>

Account Name: <?php echo $_GET['accountname']; ?>
Contact Name: <?php echo $_GET['firstname']; ?> <?php echo $_GET["lastname"]; ?>
Address: <?php echo $_GET['address']; ?> <?php echo $_GET["street"]; ?> <?php echo $_GET["direction"]; ?> <?php echo $_GET["state"]; ?> <?php echo $_GET["zip"]; ?> <?php echo $_GET["pobox"]; ?>

</body>
</html>

And all it displays is "Welcome_______" etc. It shows all the words but not the echo outputs even when there are inputs in the form. It's like they are all being recognized as blanks.

Nisse Engström
  • 4,555
  • 22
  • 24
  • 38
  • 4
    What URL are you using? Does it have a proper query string? – Jay Blanchard Jul 14 '15 at 18:32
  • having those inputs in the form is pointless if the form hasn't been submitted yet. `$_GET` works off the url, so unless you ran this script with `http://example.com?firstname=John&accountname=foo&etc..` you won't get anything. – Marc B Jul 14 '15 at 18:43
  • 2
    You should turn warnings on. http://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings It's probably returning `Notice: Undefined index: firstname` and so on. – Karl Jul 14 '15 at 18:44
  • 1
    i think you form work with the POST, to check it change your $_GET['firstname'] to $_POST['firstname'] – volkinc Jul 14 '15 at 22:56

2 Answers2

0

You need two files in order to better understand it.

index.html Set of data from this file will be sent for processing.

<form action="account.php" method="GET">
  <input name="firstname" type="text" placeholder="First name here...">
  <input name="lastname" type="text" placeholder="Last name here...">
  <input type="submit" value="Process data">
</form>

account.php - Here will be data processed

<?php 

  if(isset($_GET['firstname']) && isset($_GET['lastname')){
    //if all data are set, say hello
    echo "Welcome ".$firstname." ".$lastname.",";
  }else{
    //if first name or last name is not set, redirect to form
    header('Location: index.html');
    exit;
  }
 ?>

You are sending data from simple HTML form to PHP script by GET. Difference between GET and POST method is that, GET is posted in URL: http://www.example.com/index.php?firstname=kamil and POST data are sent inside of request body (url is not changed). Difference is better described in this thread: What is the difference between POST and GET?

Community
  • 1
  • 1
3y3skill3r
  • 889
  • 1
  • 8
  • 27
-1

It will work when:

http://your_url.com?firstname=xyz&accountname=abc

$_GET['firstname'],$_GET['accountname']

Or use:

var_dump($_GET);
Legionar
  • 6,939
  • 2
  • 34
  • 66
Prashant Srivastav
  • 1,649
  • 15
  • 23
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – helmbert Jul 14 '15 at 20:15
  • @helmbert For leaving a comment you have to have 50 points ok. – Prashant Srivastav Jul 17 '15 at 04:32