472,374 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

pass a $result from a mysql_query in a url

I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$resu lt);

but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];

I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.

I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,
Nov 12 '08 #1
9 2442
JRough wrote:
I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$resu lt);

but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];

I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.

I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,
$result is only a resource - in this case, a reference to data still
stored in MySQL. The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is large).

And BTW - if you're passing the query parms, doing it in the $_SESSION
array is safer than doing it in either $_GET or $_POST.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 12 '08 #2
Jerry Stuckle wrote:
JRough wrote:
>I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$res ult);

but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];

I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.

I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,

$result is only a resource - in this case, a reference to data still
stored in MySQL. The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is large).

And BTW - if you're passing the query parms, doing it in the $_SESSION
array is safer than doing it in either $_GET or $_POST.
Question: if you use a header(location) call, would the variable be
access with $_GET rather then $_POST?

Scotty
Nov 12 '08 #3
FutureShock schreef:
Jerry Stuckle wrote:
>JRough wrote:
>>I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$re sult);

but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];

I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.

I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,

$result is only a resource - in this case, a reference to data still
stored in MySQL. The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is large).

And BTW - if you're passing the query parms, doing it in the $_SESSION
array is safer than doing it in either $_GET or $_POST.
Question: if you use a header(location) call, would the variable be
access with $_GET rather then $_POST?
yes.

From first script:
header("Location: http://www.example.com/somescript.php?id=23");
exit;

will send that to the browser.
The browser then try to fetch the passed URL, being:
http://www.example.com/somescript.php?id=23

So, somescript.php will get the id via $_GET["id"]

Regards,
Erwin Moller
>
Scotty

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 12 '08 #4
FutureShock wrote:
Jerry Stuckle wrote:
>JRough wrote:
>>I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$re sult);

but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];

I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.

I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,

$result is only a resource - in this case, a reference to data still
stored in MySQL. The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is large).

And BTW - if you're passing the query parms, doing it in the $_SESSION
array is safer than doing it in either $_GET or $_POST.
Question: if you use a header(location) call, would the variable be
access with $_GET rather then $_POST?

Scotty
The variable would be available. But again, it's only a resource id.
Once the MySQL connection has been closed in the first script, the
resource itself has been released.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 12 '08 #5
Jerry Stuckle wrote:
FutureShock wrote:
>Jerry Stuckle wrote:
>>JRough wrote:
I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$r esult);

but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];

I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.

I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,

$result is only a resource - in this case, a reference to data still
stored in MySQL. The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is
large).

And BTW - if you're passing the query parms, doing it in the
$_SESSION array is safer than doing it in either $_GET or $_POST.
Question: if you use a header(location) call, would the variable be
access with $_GET rather then $_POST?

Scotty

The variable would be available. But again, it's only a resource id.
Once the MySQL connection has been closed in the first script, the
resource itself has been released.
Yeah that part I understood, but probably a mistake I would of made
eventually. :)
Just the $_POST statement did not seem right and was just curious about
using 'location' in the header() call whether it used POST of GET. Now I
am educated in both.
Thanks
Scotty
Nov 12 '08 #6
On Nov 11, 7:32*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$resu lt);
but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];
I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.
I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,

$result is only a resource - in this case, a reference to data still
stored in MySQL. *The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is large).

And BTW - if you're passing the query parms, doing it in the $_SESSION
array is safer than doing it in either $_GET or $_POST.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Okay, if it is only an empty resource then it won't work so what I
need is the $result from the query so will this work? It is a button
on an included template.
Can I get the hidden value of the $result this way passed to the xl
page?
thanks,
<form action ="<?=$_SERVER['PHP_SELF']?>" method=post>
<input type ="hidden" value=".$result." name = "_result">
<INPUT TYPE = "image" SRC='<?=$SITEURL."images/excel3.jpg"?>'
VALUE ="Open in Excel" ALT="Open in Excel" NAME="assign"></form>
Nov 12 '08 #7
On Nov 11, 7:32*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$resu lt);
but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];
I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.
I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,

$result is only a resource - in this case, a reference to data still
stored in MySQL. *The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is large).

And BTW - if you're passing the query parms, doing it in the $_SESSION
array is safer than doing it in either $_GET or $_POST.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
So you are saying that it is less memory intensive to requery the
database than to pass the result of a query?
Nov 12 '08 #8
JRough wrote:
On Nov 11, 7:32 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>JRough wrote:
>>I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$re sult);
but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];
I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.
I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,
$result is only a resource - in this case, a reference to data still
stored in MySQL. The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is large).

And BTW - if you're passing the query parms, doing it in the $_SESSION
array is safer than doing it in either $_GET or $_POST.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Okay, if it is only an empty resource then it won't work so what I
need is the $result from the query so will this work? It is a button
on an included template.
Can I get the hidden value of the $result this way passed to the xl
page?
thanks,
<form action ="<?=$_SERVER['PHP_SELF']?>" method=post>
<input type ="hidden" value=".$result." name = "_result">
<INPUT TYPE = "image" SRC='<?=$SITEURL."images/excel3.jpg"?>'
VALUE ="Open in Excel" ALT="Open in Excel" NAME="assign"></form>
No, you CANNOT PASS A RESULT to another page. It is only a reference to
a resource - and that resource is gone when the database connection is
closed (i.e. mysql_close() or end of your script).

You can pass the data. Or you can pass information about the query.
But you cannot pass a result and expect it to work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 12 '08 #9
JRough wrote:
On Nov 11, 7:32 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>JRough wrote:
>>I tried to pass the $result from a mysql_query in a url like this line
Header("Location:clm_historyXL.php?_result=".$re sult);
but on the redirect location clm_history.php page I get an error on
this line:
$result = $_POST['_result'];
I need the $result on the clm_historyXL page to print a list to excel
because
of a header already being sent.
I could also put the result in a hidden field in a form like this as a
session
variable but I don't know why the above doesn't work in the url?
<input type ="hidden" value=".$result." name = "_result">
thanks,
$result is only a resource - in this case, a reference to data still
stored in MySQL. The actual data will be lost when the connection is
closed (i.e at the end of the request).

If you need to pass the data, you need to first fetch the data.
Alternatively, pass information required for the query (NOT the query
itself - a huge security hole!) and re-execute the query on the next
page (the way it is usually done, especially if the result set is large).

And BTW - if you're passing the query parms, doing it in the $_SESSION
array is safer than doing it in either $_GET or $_POST.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

So you are saying that it is less memory intensive to requery the
database than to pass the result of a query?
First of all, don't get into premature optimization. If you have a
problem, then - and only then - is the time to look at optimizing your
code. Rather, code for clarity.

As for which is more "memory intensive" - there is no answer to that.
Passing it in a post variable means the data has to make 2 trips -
server to client, then back to server. If you've got 20 bytes of data,
that isn't bad. But 20MB would be terrible.

Additionally, the data could be modified by a hacker - which may or may
not be a problem for you. But it can happen (to any data coming from
the client).

The $_SESSION superglobal array is much more secure, since it never
leaves the server. But serializing and deserializing large amounts of
data here also can be slow.

Finally, if you do pass the data, one way or another, what's to say the
data hasn't been changed? The user might have gone to get a cup of
coffee, for instance, and then come back and continued. In the
meantime, someone else changed the data he was looking at. So when he
gets to the next page, the data is old.

For these reasons and more, when you're working with a database, it's
often better just to fetch the data on the new page. And if the query
is the same (and follows pretty closely in time), the data is probably
still going to be in the database cache, so retrieval will be quite fast.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 12 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Arjan | last post by:
I've got the following error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/wbdfdart/public_html/wbdfforum/verwijder.php on line 13 verwijder.php ...
4
by: Konrad | last post by:
In the part of code: $polecenie = "SELECT osoby.Id ,osoby.Imie , osoby.Nazwisko,osoby.Tytul,osoby.Email,adrespraca.Adres AS ap, adrespraca.KodPoczt AS...
2
by: maceo | last post by:
I have a script that will print out the results of a table and make a calculation of a total of one of the columns. See example: <?php /* Database connection */...
3
by: coder | last post by:
I am new to programming in PHP however, this should be a pretty straight forward answer. I have three queries that I am pulling for a content form page. 1) The Author List 2) The Content Page...
11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
7
by: Big Moxy | last post by:
Can someone please advise me on how to implement this? The data entered by a user on form 1 on page1.php is posted to delete.php to remove that row from a table. After the SQL operation the user...
3
hannable80
by: hannable80 | last post by:
Hi, I have being doing some php code for the very first time using wordpress as a template, basicaly what i want the prog to do is get data from a drop down menu, which i have populated with data...
3
by: swetha123 | last post by:
hello, I don't know how to use cookies please help me in this I am using the dream weaver cs4 I designed the navigation bar to my page using dream weaver cs4 navigation bar contains...
1
by: kkshansid | last post by:
i want to pass both variables($q1 and value of select) from this php page to java script so that i can get both variables in second php file srt.php <script type="text/javascript"...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.