473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 2531
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"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.