Retro Gamer
Retro Gamer

Reputation: 1112

Getting submit button to work in PHP file

I have this PHP file that works , and I'm just trying to make a button at the bottom that when you click it, it takes you to another PHP file that displays "Purchase Successful!" What am I missing?

Heres the first PHP:

<!DOCTYPE>
<html>
<head>
<title>Confirmation Page</title>
<style>
</style>
</head>
<body bgcolor="#E6E6FA">
<h2>Customer:</h2>

<?php
//Check whether the form has been submitted
if (array_key_exists('check_submit', $_POST)) {
  //Converts the new line characters (\n) in the text area into HTML line breaks (the <br /> tag)
  $_POST['Comments'] = nl2br($_POST['Comments']); 
  //Check whether a $_GET['Languages'] is set
   if ( isset($_POST['Colors']) ) { 
   $_POST['Colors'] = implode(', ', $_POST['Colors']); //Converts an array into a single string
  }

  //Let's now print out the received values in the browser
  echo "Your first name: {$_POST['firstName']}<br />";
   echo "Your last name: {$_POST['lastName']}<br /><br />";
echo "Your address:<br />{$_POST['address']}<br /><br />";
echo "Your phone number: {$_POST['phone']}<br /><br />";
  echo "Your favourite gaming console: {$_POST['console']}<br /><br />";
   echo "Games you choose to purchase: {$_POST['games']}<br /><br />";
echo "Card being used: {$_POST['card']}<br />";
echo "Card Number: {$_POST['cardnumber']}<br />";
echo "Card Expiration Date: {$_POST['expdate']}<br /><br />";
 } else {
 echo "You can't see this page without submitting the form.";
}
?>
<form action="assign11_a.php"></form>
<input type="submit" value="Submit">
</body>
</html>

And here's where I want to go:

<!DOCTYPE>
<html>
<head>
<title>Purchase Successful!</title>
<style>
</style>
</head>
<body bgcolor="#E6E6FA">
<h2>Purchase Successful!</h2>
<?php

?>
</body>
</html>

Upvotes: 0

Views: 60

Answers (3)

Roh&#236;t J&#237;ndal
Roh&#236;t J&#237;ndal

Reputation: 27192

Please correct your code :

Before Correction :

<form action="assign11_a.php"></form>
<input type="submit" value="Submit">

After Correction :

<form action="assign11_a.php">
    <input type="submit" value="Submit" name="check_submit">
</form>

Upvotes: 1

Marc B
Marc B

Reputation: 360662

You have:

<form action="assign11_a.php"></form>
<input type="submit" value="Submit">

form elements NOT inside a <form> will not be submitted. And form elements with no name attribute will also not be submitted.

<form etc..>
   <input type="submit" name="submit_check" value="Submit">
</form>

would work.

Upvotes: 2

Rana Soyab
Rana Soyab

Reputation: 896

input button should be inside form

Upvotes: 4

Related Questions