I have a post a comment code that validates input but submits on page refresh. so i added session unique id to the form validation. but it won't let me post on any of the detail.php pages after i have posted on one(detail.php is a dynamic page that gets the records from my db) for example
www.mylink.com/detail.php?vtopic= 78 - this allows me to post on the article on 78
www.mylink.com/detail.php?vtopic= 79- doesn't allow me.
On my form page i already have a variable that gets vtopic
$p_name = $_GET and puts in my db.
So is there a way so that the session nows the $p_name so that it stop me commenting on other articles on the detail.php
todo is the hidden field, auto increment.

$todo = uniqid();
$_SESSION['todo'] = $todo;

$todo=$_POST['todo'];
if(empty($_POST['todo'])
      or empty($_SESSION['todo'])
      or $_POST['todo'] != $_SESSION['todo'])
   {
      echo " you have submitted form";
   } 


else{
validate form
}

Any help will be appreciated
or tell me a better way to stop form submission on refresh

Member Avatar for diafol

Ensure that you send form to a different page (e.g. formhandler.php) - it's not a good idea to send forms to the same page anyway.

form.php (fill data/submit) -> formhandler.php (process data and return) -> form.php

Ensure that you send form to a different page (e.g. formhandler.php) - it's not a good idea to send forms to the same page anyway.

form.php (fill data/submit) -> formhandler.php (process data and return) -> form.php

Thanks, done it works now,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.