For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > October 2005 > connect to same page $_POST in <a> tag









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author connect to same page $_POST in <a> tag
Douglas F.

2005-10-08, 3:56 am

I would like to connect to:
<?php
if(isset(_POST['ver']) {
require_once('./MyStuff/mysql_connect.php');
$query2 = "INSERT INTO versiondl(Version, Date)
VALUES('$ver', NOW())";
}
?>

<td ... <a href= "./Download Files/somefile.exe"> somefile </a><td>

How can I use something like in a form (action="<?php echo
$_SERVER['PHP_SELF']; ?>") to connect from the html <a> tag to the above php
block?


Tyrone Slothrop

2005-10-08, 3:56 am

On Sat, 8 Oct 2005 00:20:43 -0400, "Douglas F." <whisper@yahoo.com>
wrote:

>I would like to connect to:
><?php
>if(isset(_POST['ver']) {
> require_once('./MyStuff/mysql_connect.php');
> $query2 = "INSERT INTO versiondl(Version, Date)
> VALUES('$ver', NOW())";
>}
>?>
>
><td ... <a href= "./Download Files/somefile.exe"> somefile </a><td>
>
>How can I use something like in a form (action="<?php echo
>$_SERVER['PHP_SELF']; ?>") to connect from the html <a> tag to the above php
>block?
>


Why not do it as a GET instead? Or do a bit of java script:
<a href="whatever" onClick="document.form.submit();">
Douglas F.

2005-10-08, 6:56 pm


"Tyrone Slothrop" <ts@paranoids.com> wrote in message
news:37lek1hsijgdr01tgh8k3cca23u4acuov8@
4ax.com...
> On Sat, 8 Oct 2005 00:20:43 -0400, "Douglas F." <whisper@yahoo.com>
> wrote:
>
php[color=darkred]
>
> Why not do it as a GET instead? Or do a bit of java script:
> <a href="whatever" onClick="document.form.submit();">


Wouldn't the onClick javascript redirect instead of downloading like I want?
I am not to familiar with this so allow for my ineptitude here. Would the
"document.form.submit()" connect with the above PHP block?


Douglas F.

2005-10-08, 6:56 pm


"Tyrone Slothrop" <ts@paranoids.com> wrote in message
news:37lek1hsijgdr01tgh8k3cca23u4acuov8@
4ax.com...
> On Sat, 8 Oct 2005 00:20:43 -0400, "Douglas F." <whisper@yahoo.com>
> wrote:
>
php[color=darkred]
>
> Why not do it as a GET instead? Or do a bit of java script:
> <a href="whatever" onClick="document.form.submit();"


How does the name: 'ver' get input so that _POST[ver] will pick it up?


Tyrone Slothrop

2005-10-08, 9:56 pm

On Sat, 8 Oct 2005 14:22:21 -0400, "Douglas F." <whisper@yahoo.com>
wrote:

>
>"Tyrone Slothrop" <ts@paranoids.com> wrote in message
> news:37lek1hsijgdr01tgh8k3cca23u4acuov8@
4ax.com...
>php
>
>How does the name: 'ver' get input so that _POST[ver] will pick it up?


Pass as a query string:
<a href="<?$_SERVER['PHP_SELF']?>?ver=somehting">">
Then evaluate: $_GET['ver']

Tyrone Slothrop

2005-10-08, 9:56 pm

On Sat, 8 Oct 2005 11:54:41 -0400, "Douglas F." <whisper@yahoo.com>
wrote:

>
>"Tyrone Slothrop" <ts@paranoids.com> wrote in message
> news:37lek1hsijgdr01tgh8k3cca23u4acuov8@
4ax.com...
>php
>
>Wouldn't the onClick javascript redirect instead of downloading like I want?
>I am not to familiar with this so allow for my ineptitude here. Would the
>"document.form.submit()" connect with the above PHP block?


It would post to the value passed in the post tag:
<form action="<?_$_SERVER['PHP_SELF']?>" method="post">
Doug

2005-10-08, 9:56 pm


"Tyrone Slothrop" <ts@paranoids.com> wrote in message
news:15mgk15krqk0rag04ee5tcls4ujvs40718@
4ax.com...
> On Sat, 8 Oct 2005 11:54:41 -0400, "Douglas F." <whisper@yahoo.com>
> wrote:
>
above[color=darkred]
want?[color=darkred]
the[color=darkred]
>
> It would post to the value passed in the post tag:
> <form action="<?_$_SERVER['PHP_SELF']?>" method="post">


Could the href call do download be put within the <form call like this:

<form action="<?_$SERVER['PHP_SELF']?>" method="post">
<td ... <a href= "./Download Files/somefile.exe"
onClick="document.form.submit()"> somefile </a><td>
</form>


Douglas F.

2005-10-09, 6:56 pm


"Tyrone Slothrop" <ts@paranoids.com> wrote in message
news:c0mgk1dggfvitmd7v7tl56395b0lk7e86t@
4ax.com...
> On Sat, 8 Oct 2005 14:22:21 -0400, "Douglas F." <whisper@yahoo.com>
> wrote:
>
above[color=darkred]
>
> Pass as a query string:
> <a href="<?$_SERVER['PHP_SELF']?>?ver=somehting">">
> Then evaluate: $_GET['ver']
>

Could it be written:

<a href="./Download Files/somefile.exe">somefile>
"<?$_SERVER['PHP_SELF']?>?ver= somefile"> </a>


JDS

2005-10-09, 6:56 pm

On Sun, 09 Oct 2005 13:10:02 -0400, Douglas F. wrote:

> Could it be written:
>
> <a href="./Download Files/somefile.exe">somefile>
> "<?$_SERVER['PHP_SELF']?>?ver= somefile"> </a>


No. Not sure what you are trying to do with that but you appear to be
incorrectly using HTML and PHP to produce a mishmash. (No offense
intended, just calling like I sees it).

To send a variable/value from an HTML page to a PHP script, you must put
the variable in a form or in the URL. An HTML form can use either the GET
or POST methods; a URL uses only the GET method.

PHP then takes whatever is sent and makes it accessible to the script in
either ( ( the $_POST global array OR the $_GET global array ) AND the
$_REQUEST global array ).

For clarification, read this:
http://us3.php.net/manual/en/tutorial.forms.php

and this:
http://us3.php.net/manual/en/reserv...d.variables.get


Also, the original post has some obvious errors in it that could be typos.
Did you retype it or copy and paste it from the real source?



--
JDS | jeffrey@go.away.com
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Doug

2005-10-09, 6:56 pm


"JDS" <jeffrey@example.invalid> wrote in message
news:pan.2005.10.09.17.56.45.320237@example.invalid...
> On Sun, 09 Oct 2005 13:10:02 -0400, Douglas F. wrote:
>
>
> No. Not sure what you are trying to do with that but you appear to be
> incorrectly using HTML and PHP to produce a mishmash. (No offense
> intended, just calling like I sees it).
>
> To send a variable/value from an HTML page to a PHP script, you must put
> the variable in a form or in the URL. An HTML form can use either the GET
> or POST methods; a URL uses only the GET method.
>
> PHP then takes whatever is sent and makes it accessible to the script in
> either ( ( the $_POST global array OR the $_GET global array ) AND the
> $_REQUEST global array ).
>
> For clarification, read this:
> http://us3.php.net/manual/en/tutorial.forms.php
>
> and this:
> http://us3.php.net/manual/en/reserv...d.variables.get
>
>
> Also, the original post has some obvious errors in it that could be typos.
> Did you retype it or copy and paste it from the real source?
>
>
>
> --
> JDS | jeffrey@go.away.com
> | http://www.newtnotes.com
> DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/
>


I presented the original post in abreviated form. What is working now is
the html:
<td width="140"><a href="./Download
Files/cbver169.zip">cbver169.zip</a></td> // for downloading the file

I want to modify that line to connect to the php 'if(isset(_GET['ver']) {
....}' on the same page (upper block). 'ver' is whatever is the string, in
this case (cbver169.zip).


JDS

2005-10-10, 6:58 pm

On Sun, 09 Oct 2005 14:44:15 -0400, Doug wrote:

> I presented the original post in abreviated form. What is working now is
> the html:
> <td width="140"><a href="./Download
> Files/cbver169.zip">cbver169.zip</a></td> // for downloading the file
>
> I want to modify that line to connect to the php 'if(isset(_GET['ver']) {
> ...}' on the same page (upper block). 'ver' is whatever is the string, in
> this case (cbver169.zip).



I still think you are not quite understanding how this all works. Also,
and this will sound like nitpicking but it is not, do *NOT* use spaces in
file or directory names within URLs. "Download Files" should really
really really not have a space in it. But that is a separate issue.

In any case, what do you mean by "modify that line to connect to the php"?
Do you mean that you want to link to a PHP script in that line? There is
no "ver" variable anywhere that I can see.

Also, the PHP code has a clear typo in it -- "_GET" must start with a
dollar sign -- "$_GET". Is this a typo in your posting or is this
actually in the PHP code?

Let's go back a few steps.

What are you trying to do?

--
JDS | jeffrey@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Doug

2005-10-10, 6:58 pm


"JDS" <jeffrey@example.invalid> wrote in message
news:pan.2005.10.10.14.02.14.214081@example.invalid...
> On Sun, 09 Oct 2005 14:44:15 -0400, Doug wrote:
>
is[color=darkred]
{[color=darkred]
in[color=darkred]
>
>
> I still think you are not quite understanding how this all works. Also,
> and this will sound like nitpicking but it is not, do *NOT* use spaces in
> file or directory names within URLs. "Download Files" should really
> really really not have a space in it. But that is a separate issue.
>
> In any case, what do you mean by "modify that line to connect to the php"?
> Do you mean that you want to link to a PHP script in that line? There is
> no "ver" variable anywhere that I can see.
>
> Also, the PHP code has a clear typo in it -- "_GET" must start with a
> dollar sign -- "$_GET". Is this a typo in your posting or is this
> actually in the PHP code?
>
> Let's go back a few steps.
>
> What are you trying to do?
>
> --
> JDS | jeffrey@example.invalid
> | http://www.newtnotes.com
> DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/
>


The existing web page https://st23.startlogic.com/~libertys/download.php has
downloads at the bottom of the page. When a user clicks on a link the
browser goes into the download mode and the user downloads the file. What I
am trying to do is run a MySQL query in PHP (same page because there is a
header call for the form data) to store the version string ("cbverxxx.exe")
and present date of download. The way the code exists to do this (download
the file) is as shown in my last post noted above.

On a Windows directory reference 'Download Files', spaces are allowed and it
has worked so far in all of the Windows code I have written.


JDS

2005-10-10, 6:58 pm

On Mon, 10 Oct 2005 11:28:37 -0400, Doug wrote:

> The existing web page https://st23.startlogic.com/~libertys/download.php has
> downloads at the bottom of the page. When a user clicks on a link the
> browser goes into the download mode and the user downloads the file. What I
> am trying to do is run a MySQL query in PHP (same page because there is a
> header call for the form data) to store the version string ("cbverxxx.exe")
> and present date of download. The way the code exists to do this (download
> the file) is as shown in my last post noted above.
>
> On a Windows directory reference 'Download Files', spaces are allowed and it
> has worked so far in all of the Windows code I have written.


I see. I'll answer the "spaces in filenames" part first.

Spaces are allowd in Windows file and directory names, yes. In fact, they
are allowed in Linux, Mac, and other OS file and directory names.

They are NOT, however, allowed in URLs (even though browsers are flexible
enough to compensate). A space in a URL should be encoded as "%20".
There are a number of reasons why you should follow this suggestion, but
that is an aside...

Now, back to point in hand. To have the string of PHP code "get" the
value of the $_GET variables when the link is clicked, the link has to
point to the PHP page, like so (assuming the page is called "booger.html"):

<a href="booger.html?ver=1.23">Download Version 1.23 of This File</a>

Then the PHP can use the SQL statement to track the version chosen. But
what about the download? Well, you will have to point the script to the
download file at that point by one of three ways:

* Use a redirect header to redirect to the proper download file
* Read the file into a variable, send the proper MIME headers, and then
output the binary contents of the file.
* Some other way I haven't thought of. There is *always* another way to
do something.

The first one is easiest, but offers the least control and security
options. The second way is more flexible and potentially secure, but
harder to implement.

See:
http://us2.php.net/header
http://us2.php.net/manual/en/functi...et-contents.php
http://us2.php.net/manual/en/function.fopen.php
etc...

--
JDS | jeffrey@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com