473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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_self>";
echo "<br>$dispayed_colname:<BR><INPUT TYPE=\"TEXT\" NAME=\"hey\"
SIZE=\"40\">";

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

if($submit_the_values){
$sql=mysql_query("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 27595
<ki*********@yahoo.com> wrote in message
news:39**************************@posting.google.c om...
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 "<br>$dispayed_colname:<BR><INPUT TYPE=\"TEXT\" NAME=\"hey\"
SIZE=\"40\">";

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

if($submit_the_values){
$sql=mysql_query("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_query("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("Location: ".$_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_self>";


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

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

register_globals
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='$_SERVER[PHP_SELF]'>";

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


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

echo "<form method='post' action='{$_SERVER["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.net> wrote:
echo "<form method='post' action='$_SERVER[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='{$_SERVER["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.net> wrote:
echo "<form method='post' action='$_SERVER[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("Location: ".$_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"

"Christopher Finke" <cf****@gmail.com> wrote in message news:<2r*************@uni-berlin.de>...
<ki*********@yahoo.com> wrote in message
news:39**************************@posting.google.c om...
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 "<br>$dispayed_colname:<BR><INPUT TYPE=\"TEXT\" NAME=\"hey\"
SIZE=\"40\">";

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

if($submit_the_values){
$sql=mysql_query("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_query("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("Location: ".$_SERVER["PHP_SELF"]);

Chris Finke

Jul 17 '05 #7
<ki*********@yahoo.com> wrote:
I tried to use "header("Location: ".$_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"

"Christopher Finke" <cf****@gmail.com> wrote in message news:<2r*************@uni-berlin.de>...
<ki*********@yahoo.com> wrote in message
news:39**************************@posting.google.c om...
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 "<br>$dispayed_colname:<BR><INPUT TYPE=\"TEXT\" NAME=\"hey\"
SIZE=\"40\">";

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

if($submit_the_values){
$sql=mysql_query("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_query("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("Location: ".$_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.net> <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
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 ==...
4
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...
6
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...
1
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...
1
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...
10
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...
1
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. ...
2
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.