In this code everything is working fine it take user name from session and insert data perfectly via radio button, only problem is it automatically insert data again when I reload the page.
if(isset($_SESSION['user_id'])&&isset($_POST['r1'])&&isset($_POST['r2'])&&isset($_POST['r3'])&&isset($_POST['r4'])&&isset($_POST['suggestion'])&&isset($_POST['submit'])){
$user=$_SESSION['user_id'];
$r1=$_POST['r1'];
$r2=$_POST['r2'];
$r3=$_POST['r3'];
$r4=$_POST['r4'];
$suggestion=$_POST['suggestion'];
$query_insert="INSERT INTO `wp_feedback` VALUES ('".$user."','".$r1."','".$r2."','".$r3."','".$r4."','".$suggestion."')";
if($query_run=mysql_query($query_insert)){
echo "alright";
}
else {
echo "not inserted";
}
}
Thanks in advance.
Please try it,
if(isset($_SESSION['user_id'])&&isset($_POST['r1'])&&isset($_POST['r2'])&&isset($_POST['r3'])&&isset($_POST['r4'])&&isset($_POST['suggestion'])&&isset($_POST['submit']))
{
$user=$_SESSION['user_id'];
$r1=$_POST['r1'];
$r2=$_POST['r2'];
$r3=$_POST['r3'];
$r4=$_POST['r4'];
$suggestion=$_POST['suggestion'];
$query_insert="INSERT INTO wp_feedback VALUES ('".$user."','".$r1."','".$r2."','".$r3."','".$r4."','".$suggestion."')";
if(isset($_POST['submit']))
{
if($query_run=mysql_query($query_insert))
{
echo "alright";
header('Location:setlocation.php');
}
else
{
echo "not inserted";
}
}
}
set header location after insert query...
Put a redirection at the buttom of your script because i think reloading the page still execute your form submission
if(isset($_SESSION['user_id'])&&isset($_POST['r1'])&&isset($_POST['r2'])&&isset($_POST['r3'])&&isset($_POST['r4'])&&isset($_POST['suggestion'])&&isset($_POST['submit'])){
$user=$_SESSION['user_id'];
$r1=$_POST['r1'];
$r2=$_POST['r2'];
$r3=$_POST['r3'];
$r4=$_POST['r4'];
$suggestion=$_POST['suggestion'];
$query_insert="INSERT INTO `wp_feedback` VALUES ('".$user."','".$r1."','".$r2."','".$r3."','".$r4."','".$suggestion."')";
if($query_run=mysql_query($query_insert)){
echo "alright";
}
else {
echo "not inserted";
}
header('Location: redirect url');
}
if(isset($_SESSION['user_id'])&&isset($_POST['r1'])&&isset($_POST['r2'])&&isset($_POST['r3'])&&isset($_POST['r4'])&&isset($_POST['suggestion'])&&isset($_POST['submit'])){
$user=$_SESSION['user_id'];
$r1=$_POST['r1'];
$r2=$_POST['r2'];
$r3=$_POST['r3'];
$r4=$_POST['r4'];
$suggestion=$_POST['suggestion'];
$query_insert="INSERT INTO `wp_feedback` VALUES ('".$user."','".$r1."','".$r2."','".$r3."','".$r4."','".$suggestion."')";
if($query_run=mysql_query($query_insert)){
echo "alright";
header("Location:someurl");//This will redirect into some other pages and solve your problem
}
else {
echo "not inserted";
}
}
if(isset($_SESSION['user_id'])&&isset($_POST['r1'])&&isset($_POST['r2'])&&isset($_POST['r3'])&&isset($_POST['r4'])&&isset($_POST['suggestion'])&&isset($_POST['submit'])){
$user=$_SESSION['user_id'];
$r1=$_POST['r1'];
$r2=$_POST['r2'];
$r3=$_POST['r3'];
$r4=$_POST['r4'];
$suggestion=$_POST['suggestion'];
$query_insert="INSERT INTO `wp_feedback` VALUES ('".$user."','".$r1."','".$r2."','".$r3."','".$r4."','".$suggestion."')";
if($query_run=mysql_query($query_insert)){
echo "alright";
}
else {
echo "not inserted";
}
header('Location:yourpage.php');
}