somo Posted July 12, 2006 Share Posted July 12, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14388-if-statement/ Share on other sites More sharing options...
effigy Posted July 12, 2006 Share Posted July 12, 2006 You need a semicolon at the end of your echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/14388-if-statement/#findComment-56775 Share on other sites More sharing options...
somo Posted July 12, 2006 Author Share Posted July 12, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14388-if-statement/#findComment-56776 Share on other sites More sharing options...
obsidian Posted July 12, 2006 Share Posted July 12, 2006 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]<?phpif (isset($_POST['submit'])) { // form has been submitted}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14388-if-statement/#findComment-56782 Share on other sites More sharing options...
somo Posted July 12, 2006 Author Share Posted July 12, 2006 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]<?phpif (isset($_POST['submit'])) { // form has been submitted}?>[/code][/quote] Quote Link to comment https://forums.phpfreaks.com/topic/14388-if-statement/#findComment-56792 Share on other sites More sharing options...
somo Posted July 12, 2006 Author Share Posted July 12, 2006 can any one help please ??? Quote Link to comment https://forums.phpfreaks.com/topic/14388-if-statement/#findComment-56829 Share on other sites More sharing options...
ober Posted July 12, 2006 Share Posted July 12, 2006 Here's how it works:[code]<?phpif(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? Quote Link to comment https://forums.phpfreaks.com/topic/14388-if-statement/#findComment-56831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.