shane85 Posted April 6, 2010 Share Posted April 6, 2010 hey guys im trying to do some form validation but running into a problem....I have 2 pages, edit_prospect.php and edit_prospect2.php my form is on edit prospect.php but im viewing records with it so its always like edit_prospect.php?prospect_id=30 or something like that...when the form is submitted, it submits to edit_prospect2.php on edit_prospect2.php I have the following code <?php //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; // the if statements and error messages if($firstname == '') { $errmsg_arr[] = 'First name missing'; $errflag = true; } if($lastname == '') { $errmsg_arr[] = 'Last name missing'; $errflag = true; } if($contact_next == '') { $errmsg_arr[] = 'You must enter a date to contact this prospect next'; $errflag = true; } //If there are input validations, redirect back to the registration form if($errflag) { header("location: edit_prospect.php?prospect_id=38"); // for testing purposes im just testing the 38 record but eventually it will jus tbe to // edit_prospect.php?prospect_id=(variable for prospect_id here) } then on edit_prospect.php I just have the following <?php echo $errmsg_arr; ?> now obviously the form submits to it when there is an error, but it dosnt display what the error is. If u fill in the fields, it goes to the proper page. What is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/ Share on other sites More sharing options...
shane85 Posted April 6, 2010 Author Share Posted April 6, 2010 also, I tried changing it from prospect_id=38 to putting in the variable and I get this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in edit_prospect2.php on line 72 line 72 is header("location: edit_prospect.php?prospect_id=$arrEntry['prospect_id']"); Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/#findComment-1037618 Share on other sites More sharing options...
oni-kun Posted April 6, 2010 Share Posted April 6, 2010 <?php session_start(); //Array to store validation errors $_SESSION['errmesg'] = array(); Simple enough using sessions from then on. It'll allow you to keep the variable on any page provided you place session_start in it. ---- header("location: edit_prospect.php?prospect_id=$arrEntry['prospect_id']"); It should be: header("Location: edit_prospect.php?prospect_id={$arrEntry['prospect_id']}"); Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/#findComment-1037619 Share on other sites More sharing options...
shane85 Posted April 6, 2010 Author Share Posted April 6, 2010 thanks alot! solved!!! Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/#findComment-1037620 Share on other sites More sharing options...
shane85 Posted April 6, 2010 Author Share Posted April 6, 2010 ahhh....I jumped the gun..... using this header("Location: edit_prospect.php?prospect_id={$arrEntry['prospect_id']}"); submits the page and gives the error, however the record for $arrEntry['prospect_id'] doesnt print in the url, so it doesnt reload that form Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/#findComment-1037624 Share on other sites More sharing options...
anupamsaha Posted April 6, 2010 Share Posted April 6, 2010 Try this: header("Location: edit_prospect.php?prospect_id=".$arrEntry['prospect_id']); Hopefully, this will help. Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/#findComment-1037634 Share on other sites More sharing options...
shane85 Posted April 6, 2010 Author Share Posted April 6, 2010 nope still not putting the prospect_id in the header..hmm.... Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/#findComment-1037635 Share on other sites More sharing options...
shane85 Posted April 6, 2010 Author Share Posted April 6, 2010 hmm I tried putting this in the page cause I didnt know if it was getting the variable $prospect_id="'.$_GET['prospect_id'].'"; and now I can see the prospect_id in the header, but im getting this msg Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in edit_prospect2.php on line 65...and line 65 is the above code Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/#findComment-1037637 Share on other sites More sharing options...
shane85 Posted April 6, 2010 Author Share Posted April 6, 2010 I took out the double quotes so line 65 is as follows $prospect_id='.$_GET['prospect_id'].'; and I get the following error Parse error: syntax error, unexpected T_STRING in edit_prospect2.php on line 65 Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/#findComment-1037639 Share on other sites More sharing options...
oni-kun Posted April 6, 2010 Share Posted April 6, 2010 I took out the double quotes so line 65 is as follows $prospect_id='.$_GET['prospect_id'].'; and I get the following error Parse error: syntax error, unexpected T_STRING in edit_prospect2.php on line 65 If you look at the syntax highlighting it tells you, You should get a proper IDE/notepad that automatically highlights syntax, such as notepad++ / VIM. $prospect_id = $_GET['prospect_id']; Or if you wanted: header("Location: edit_prospect.php?prospect_id={$_GET['prospect_id']}"); Which should work fine. Remember syntax regarding quotes, and escaping them. It's one of the frontline debugging tasks! Quote Link to comment https://forums.phpfreaks.com/topic/197721-help-with-form-validation/#findComment-1037648 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.