berilac Posted September 25, 2006 Share Posted September 25, 2006 Hi,I have an html form included in a php file.when it submits it uses post to change a variable from 0 to 1, so that if any errors occur it will display relevant error messages. To briefly explain, when its set to 0, only the form is shown and no error checks are made, but when they click submit it changes it to 1 and allows the php to make error checks. (Sorry if this is badly explained - im new to php)however, on clicking refresh, i would like the variable to be reset to 0 so that no error checks are made, but i cant change the $_POST value back to 0.Heres the beginning to the code, which hopefully will clarify where ive made a complete idiot of myself with my bad coding... :|[code]<?/* Load html backplate */ include ("../html/head.html");include 'db.php'; /* Check that the user has submitted their details */$submitcheck = 0;$submitcheck = $_POST['submitcheck'];if ($submitcheck == 0){ /* load form */ include ("../html/regfrm.html");}else{$_POST['submitcheck'] = 0; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $website = $_POST['website']; $info = $_POST['info'];[/code]Please, if anyone can help, it would be amazing.Just ask if i need to explain myself better, etc.Thank youMichael Quote Link to comment https://forums.phpfreaks.com/topic/22023-change-_post/ Share on other sites More sharing options...
kenrbnsn Posted September 25, 2006 Share Posted September 25, 2006 The $_POST array is recreated each time the form is submitted (that includes on a refresh), so setting a value in $_POST and expecting the form to to reflect the change will not work.What you probably want to used here is a session variable. Try something like this:[code]<?phpsession_start();/* Load html backplate */ include ("../html/head.html");include 'db.php'; /* Check that the user has submitted their details */$submitcheck = (isset($_SESSION['submitcheck']))?$_SESSION['submitcheck']:false;if (!isset($_POST['submit'])){ /* load form */ include ("../html/regfrm.html");}else{$_SESSION['submitcheck'] = true; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $website = $_POST['website']; $info = $_POST['info'];?>[/code]This assumes that the Submit button on the form is named 'submit'.Ken Quote Link to comment https://forums.phpfreaks.com/topic/22023-change-_post/#findComment-98490 Share on other sites More sharing options...
ober Posted September 25, 2006 Share Posted September 25, 2006 I think you're going about this wrong. If this is for verification, you need to put your processing part above the form in case the processing fails and you need to show the form again. Also, I'm not sure why you want to change the $_POST value. That's not going to do much good for you. Quote Link to comment https://forums.phpfreaks.com/topic/22023-change-_post/#findComment-98491 Share on other sites More sharing options...
berilac Posted September 25, 2006 Author Share Posted September 25, 2006 thank you to both of you.Like i said, i am extremely new to php and basically used some tutorials to help build a kind of test website. I then alter the code as much as i can to make it work for me as well as learn to understand it...i will try to implement a session varaible instead. Sounds a much better option, one i hadnt explored as i was using the knowledge id gained thus far... Quote Link to comment https://forums.phpfreaks.com/topic/22023-change-_post/#findComment-98496 Share on other sites More sharing options...
berilac Posted September 25, 2006 Author Share Posted September 25, 2006 tried it and it works but it doesnt reset the session variable i dont think, as when you click refresh, it shows the error check messages... Quote Link to comment https://forums.phpfreaks.com/topic/22023-change-_post/#findComment-98501 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.