0

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.

6
Contributors
13
Replies
15
Views
7 Years
Discussion Span
Last Post by diafol
0

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.

0

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

0

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

0

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...
0

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

0
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?

0

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.

0

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.

This topic has been dead for over six months. 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.