So, i need help to do couple of things:

1. To change the hyperlink into a button. The link downloads the file from the server, which is pointed in the database. Below is the actual code of the hyperlink, and what I tried to do, to change it to a button, respectively:

echo '<h3>';
echo mysql_result($result, 0, "Name");
echo '</h3>';
echo '<p>Please right-click on the link below, and select "Save as..."</p>';
echo '<p><a href="./downloads/';
echo mysql_result($result, 0, "Link");
echo '">Download</a></p>';
echo '<h3>';
echo mysql_result($result, 0, "Name");
echo '</h3>';
echo '<FORM>';
echo '<p><input type="button" value="Download" onClick="./downloads/';
echo mysql_result($result, 0, "Link");
echo '"></p>';
echo '</FORM>'

The button appears, but when pressed nothing happens. When it's changed back to the hyperlink, then when pressed the download box pops-up, with the file name correspondent to the "Name" and "Link". Any help would be appreciated.


2. The other help i need in is the page which actually appears before this download page does. So I want to implement a page where the user will have to input some of their personal data before being able to download any file. The way I need to implement it is that there will be 2 radio buttons, when clicked on any of them a drop-down list appears where there will be some input boxes, and other radio options to chose from.

As of now, I have a simple layout without drop-down list (when 1 of the options is chosen first). I will provide the code, as soon as I will be able to complete task 1.


I would really appreciate any help. Thanks beforehand PHP Gurus.

In the second situation use two div elements each containing the form elements for one radio button and one div being visible (display:block) and other hidden (display:none). Radio buttons should have JS code which is fired on onclick event and toggles the visibility of both div elements.

To try to help with first question: onclick event can call only javascript function (I think) so you can write one and use window.open('./downloads/') javascript built in method or window.location='./downloads/'.

Member Avatar for diafol
onClick="./downloads/'

I can't understand what that does either. onclick should run js code - either inline code inside the attribute itself or a call to a js function (usually placed in the head section of the html page).

Forgive my ignorance, but this output looks overly complicated:

<h3><?php echo mysql_result($result, 0, "Name");?></h3>
<form>
<p><input type="button" value="Download" onClick="...some js...<?php echo mysql_result($result, 0, "Link");?>"></p>
</form>

That would be more readable when it comes to debugging etc. Or even:

<?php
  $var1 = mysql_result($result, 0, "Name");
  $var2 = mysql_result($result, 0, "Link");
?>
<h3><?php echo $var1;?></h3>
<form>
<p><input type="button" value="Download" onClick="...some js...<?php echo $var2;?>"></p>
</form>

I still can't work out what the second var does. Does it append a bit of url to the downloads directory?

As broj1 states, you need to use a js redirect if this is the functionality you're looking for. OR, you can enter this url to the form action attribute and set the button click to submit.

BTW - do you really need to use mysql_result? It's slow and there could be better functions to use to retrieve data from a result object.

To try to help with first question: onclick event can call only javascript function (I think) so you can write one and use window.open('./downloads/') javascript built in method or window.location='./downloads/'.

Well, I'm not trying to open the download folder, what I am trying to do is when the user clicks on the button the corresponding file download window pops-up

I still can't work out what the second var does. Does it append a bit of url to the downloads directory?

As broj1 states, you need to use a js redirect if this is the functionality you're looking for. OR, you can enter this url to the form action attribute and set the button click to submit.

The $var-s actually link to a database where there is a column with "Name" (name of the file, which appears for the user before downloading) and "Link" (the actual location of the file recorded in the database). These two variables indicate what corresponding file to download from a folder by use of the database. I hope this clarified a little what I'm trying to do.

BTW - do you really need to use mysql_result? It's slow and there could be better functions to use to retrieve data from a result object.

The problem is that I didn't actually develop this web system. It was developed by someone else, all I am doing is adding some new features. I actually don't want to rebuild the whole system just because of the slow query result fetching. Besides, the whole system is on LAN, so the speed is not that important.


Now, to make it more understandable, what I'm trying to do is just change the hyperlink (like this) into a button, but the function of the link is just a simple download. I have to mention that I'm not that good at web-programming, my main concentration is high-level programming languages like C/C++, Java and so on, but I was asked to help out to do some minor interface changes, so I agreed.

<a href="./path/to/some/file/to/download.pdf"><button name="" id="">Download</button></a>

Am I missing anything about the complexity or functionality of this?

PHP Syntax (Toggle Plain Text)

<a href="./path/to/some/file/to/download.pdf"><button name="" id="">Download</button></a>


Am I missing anything about the complexity or functionality of this?

The problem is that each file has a long name like SvrEncrptHashChk.pdf and alike, and the missing part is that I don't want to hard-link every file to a link because there are more than 200 files in that folder. The previous hyperlink did a sort by name and let the user download the corresponding file according to 2 parameters, which are the "Name" and "Link" cause these 2 are like unique keys in the database

EDIT: The 1st attached file shows the picture of how it look now.

The 2nd attachment shows the page which appears before actual download page does.

Member Avatar for diafol

you can loop these via php - you don't have to hard code anything.

have an array of filenames
set up a loop to print a filename/link/button from the array on each iteration

you can loop these via php - you don't have to hard code anything.

have an array of filenames
set up a loop to print a filename/link/button from the array on each iteration

If i understood you correctly, then do you want me to print all of the file names in the folder?

Member Avatar for diafol

NO. You can get all the filenames from a simple file in directory iteration or if you have certain filenames in mind, just place them into an array.

loop the array, extract the filename and place into some html on each iteration

standard stuff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.