php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30771 Header Problem in PHP when submitting a form
Submitted: 2004-11-13 08:53 UTC Modified: 2004-11-15 08:18 UTC
From: renjuchacko at sify dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.9 OS: Windows 2000 Professional
Private report: No CVE-ID: None
 [2004-11-13 08:53 UTC] renjuchacko at sify dot com
Description:
------------
I have coded a page in php to add/edit/delete some values. The three actions are checked with the help of get variables.

The problem is when i submit the page once, the values are getting entered to the database twice. That is, two records are created with the same values.

I am using a header("location: ...") function to the same page with change in the query string. 

I have watched that the same location (as when adding) is retained and getting submitted even if i had coded for a change in location using header function.

The interesting thing is that this not happening always. Sometimes it works correctly. Many of my friends had the same issues and i was totally stuck with the problem.

Please help me out on this issue.

Reproduce code:
---------------
Create a page which have the codes of insert, update, delete with actions distinguished by the querystring values like add=yes, update=yes, delete=yes

These values are checked like

if (isset($HTTP_GET_VARS["add"]) && $HTTP_GET_VARS["add"]=="yes")

When i click on the add button, i have written a javascript to submit the page, which will be like

pagename.php?add=yes

after the insert query is executed, the next statement is to call the same page with different querystring values. This will be like

header("location: pagename.php?id=newidcreated");
exit();

Expected result:
----------------
Only a single entry is to be made to the table.

Actual result:
--------------
Sometimes the data is submitted twice and two entries with the same details are getting posted to the table, which leads to duplicate values.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-15 08:10 UTC] renjuchacko at sify dot com
I got this problem solved.

I was using javascript function for submitting the form. That is, i was calling the javascript function on button click. This was causing the problem. Now i have changed, and set the action attribute of the form tag. Now this works fine.

Thank You.
 [2004-11-15 08:18 UTC] tony2001@php.net
No bug here -> bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 22:01:28 2024 UTC