Jump to content

Recommended Posts

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">

Link to comment
https://forums.phpfreaks.com/topic/238659-unable-to-get-number-value-from-string/
Share on other sites

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.

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.

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">

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.