473,612 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

refresh on submit

I have a php script with a form that insert data in a mysql db and
when I click on submit I would like the page to refresh after the
insertion, how can I do that? it's a php script that display data from
a mysql db, and the submit button modify the content of the page yet I
need to manually refresh to see the result of my insertion.

it kinda looks like this:

echo "<form method=\"post\" action=$php_sel f>";
echo "<br>$dispayed_ colname:<BR><IN PUT TYPE=\"TEXT\" NAME=\"hey\"
SIZE=\"40\">";

echo "<p><input type=\"submit\" name=\"submit_t he_values\"
value=\"$submit \">
</form>";

if($submit_the_ values){
$sql=mysql_quer y("INSERT INTO $tabname($cols_ to_insert)". "VALUES
($hey)");

//I would like to refresh $php_self here, please tell me if you know
:)

}

thanx in advance

Pat
Jul 17 '05 #1
7 27610
<ki*********@ya hoo.com> wrote in message
news:39******** *************** ***@posting.goo gle.com...
I have a php script with a form that insert data in a mysql db and
when I click on submit I would like the page to refresh after the
insertion, how can I do that? it's a php script that display data from
a mysql db, and the submit button modify the content of the page yet I
need to manually refresh to see the result of my insertion.

it kinda looks like this:

echo "<form method=\"post\" action=$php_sel f>";
echo "<br>$dispayed_ colname:<BR><IN PUT TYPE=\"TEXT\" NAME=\"hey\"
SIZE=\"40\">";

echo "<p><input type=\"submit\" name=\"submit_t he_values\"
value=\"$submit \">
</form>";

if($submit_the_ values){
$sql=mysql_quer y("INSERT INTO $tabname($cols_ to_insert)". "VALUES
($hey)");

//I would like to refresh $php_self here, please tell me if you know
:)

}


You could move the query code to the top of the page so that the insertion
would already be done by the time the data is displayed:

<?php

if($submit_the_ values){
$sql=mysql_quer y("INSERT INTO $tabname($cols_ to_insert)". "VALUES
($hey)");
}

// ... other stuff

?>

If, for some reason, this isn't satisfactory, you can refresh with this
line:

header("Locatio n: ".$_SERVER["PHP_SELF"]);

Chris Finke

--
I'll send you a gMail invite if you sign up for a free iPod and complete an
offer:
http://www.freeiPods.com/default.aspx?referer=9228418
Jul 17 '05 #2
.oO(ki********* @yahoo.com)

Just some hints:
echo "<form method=\"post\" action=$php_sel f>";


If you want your script to run on all servers you should read the manual
about register_global s.

Chapter 27. Using Register Globals
http://www.php.net/manual/en/security.globals.php

register_global s
http://www.php.net/manual/en/ini.sec...gister-globals

Additionally HTML also allows single quotes around attribute values,
this avoids ugly escaping:

echo "<form method='post' action='$_SERVE R[PHP_SELF]'>";

Micha
Jul 17 '05 #3
Michael Fesser <ne*****@gmx.ne t> wrote:
echo "<form method='post' action='$_SERVE R[PHP_SELF]'>";


If you are trying to advocate good practice, please don't write sloppy
code :)

echo "<form method='post' action='{$_SERV ER["PHP_SELF"]}'>";

E_ALL should be the default on development machines when it comes to
error reporting :)

--

Daniel Tryba

Jul 17 '05 #4
.oO(Daniel Tryba)
Michael Fesser <ne*****@gmx.ne t> wrote:
echo "<form method='post' action='$_SERVE R[PHP_SELF]'>";
If you are trying to advocate good practice, please don't write sloppy
code :)


The above is correct (simple) syntax. Really. ;)

(The assoc. array is accessed directly from inside the string, quoting
the index would cause a parse error.)
echo "<form method='post' action='{$_SERV ER["PHP_SELF"]}'>";
This is correct either (complex/curly syntax).

(In this case the curly braces are kind of an escaping mechanism to
allow more complex expressions, one could say the array is accessed
outside the string and hence needs quotes around the index.)
E_ALL should be the default on development machines when it comes to
error reporting :)


Full ACK

And believe me, this is one of the first settings I change after an
initial PHP installation on a dev-machine.

Micha
Jul 17 '05 #5
Michael Fesser <ne*****@gmx.ne t> wrote:
echo "<form method='post' action='$_SERVE R[PHP_SELF]'>";


If you are trying to advocate good practice, please don't write sloppy
code :)


The above is correct (simple) syntax. Really. ;)

(The assoc. array is accessed directly from inside the string, quoting
the index would cause a parse error.)


Note to self, test before port next time :)

--

Daniel Tryba

Jul 17 '05 #6
I tried to use "header("Locati on: ".$_SERVER["PHP_SELF"]);" but I get
an error telling that the header has already been sent before at a
line where I use an echo "something"

"Christophe r Finke" <cf****@gmail.c om> wrote in message news:<2r******* ******@uni-berlin.de>...
<ki*********@ya hoo.com> wrote in message
news:39******** *************** ***@posting.goo gle.com...
I have a php script with a form that insert data in a mysql db and
when I click on submit I would like the page to refresh after the
insertion, how can I do that? it's a php script that display data from
a mysql db, and the submit button modify the content of the page yet I
need to manually refresh to see the result of my insertion.

it kinda looks like this:

echo "<form method=\"post\" action=$php_sel f>";
echo "<br>$dispayed_ colname:<BR><IN PUT TYPE=\"TEXT\" NAME=\"hey\"
SIZE=\"40\">";

echo "<p><input type=\"submit\" name=\"submit_t he_values\"
value=\"$submit \">
</form>";

if($submit_the_ values){
$sql=mysql_quer y("INSERT INTO $tabname($cols_ to_insert)". "VALUES
($hey)");

//I would like to refresh $php_self here, please tell me if you know
:)

}


You could move the query code to the top of the page so that the insertion
would already be done by the time the data is displayed:

<?php

if($submit_the_ values){
$sql=mysql_quer y("INSERT INTO $tabname($cols_ to_insert)". "VALUES
($hey)");
}

// ... other stuff

?>

If, for some reason, this isn't satisfactory, you can refresh with this
line:

header("Locatio n: ".$_SERVER["PHP_SELF"]);

Chris Finke

Jul 17 '05 #7
<ki*********@ya hoo.com> wrote:
I tried to use "header("Locati on: ".$_SERVER["PHP_SELF"]);" but I get
an error telling that the header has already been sent before at a
line where I use an echo "something"

"Christophe r Finke" <cf****@gmail.c om> wrote in message news:<2r******* ******@uni-berlin.de>...
<ki*********@ya hoo.com> wrote in message
news:39******** *************** ***@posting.goo gle.com...
I have a php script with a form that insert data in a mysql db and
when I click on submit I would like the page to refresh after the
insertion, how can I do that? it's a php script that display data from
a mysql db, and the submit button modify the content of the page yet I
need to manually refresh to see the result of my insertion.

it kinda looks like this:

echo "<form method=\"post\" action=$php_sel f>";
echo "<br>$dispayed_ colname:<BR><IN PUT TYPE=\"TEXT\" NAME=\"hey\"
SIZE=\"40\">";

echo "<p><input type=\"submit\" name=\"submit_t he_values\"
value=\"$submit \">
</form>";

if($submit_the_ values){
$sql=mysql_quer y("INSERT INTO $tabname($cols_ to_insert)". "VALUES
($hey)");

//I would like to refresh $php_self here, please tell me if you know
:)

}


You could move the query code to the top of the page so that the insertion
would already be done by the time the data is displayed:

<?php

if($submit_the_ values){
$sql=mysql_quer y("INSERT INTO $tabname($cols_ to_insert)". "VALUES
($hey)");
}

// ... other stuff

?>

If, for some reason, this isn't satisfactory, you can refresh with this
line:

header("Locatio n: ".$_SERVER["PHP_SELF"]);

Chris Finke


1.: According to the RFC, the Location:-Header *has* to be an abolute URL.
2.: Replace header() with print() and look into the generated HTML. While
there are *any* characters in the file before the Location:-part, you have
to move your code upwards in your .php.
An HTTP-response looks like this:
-----BEGIN HTTP BLOCK-----
1: HTTP/1.1 200 OK
2: Content-Type: text/plain
3: Content-Encoding: foo
4:
5: hey, i am the content of the sent text file!
------END HTTP BLOCK------

Line 1-3 are the HTTP header (yes, exactly as in "header()") , followed by
an empty line, followed by the body (on View > Sourcecode, you are only
shown the body).
If output buffering is turned off, PHP will send the prepared headers and
the empty line to the client and starts sending the body, as soon as there
is any data outside of a <?php...?>-block or any output within a php-block
(no matter, whether it's echo, var_dump or a parse error).
As soon as the empty line is sent out, you can *never* get back into the
header area to add something you forgot. It's like saying hurting words to
a loved one: You want to undo it, but no matter how hard you wish or try,
it's impossible to make it undone.
Ok... sorry, back to topic :)
If you want to send headers, you have to put them at the very beginning of
you script. If you have to validate data and while doing that generating
output, instead of just echoing this output write it into a variable and
echo the variable at the correct location.

HTH
Simon
--
Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4911
by: Mark | last post by:
I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this: if (isset($_POST)) { if ($_POST == "") { include ("InsertRecord.inc"); // Insert new record }
4
5488
by: Noel Wood | last post by:
Hello, I have a problem that I'm sure is simple but I have searched the newsgroup and have not found it posted before so I apologize if it has been asked heaps of times before. I have a page that list all current orders from customers. Customers can order at any time. I have a checkbox beside each listing so that as each order is complete it can be ticked off. I want the page to refresh every 2 mins so I have added .... <meta...
6
3322
by: laura | last post by:
I'm doing a page which gathers some text in the form of a text box in a <form>. This text is saved to a text file, notices.txt and I want to be able to display the saved text on the page, as soon as they click the SUBMIT button - is this possible? At the moment I have a hyperlink called "back" which, once they have entered the text and they click SUBMIT, the "back" hyperlink will refresh the page and it displays the newly entered text....
1
1428
by: kindermaxiz | last post by:
I have a php script with a form that insert data in a mysql db and when I click on submit I would like the page to refresh after the insertion, how can I do that? it's a php script that display data from a mysql db, and the submit button modify the content of the page yet I need to manually refresh to see the result of my insertion. it kinda looks like this: echo "<form method=\"post\" action=$php_self>"; echo...
1
5964
by: tony wong | last post by:
the page has upper frame (submit record) and lower frame (show records). i wish to refresh lower frame once submit record at upper frame. i try this, it works to refresh the lower frame function ABC() { window.parent.mainFrame.location.reload();} <input type="button" value="refresh" onclick="return ABC()"></TD>
10
9236
by: tasmisr | last post by:
This is an old problem,, but I never had it so bad like this before,, the events are refiring when clicking the Browser refresh button. In the Submit button in my webform, I capture the server side click event and I update session information to track the visibilty of some panels in a wizard type navigation ("Next >>" and "<< Back" buttons).. but the refresh button makes another event firing and takes the whole thing to a Choes.. ...
1
2705
by: Ibrahim. | last post by:
Hi, I have a login page, the problem I'm facing is like this; 1. Login page with submit button (being default button); 2. When first time the page is submitted then submit code is called. 3. Again when page refresh is done by (f5) then submit button is fired implicitly.
2
2824
by: entfred | last post by:
I was experimenting with trying to select the same item in a select box twice in a row and found out that you need to do a refresh (view - refresh) in Internet Explorer. This is so you can click on the same item twice "in a row" to select it. Does anyone know how to automatically make a web page do a refresh when the web page loads? This would prevent the user from having to do the refresh, themselves.
11
12988
by: gotonagle | last post by:
hi, can some help me in this regard i m entering some values in my databse from my asp page. for this i m using a submit button which submit the form to a new page that is 'insert.asp'. this page perform insertion and redirect it back to my previos page. can i not do this insertion on the same page? if i wirte insertin code on the same page it perform insertion for the page refresh also...thats why i m using another page(some people says...
0
8105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8246
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8415
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6076
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5532
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4109
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1413
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.