Jump to content

Archived

This topic is now archived and is closed to further replies.

somo

if statement....

Recommended Posts

i have got an if statement to submit data to a mysql db. But get an error shown in bold below.  I think its as i havent reference the submit button properly, can any one tell me how?

cheers.


[code]
echo "<input type='submit' value='Confirm Booking' >"

  if ($_POST['submit']) { // <----------error here
   
//add data to database

  } else {

    //otherwise error msg

  }[/code]

Share this post


Link to post
Share on other sites
You need a semicolon at the end of your echo statement.

Share this post


Link to post
Share on other sites
i didnt put the ";" on the code on hear. Im getting undefined index on the if statement

[quote author=effigy link=topic=100313.msg395764#msg395764 date=1152715934]
You need a semicolon at the end of your echo statement.
[/quote]

Share this post


Link to post
Share on other sites
you'll always get that before your form is submitted. that's why you need to check if it is set instead of just referencing the variable:
[code]
<?php
if (isset($_POST['submit'])) {
  // form has been submitted
}
?>
[/code]

Share this post


Link to post
Share on other sites
im not to sure where to place the isset if statement. What from the code below needs changing to get it to work?

[code]
<input type='submit' value='Confirm Booking'>

<?

if (isset($_POST['submit'])) {
   
mysql_query("INSERT INTO Bookings VALUES ('$username', '$R_ID', '$Todays_Date', '$Arrive', '$Depart', '$date_diff', '$Adults', '$Childs', '$Cost')")or die("Error Inserting Customer Details: ".mysql_error());
mysql_close($link);
print "<p>Booking Added, re-driecting you to payment page</p>";

  }
[/code]


[quote author=obsidian link=topic=100313.msg395771#msg395771 date=1152716573]
you'll always get that before your form is submitted. that's why you need to check if it is set instead of just referencing the variable:
[code]
<?php
if (isset($_POST['submit'])) {
  // form has been submitted
}
?>
[/code]
[/quote]

Share this post


Link to post
Share on other sites
Here's how it works:

[code]<?php
if(isset($_POST['submit']))
{
      // process form variables, show thank you, etc.
}
else
{
?>
  <form name="myform" method="post" action="thispage.php">

  <!-- inputs and rest of form -->
 
  <input type="submit" value="Submit" />
  </form>
<?php
}
?>[/code]

Does that make sense?

Share this post


Link to post
Share on other sites

×

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.