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

  • Home
  • SEARCH
  • 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 8115487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:29:50+00:00 2026-06-06T03:29:50+00:00

I am creating an insert process in php but I have a problem in

  • 0

I am creating an insert process in php but I have a problem in my code. when I refresh my page, it will also submit and insert the data.

here is my code :

<form action="/drupal/node/1" method="post">
Name: <input type="text" name="name" />
Price: <input type="text" name="price" />
Minutes: <input type="text" name="minutes" />
<input type="submit" />
</form>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code
mysql_select_db("zain", $con);
if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['minutes']))
{
 $val_name = $_POST['name'];
 $val_price = $_POST['price'];
 $val_min = $_POST['minutes'];
 $max_id_sql = mysql_query("SELECT MAX(id) FROM card_category");
 $data = mysql_fetch_array($max_id_sql);
 if ($data[0]==0)
 {
    $val_id = 1;
 }
 else
 {
    $val_id = $data[0] + 1;
 }

 mysql_query("INSERT INTO card_category (id, name, price, minutes) VALUES ($val_id,'$val_name',$val_price,$val_min )");
 $_POST['name'] == NULL;
 $_POST['price'] == NULL;
 $_POST['minutes'] == NULL;
}
$result = mysql_query("SELECT * FROM card_category");

echo "<table border='1'>
<tr>
<th>id</th>
<th>name</th>
<th>price</th>
<th>mins</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
  echo "<td>" . $row['minutes'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
if (isset($_POST['lastname']))
{
print $_POST['lastname'];
}
mysql_close($con);
?>

my question is, how can I handle when I refresh the page and it will not submit the data?

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-06T03:29:51+00:00Added an answer on June 6, 2026 at 3:29 am

    When you get the POST submission:

    1. Process the data
    2. Return a Redirect response
    3. Get a GET request from the browser on the URL you redirect to
    4. Respond to that with the HTML

    If the browser is refreshed, it will resubmit the GET request which your PHP won’t use to modify the database.

    This is the POST-REDIRECT-GET pattern. There are some more details in this blog entry (which also has example PHP code in the comments).

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

Sidebar

Related Questions

i am using this code to insert names to table,i have a problem that
Creating an Iphone application, I used to perform INSERT QUERY on different databases. But
Basically I need to insert a bunch of data to an Excel file. Creating
I have a nightly SSIS process that exports a TON of data from an
I have a large amount of data files to process and to be stored
I'm creating a application that will fetch data from an SQLite database and display
I'm creating a trigger in SQL Server after INSERT, UPDATE and DELETE. Is there
is it possible to insert an object into a session instead of creating a
After creating a table (by migration), I want to insert some entries directly. How
I am just simply creating a web application. I wanted to insert a line

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.