jasonc Posted June 7, 2011 Share Posted June 7, 2011 For some reason the value in the input field says at 1 what am i doing wrong that is preventing this from working ? <? // count number of submit attemps before all fields were filled out correctly. if (isset($_POST['postCounter'])) { $postCounter = intval($_POST['postCounter']) + 1; } else { $postCounter = 1; }?> <input name="postCounter" value="<? echo($postCounter); ?>" type="hidden"> Quote Link to comment https://forums.phpfreaks.com/topic/238659-unable-to-get-number-value-from-string/ Share on other sites More sharing options...
dragon_sa Posted June 7, 2011 Share Posted June 7, 2011 should be like this <input name="postCounter" value="<? echo $postCounter; ?>" type="hidden"> Quote Link to comment https://forums.phpfreaks.com/topic/238659-unable-to-get-number-value-from-string/#findComment-1226442 Share on other sites More sharing options...
PFMaBiSmAd Posted June 7, 2011 Share Posted June 7, 2011 Your posted code works correctly for me (edit due to dragon_sa's post: the () on an echo statement are optional and don't affect the operation.) Is that code part of a form? Are you overwriting the $postCounter or $_POST['postCounter'] variable somewhere else in your code? Do you have more than one form field named 'postCounter'? Just posting a few lines of your code out of context doesn't help any one to help you because it doesn't show how you are using the code or what else you might be doing in the code up to that point that could affect the value. Quote Link to comment https://forums.phpfreaks.com/topic/238659-unable-to-get-number-value-from-string/#findComment-1226444 Share on other sites More sharing options...
jasonc Posted June 8, 2011 Author Share Posted June 8, 2011 As far as I know there are no other fields with a name like it, as to be sure I renamed it postCounter and even save it the name 'joebloggs' ! both time it does the same thing. I then placed the echo line to show me the content if the POST cvariable and it again shows me the correct value going up by one each time i click submit and miss filling out a needed field. But the counter field does not update with or without the brackets in the echo line. Quote Link to comment https://forums.phpfreaks.com/topic/238659-unable-to-get-number-value-from-string/#findComment-1226796 Share on other sites More sharing options...
Pikachu2000 Posted June 8, 2011 Share Posted June 8, 2011 Are you successfully using short <? open tags elsewhere in your scripts? They really should be full <?php syntax anyhow. <input name="postCounter" value="<? echo($postCounter); ?>" type="hidden"> Quote Link to comment https://forums.phpfreaks.com/topic/238659-unable-to-get-number-value-from-string/#findComment-1226799 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.