Dear All

I am writing one small web application in PHP. I am trying to save some data which is entered in PLLWINDOW.PHP and when I click on Button Data should be saved in database, my insert into statement is written in SAVE.PHP. After saving the data in database my PLLWINDOW.PHP should be reload and it should display Record 2 on top and blank fields. This has to happen on every click on button.
How can I do this I need guidance.

Use header

header("location:yourpage.php");

Use header

header("location:yourpage.php");

Thanks 4 reply but i have already use header once for a file so please suggest me another way to solve.

Hi,
I am not giving you in details.But I am giving you sudocode to do your code.
1)PLLWINDOW.PHP
<?php
/* Connect to databse*/

/* Retrive your information from databse.If empty i.e. first time dont show anything.If found any record show in whatever format you have
close database connection.
*/


/*Write HTML code i.e. form,text fields,button.
in form action tag<form action="SAVE.php" method="get">...
*/
?>

2)SAVE.php
<?php
/*get data from previous page by using $_GET or $_POST as your action metod and store in a varibles
do input validation if you want
*/
/* Connect to databse*/
/*
write a php code to insert values in a databse.
if everything goes well values will be inserted in a database.
*/

/* Now the time to go again on your PLLWINDOW.php */
header("/location/where/PLLWINDOW.php");
?>

Hi,
I am not giving you in details.But I am giving you sudocode to do your code.
1)PLLWINDOW.PHP
<?php
/* Connect to databse*/

/* Retrive your information from databse.If empty i.e. first time dont show anything.If found any record show in whatever format you have
close database connection.
*/


/*Write HTML code i.e. form,text fields,button.
in form action tag<form action="SAVE.php" method="get">...
*/
?>

2)SAVE.php
<?php
/*get data from previous page by using $_GET or $_POST as your action metod and store in a varibles
do input validation if you want
*/
/* Connect to databse*/
/*
write a php code to insert values in a databse.
if everything goes well values will be inserted in a database.
*/

/* Now the time to go again on your PLLWINDOW.php */
header("/location/where/PLLWINDOW.php");
?>

use javascript

Member Avatar for diafol

I wouldn't use javascript here, unless you need an Ajax solution.

PLLWINDOW.PHP
send form with data via button to SAVE.PHP

SAVE.PHP
1) insert data
2) get id number from newly added record
3) return to PLLWINDOW.PHP with id in querystring for display:

$r=mysql_query("INSERT INTO ....");
//check everything fine then...
$id = mysql_insert_id();
header("Location:http://www.example.com/PPLWINDOW.PHP?id=$id");
exit;

The PLLWINDOW.PHP file should have the following code ABOVE the DTD:

<?php 
if(isset($_GET['id'])){
   $id = intval($_GET['id']);
   $r = mysql_query("SELECT * FROM table WHERE id='$id' ");
   $d = mysql_fetch_array($r);
   $myfield1 = stripslashes($d['myfield1']);
   $myfield2 = stripslashes($d['myfield2']);
//etc - then create a <table> output with these - in variable called $output;
}else{
  $output = "";
}
?>

...rest of page...
<?php echo $output;?>
...rest of page...

hi,
Yes you are right ,javascript can also be used.
I have written solution as per requirement written in the thread.

use javascript code Window.location if it's suites to your code.

Member Avatar for diafol
Thanks 4 reply but i have already use header once for a file so please suggest me another way to solve.

Why?

Why do you want to involve javascript into a starightforward php solution? Doesn't make much sense to me. Unless you're going to use ajax techniques to prevent total page reload?

i replied above, but i think you miss it... here it is

<?php echo "<script>window.location='yourpage.php'</script>"; ?>
Member Avatar for diafol

The only advantage I can see with js (last post example) is that it doesn't worry if there is an error or html output from the db update, which could prevent header() from executing. If js is disabled (unlikely these days - but you never know), you'd be stuck on the formhandler page - which is really not a good thing.

well im just answering his resquest... he want an alternatives of php hearer() function.

Member Avatar for diafol

well im just answering his resquest... he want an alternatives of php hearer() function.

Indeed - and I'm not criticising your post - quite the opposite - good info. I'm just pointing out that php can do all this without the need for js - that was directed at the thread starter, wherever he got to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.