Jump to content


Photo

if statement....


  • Please log in to reply
6 replies to this topic

#1 somo

somo
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 12 July 2006 - 02:44 PM

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.


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

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

  } else {

    //otherwise error msg

  }


#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 12 July 2006 - 02:52 PM

You need a semicolon at the end of your echo statement.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 somo

somo
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 12 July 2006 - 02:54 PM

i didnt put the ";" on the code on hear. Im getting undefined index on the if statement

You need a semicolon at the end of your echo statement.



#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 12 July 2006 - 03:02 PM

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:
<?php
if (isset($_POST['submit'])) {
  // form has been submitted
}
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 somo

somo
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 12 July 2006 - 03:36 PM

im not to sure where to place the isset if statement. What from the code below needs changing to get it to work?

<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>";

  } 


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:

<?php
if (isset($_POST['submit'])) {
  // form has been submitted
}
?>



#6 somo

somo
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 12 July 2006 - 04:45 PM

can any one help please  ???

#7 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 July 2006 - 04:48 PM

Here's how it works:

<?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
}
?>

Does that make sense?

Info: PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users