maddie2120 Posted September 28, 2011 Share Posted September 28, 2011 Hi I found this php code which I'm adapting for a project, and I've run into the curly braces problem - could someone look at it for me as I've been looking for hours and still can't sort it out!. It's a form that adds dates and information to a database, the problem is at the error handling stage towards the end of the script - if anyone has any ideas I would be very grateful <form name="reminder" action="remind.php" method="post"> <table border='0' align='center' cellpadding="5" cellspacing="5"> <tr> <td>First Name:</td> <td colspan="3"> <input name="fname" type="text" maxlength="30" /> </td> </tr> <tr> <td>Last Name:</td> <td colspan="3"> <input name="lname" type="text" maxlength="30" /> </td> </tr> <tr> <td>Email Address:</td> <td colspan="3"> <input name="email" type="text" maxlength="50" /> </td> </tr> <tr> <td>Comapny:</td> <td colspan="3"> <input name="company" type="text" maxlength="50" /> </td> </tr> <tr> <td>Date Certificate taken:</td> <td> Day:<br /> <select name="day"> <?php for($counter=1;$counter<=31;$counter++) { if($counter < 10) $prefix = "0"; else $prefix = ""; echo("\n<option>$prefix$counter</option>"); } ?> </select></td> <td>Month:<br /> <select name="month"> <?php for($counter=1;$counter<=12;$counter++) { if($counter < 10) $prefix = 0; else $prefix = ""; echo("\n<option>$prefix$counter</option>"); } ?> </select></td> <td>Year:<br /> <select name="year"> <?php $current_year = date("Y"); for($counter=$current_year;$counter>=$current_year-5;$counter--) { echo("\n<option>$counter</option>"); } ?> </select></td> </tr> <tr> <td id="alert">*Please complete all fields</td> <td colspan="3"> <input name="step" type="hidden" value="1" /> <input name="submit" type="submit" value="add" /> </td> </tr> </table> </form> </div> </body> </html> <?php // Check for errors in the submitted form... } else { $error = ""; $date = date( "dmY" ); $renew_date = $_POST['day'].$_POST['month'].$_POST['year']; if( empty($_POST['fname']) ) $error .= "Please enter a first name<br />"; if( empty($_POST['lname']) ) $error .= "Please enter a last name<br />"; if( empty($_POST['email']) ) $error .= "Please enter a valid email address<br />"; if(!isEmail($email) ) $error .= "You have entered an invalid e-mail address, please try again.<br />"; if( !checkdate( $_POST['day'], $_POST['month'], $_POST['year'] )) $error .= "The date entered is invalid, please check<br />"; if( empty( $error ) ) { // No error let's add the entry mysql_query( "INSERT INTO clients('first_name', 'last_name', 'email', 'enrolled', 'company') VALUES('".addslashes($_POST['fname'])."', '".addslashes($_POST['lname'])."', '".addslashes($_POST['email'])."', '".addslashes($renew_date)."', '".addslashes($_POST['company'])."')" ); // Let's go to the Reminder List page Header("Refresh: 1;url=list.php"); echo <<< _HTML_END_ Reminder Added, redirecting ... _HTML_END_; } else { // Error occurred let's notify it echo( $error ); } } ?> Quote Link to comment Share on other sites More sharing options...
the182guy Posted September 28, 2011 Share Posted September 28, 2011 Error message? Quote Link to comment Share on other sites More sharing options...
Buddski Posted September 28, 2011 Share Posted September 28, 2011 There appears to be no "if statement" before the following else. // Check for errors in the submitted form... } else { Quote Link to comment Share on other sites More sharing options...
maddie2120 Posted September 28, 2011 Author Share Posted September 28, 2011 Thank you for your quick response, I must have had a senior moment - I'd commented out the 'if' statement at the top of the page. Hopefully problem is sorted now. Many thanks Quote Link to comment Share on other sites More sharing options...
harristweed Posted September 28, 2011 Share Posted September 28, 2011 It looks like the error is on line 81. There is a closing brace and no opening brace above it. I think that there should be something like: <?php if($_POST['submit']=="submit") { ?> at the top of the code... Quote Link to comment Share on other sites More sharing options...
maddie2120 Posted September 28, 2011 Author Share Posted September 28, 2011 Yes I accidentally commented out the following code at the top of the page: <?php include('../dbconnect.php'); // database connectivity file if($_POST['step'] != '1') { ?> Unfortunately now I keep getting the 'undefined index' error message, the 'if' statement refers to the hidden field in the form. Any ideas as to how I can fix this? I have an understanding of php but I'm really a novice at this. Quote Link to comment Share on other sites More sharing options...
Buddski Posted September 28, 2011 Share Posted September 28, 2011 Is that if statment used to detect when the form hasnt been submitted yet? If so, if (!isset($_POST['step'])) { Quote Link to comment Share on other sites More sharing options...
maddie2120 Posted September 28, 2011 Author Share Posted September 28, 2011 Yes, if the form has not been submitted then display the form, if it has then go to: // Let's go to the List page Header("Refresh: 1;url=list.php"); echo <<< _HTML_END_ Reminder Added, redirecting ... _HTML_END_; } else { // Error occurred let's notify it echo( $error ); } } Quote Link to comment Share on other sites More sharing options...
Buddski Posted September 28, 2011 Share Posted September 28, 2011 Just replace <?php include('../dbconnect.php'); // database connectivity file if($_POST['step'] != '1') { ?> with <?php include('../dbconnect.php'); // database connectivity file if(!isset($_POST['step'])) { ?> And it should get rid of that undefined error. Quote Link to comment Share on other sites More sharing options...
maddie2120 Posted September 28, 2011 Author Share Posted September 28, 2011 Thank you very much, that's done the trick - not sure why it includes the additional bit, is it just testing for a boolean value? Quote Link to comment Share on other sites More sharing options...
Buddski Posted September 28, 2011 Share Posted September 28, 2011 That if statement is basically saying "If $_POST['step'] is NOT set" which when there is no post data is true Quote Link to comment Share on other sites More sharing options...
maddie2120 Posted September 28, 2011 Author Share Posted September 28, 2011 Okay I think I prefer the simpler statement. Many thanks again, I'm still working on this application and I'm sure I'll run into all sorts of problems so I'll certainly be using this forum a lot. Quote Link to comment 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.