Porkie Posted April 28, 2009 Share Posted April 28, 2009 i just want a simple code that counts everytime the submit button is pressed on my form and displays the number.is this possible? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/ Share on other sites More sharing options...
Zhadus Posted April 28, 2009 Share Posted April 28, 2009 Do you want the number to be stored in a database? Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821376 Share on other sites More sharing options...
Porkie Posted April 28, 2009 Author Share Posted April 28, 2009 doesnt matter just everytime the button is clicked , i want a one to be added to number.database or not Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821401 Share on other sites More sharing options...
redarrow Posted April 28, 2009 Share Posted April 28, 2009 some think like this link. <a href='http://page_one.php?page_name=page_one&page_number=1'>press me</a> ?page_name=page_one&page_number=1 <?php $sql="update page_counter set page_number=page_number+{$_GET['page_number']} WHERE page_name='{$_GET['page_name']}'"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821410 Share on other sites More sharing options...
premiso Posted April 28, 2009 Share Posted April 28, 2009 $file = "submitCount.txt"; if (!file_exists($file)) { $count = 0; }else { $count = file_get_contents($file); } $fh = fopen($file, "w+"); fwrite($fh, ($count + 1)); fclose($fh); Simple as that with a flat file housing the data. You will of course have to put that into an if to check if the form was submitted or not. Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821411 Share on other sites More sharing options...
Porkie Posted April 28, 2009 Author Share Posted April 28, 2009 i have created a file called SubmitCount.txt added the code to my file however i dont get anything displayed and dont know how to link with my submit button ? could you explain please? Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821420 Share on other sites More sharing options...
redarrow Posted April 28, 2009 Share Posted April 28, 2009 you add it, to the page that the user is going to. Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821422 Share on other sites More sharing options...
premiso Posted April 28, 2009 Share Posted April 28, 2009 <?php $file = "submitCount.txt"; $count = (file_exists($file))?file_get_contents($file):0; if (isset($_POST['submit']) { $count++; $fh = fopen($file, "w+"); fwrite($fh, $count); fclose($fh); } ?> Submit Count is now <?php echo $count; ?><br /> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="submit" name="submit" value="Submit!" /> </form> Should add one each time that form is submitted and display the count. Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821424 Share on other sites More sharing options...
Porkie Posted April 28, 2009 Author Share Posted April 28, 2009 if (isset($_POST['submit']) { $count++; Parse error: syntax error, unexpected T_VARIABLE in test1.php on line 6 also how would i link this with my submit form? Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821433 Share on other sites More sharing options...
premiso Posted April 28, 2009 Share Posted April 28, 2009 if (isset($_POST['submit'])) { Sorry, missed an ending ) Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821435 Share on other sites More sharing options...
Porkie Posted April 28, 2009 Author Share Posted April 28, 2009 how can i make this work? <td colspan="4" rowspan="2"><form id="form1" name="form1" method="post" action="Thanks.php""<?php echo $_SERVER['PHP_SELF']; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/156022-php-simple-coding-help/#findComment-821436 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.