Page 1 of 1

Pass Query result to another page

Posted: Tue Mar 20, 2012 10:25 pm
by kat5252
Hi guys, I'm very very new to Php so forgive me if this problem I have would be a piece of cake to all of you. I badly need your help!
There are still a lot of functions and even terms that I am not familiar with but I'm trying hard to learn a little everyday.

I have created a simple webpage where I can input data and save it to my database.
I have also created this code that retrieves the value from my database and displays the results in a table.
Here's the code I used to retrieve data from the database.
Image

Here's an illustration on how the data are displayed when I access the page.
Image

There's a "SUBMIT" and a "DELETE" button. What I want when I click the Submit button is to display the result("1", "AAA", and "0000") in another page that would allow me to modify the values. That would make the submit button function as EDIT, so maybe I'll just rename it to "EDIT" later.
Or the result should look at least like this in the new page:

Fund Type: 1
Fund Name: 2
Base Price: 0000

I've tried the simple POST and GET method. It worked because I followed a sample from the web where I input a data and it is automatically displayed on the other page when I hit the submit button. But I can't make it work with displaying this data that were just retrieved from the database.

Any help and suggestions would be greatly appreciated.

Re: Pass Query result to another page

Posted: Fri Mar 23, 2012 4:59 pm
by mecha_godzilla
Hi,

You need to include a form value relating to the button you're clicking on - at the moment your form code is missing this value and you would need to add something like this:

Code: Select all

echo '<input type="hidden" name="my_value" value="' . $row['some_field_in_your_database'] . '" />';
This code should ideally go just after the first <form> tag. You can also add the information like this:

Code: Select all

echo '<form name="myform" action="file2.php?my_value=' . $row['some_field_in_your_database'] . '" method="post">';
and you don't need to add the extra input tag. This also works if you want to create a link to your script without using forms all the time:

Code: Select all

echo '<a href="file2.php?my_value=' . $row['some_field_in_your_database'] . '" target="_self">Click here</a>';
To capture this value in the script that receives it you then need to use something like this:

Code: Select all

$my_value = $_POST['my_value'];
or

Code: Select all

$my_value = $_GET['my_value'];
depending on which form method you're using - if in doubt, try both! If you don't already know about this, make sure you understand what the difference is between using single and double quotes in your code because PHP treats them differently - the way I used is a bit less intuitive but it makes it clearer in the script what's going on, particularly if your text editor has syntax highlighting.

If you need any more help please say so.

Mecha Godzilla