Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Processing data before calling next script

Posted on 2004-09-23
9
Medium Priority
?
231 Views
Last Modified: 2008-03-06
I'm writing a short application which saves data to a database and then retrieves it.

What I want to do is list the data based on certain criteria. So I have a form which asks certain questions. What I want to do is to take the input data from these questions and process it before calling the script which generates the list. The only way I can see of doing this is to have an intermediate form which does the processing and then sets some hidden variables before calling the listing script. However this form must then have its own submit button, an unecessary step for the user.

Is there any way of automatically submitting a form, without user interaction, or is there a better way of doing this.

Thanks
0
Comment
Question by:glassd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 12131519
Isn't it more logical to separate the writing from the reading essentialy? Otherwise people - just because they do - hit the F5/refresh to update your listview, adding data to your db, because they don't remember they did input some data to store earlier.

-r-
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12131555
This is one method, not necessarily the best because it requires using the query string but it should work for you:

point your form to process.php (ie the action) for example, process.php will look like this:

$data = $_POST['input_name']; //do this for each
$data2 = $_POST['input_name2'];

$query = mysql_query ("INSERT INTO tablename (filedname,fieldname,etc) VALUES ('$data','$data2','etc')") or die (mysql_error());

header ("location: page.php?var1=$data&var2=$data2");
exit;

This page will process the sent form data, run the query (all of which you will have to modify to work for your system) then redirects the header back to your page which you want to run the select query on (in the example - page.php).

On the select query page you can get the values using

$data1 = $_GET['var1'];
$data2 = $_GET['var2'];

and so on for as many is needed, you can then plug these variables into the query, for example:

$query = "SELECT * FROM tablename WHERE somefield = '$data1' AND anotherfield = '$data2'";
0
 
LVL 7

Author Comment

by:glassd
ID: 12131578
Sorry, slight misunderstanding. This process formats data input by the user and then generates a list based on that data. There is no write to the database.

PS. I manage the F5 problem using cookies.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:glassd
ID: 12131614
Okay, more information.

My listing script looks something like this:

$Result = mysql_query("select column from table $Search;");

I take the user selection from the input form and process it with the intermediate form, coming up with a string which looks something like this:
' where column = "value" '
which is then passed on to the listing script.

which is then passed to the listing. This means I can use different input forms for different purposes and they will generate the search ctring. Or I can call the listing script directly and get everything.
0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 1000 total points
ID: 12131620
Sorry your first line in the question threw me, nonetheless you should still be able to employ the same method:

$data = $_POST['input_name']; //do this for each
$data2 = $_POST['input_name2'];
//process the data here
header ("location: page.php?var1=$data&var2=$data2");
exit;

Then for the header line you can add the output of your processing script to the query string and access the values on page.php using $_GET['varname'] as shown above.

Failing that, back to basics

>> Is there any way of automatically submitting a form, without user interaction

You can use <body onLoad="document.forms.form_name.submit();">
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12131626
Posted above before your follow up comment, il come back to this in a minute if necessary, have to point my attention to something else for a moment.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12131998
Ok, another method which may be more useful to you is using sessions. The session data will be globally available around your site all the time the session is active so it will mean you will not need to submit form data any more times then is necessary.

session_start(); //top of each page that uses the session data

$_SESSION['var_name'] = "value";

When form data is posted for the first time you can assign it to a session variable so that it is available throughout your scripts from that point fourth, you can also assign any data that is outputted as a result of processing to a sesson variable

$_SESSION['variable'] = $_POST['variable'];

You can then use that data anywhere using $_SESSION['variable'] as long as session_start(); is at the top of the page.

If you have processing occuring on seperate pages you can also use the header redirect - header("location: page.php"); - where needed.
0
 
LVL 7

Author Comment

by:glassd
ID: 12168022
Thanks for the advice.

I used the
header ("location: page.php?var1=$data&var2=$data2");
method and that works fine for what I am doing.

I also had huge problems dealing with strings containing single and double quotes, especially passing them between scripts with the
<input type=hidden ... >
method. The session variable method worked well.

Cheers
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12168044
no problem :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question