Jump to content

php simple coding help.


Porkie

Recommended Posts

 

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']}'";

?>

$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.

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.