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
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]
Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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