Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8611547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:24:13+00:00 2026-06-12T04:24:13+00:00

I have a simple coding problem. I try to create a page with a

  • 0

I have a simple coding problem. I try to create a page with a textbox and a share button.

When the user clicks the share button the text in the textbox get inserted as string into the database table named “posts”.

I use the following code.

<?php
    if(isset($_POST['share']))
    {
            $status = $_POST['status'];
            $res = mysql_query("insert into `posts`(postid,username,post,pointscollected) values('','$username','$status','')");
            if($res)
                echo "<script type='text/javascript'>alert('Posted successfully')</script>";
            else
                echo "<script type='text/javascript'>alert('some error')</script>";
    }
    else
    {
        ?>
            <form action="<?php $_SERVER['PHP_SELF']?>" method="post">
            Status : <input type = "text" name ="status">
            <input type = "submit" name ="share">
            </form>
        <?php
    }

This solution works fine but there is a problem when the user refreshes the page. The browser will show a message window asking for resend the information, which will submit the post to the table again. Then the same entry is in the table twice.

I want the user to stay on the same page after submitting. But a page refresh should not show the message window or send the information again.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:24:14+00:00Added an answer on June 12, 2026 at 4:24 am

    Redirect the user after he shares, use redirect

    header('Location: whatever.php');
    exit;
    

    Use this :

    <?php
    if(isset($_POST['share'])) {
          $status = $_POST['status'];
          $res = mysql_query("insert into `posts`(postid,username,post,pointscollected) values('','$username','$status','')");
          if($res) {
          ?>
              <script type='text/javascript'>alert('Posted successfully')</script>
          <?php              
              header('Location: whatever.php');
              exit;
            } else {
             ?>
              <script type='text/javascript'>alert('some error')</script>
           <?php
              header('Location: whatever.php');
              exit;
             }
        }
     ?>
    

    And btw better don’t alert the users using javascript

    AND DO USE BRACES AROUND IF ELSE

    P.S : You Can Also Redirect An User Using JavaScript window.location

    Header Reference

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have a coding/maths problem that I need help translating into C#. It's a
I'm coding a simple SDL program with VC10. The problem that I am having
I am faced with a problem coding my next feature. I want the user
I have developed a simple Cake application and after finishing coding of it, I
i have simple tr an td's coming from database <tr> <td > <td style=
I have simple class with width and height member fields which define number of
I have simple php validation form that is halfway working. If you leave the
I have simple JavaScript snippet: var obrazek = [{nazwa: "Sniadanie", wiek: 100, autor: "Alicja"},{nazwa:
I have simple script with EventMachine, Fibers and faye require faye require em-synchrony require

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.