Jump to content

if statement....


somo

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]
Link to comment
https://forums.phpfreaks.com/topic/14388-if-statement/
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]
Link to comment
https://forums.phpfreaks.com/topic/14388-if-statement/#findComment-56792
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?
Link to comment
https://forums.phpfreaks.com/topic/14388-if-statement/#findComment-56831
Share on other sites

Archived

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

×
×
  • 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.