0

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
:)

}

please help me out...

4
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by jacksantho
0

Your page should 'refresh' on the post to php_self.
Post your full page, maybe I can help you.

0

post code between [code=language]code [/code] tags, adds highlights, makes errors visible,, eg [code=php]<?php echo phpinfo(); ?> [/code] creates this

<?php echo phpinfo(); ?>

the page is refreshed, its just the code used does not display the $_post values anywhere

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)");

wrong use of quotes breaks echo at the first value
corrected some

echo "<form method='post' action='$_SERVER['PHP_SELF']'>"; 
// quotes corrected, action value quoted, php_self is deprecated correct form used
.if(isset($_POST['hey'])) {echo "<br>$dispayed_colname:<br><input type='text' name='hey' value='$_POST{'hey']' size='40'>";}
else echo "<br>$dispayed_colname:<br><input type='text' name='hey' value='' size='40'>";} 
// corrected case, quotes, displayed updated value in input (there are shorter this is the one I thought first)
echo "<p><input type='submit' name='submit' value='submit'></form>";
if($_POST['submit']){ $sql=mysql_query("INSERT INTO $tabname cols_to_insert) VALUES ($_post['hey'])"; } 
//closed the braces, removed deprecated variable

I just got sick of making changes,
suggest get a code highlighting editor like notepad2 notepad++ (hundreds of them) and errors like these will be evident in the code as you write it
and easily corrected

Edited by almostbob: n/a

-1

Use something like this:

<?php

if(!$_POST) {

	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>";
} else {
	$sql = mysql_query("INSERT INTO $tabname($cols_to_insert)". "VALUES($hey)");
	Header("Location: $php_self");
}

?>

Obviously I don't know what your variables are set at so I dont know it if will work.

Votes + Comments
corrected code is wrong
0

Hi,
I got working it. I just copied and pasted my code at the top of the page. It's working finely. I got refreshed page.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.