bluesteel Posted July 29, 2009 Share Posted July 29, 2009 Hi everyone, I'm new here and desperately need some guidance. Bit of a PHP noob too. Basically what I'm doing is making a site where a form is required to send information to an email address. That part I have working fine but what i need to do is have a reference number included in the email so that every time someone submits the form, the reference number included in the email goes up by one. What I've done is included a hidden text field in the form and set it to 1, but I'm not sure how to increment this in the PHP script. Heres my PHP script so far: <?php //--------------------------Set these paramaters-------------------------- // Subject $subject = 'Quotation Form'; // email address for data to be sent to $emailadd = '[email protected]'; // Where to redirect. $url = 'http://www.derekfordwebdesigns.com/examples/wss/confirm.html'; // Make all fields required. $req = '1'; $text = "Form results:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> <?php $ref=$_POST('$ref')+1; ?> The hidden text field for the reference number in the form looks like this: <input name="ref" type="hidden" id="ref" value="1"/> Please help? Everything works put the increment. When I submit the form, I get the proper result but with the same reference number every time. Sorry for asking what is probably a silly and basic question. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/167977-how-to-increment-hidden-text-field/ Share on other sites More sharing options...
tbare Posted July 29, 2009 Share Posted July 29, 2009 Is it supposed to increment by one for each page hit? if so, the best way to do that is using a Database. PHP (being server-side) has no way of knowing what the last number is, especially if it's hard-coded into the page. Link to comment https://forums.phpfreaks.com/topic/167977-how-to-increment-hidden-text-field/#findComment-885996 Share on other sites More sharing options...
bluesteel Posted July 29, 2009 Author Share Posted July 29, 2009 Well its supposed to increment everytime someone hits the submit button on the form, so that when i get the results in an email, it will have a differant number (ie. the hidden field goes up by one each time.) Thanks for the reply btw Link to comment https://forums.phpfreaks.com/topic/167977-how-to-increment-hidden-text-field/#findComment-886002 Share on other sites More sharing options...
tbare Posted July 29, 2009 Share Posted July 29, 2009 if you don't have a database (such as mysql) what i have done is write a number to a text file, then each time, read the number, increase by one, then over-write the text file w/ a new one containing the new number... worked well w/o a DB Link to comment https://forums.phpfreaks.com/topic/167977-how-to-increment-hidden-text-field/#findComment-886102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.