The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> How to insert a row in a table when user clicks download button(link)
Rating  5
larry78723
post Apr 6 2020, 02:43 PM
Post #1


Member
***

Group: Members
Posts: 39
Joined: 5-March 20
Member No.: 27,220



When a user opens my webpage, a connection to the database is established and a row is inserted into a table with the user's ip address. If the user decides to download a file, another row needs to be inserted into the same table with the user's ip address and filename. What I'm asking is how to trigger that line when the button (link) is clicked.
Here's what the top of my index.php looks like:

CODE

<?php
session_start();
// start of script every time.

//  setup a path for all of your canned php scripts
$php_scripts = '/home/larry/web/test/php/'; // a folder above the web accessible tree
//  load the pdo connection module  
require $php_scripts . 'PDO_Connection_Select.php';
require $php_scripts . 'GetUserIpAddr.php';

//*******************************
//   Begin the script here
$ip = GetUserIpAddr();
if (!$pdo = PDOConnect("foxclone")):
{
    echo "Failed to connect to database";
    exit;
}
else:
{
    $filename = NULL;
    $stmt = $pdo->prepare("INSERT INTO download (IP_ADDRESS, FILENAME) VALUES (?, ?)");
    $stmt->execute([$ip,$filename]);
}

endif;
//exit();
?>

<DOCTYPE html>


$stmt->execute([$ip,$filename]) ; is what does the insertrow.

The download section of index.php looks like this:

CODE

<!--  DOWNLOAD -->
<div id="download" class="stylized">
    <div "myform">
    <div class="container">
        <div class="row">
            <div class="download">
                <br /><br>
                <h1><center>FoxClone Download Page</center></h1>
                   <?php
                    $files = glob('download/*.iso');
                    $file = $files[count($files) -1];
                    $info = pathinfo($file);
                    $filename =  basename($file);
                    $filename = ltrim($filename,'/');
                    $md5file = md5_file($file);
                   ?>

                    <?php
                    $pdfs = glob('download/foxcloneV*.pdf');
                    $pdf = $pdfs[count($pdfs) -1];
                    $pdfname = basename($pdf);
                   ?>

                   <?php
                    $debs = glob('download/*.deb');
                    $deb = $debs[count($debs) - 1];
                    $debname =  basename($deb);                
                   ?>

                    <?php
                    $srcs = glob('download/*.tar.*');
                    $src = $srcs[count($srcs) - 1];
                    $srcname = basename($src);                  
                   ?>

                    <div class="container">
                        <div class="divL">                      
                            <h3>Get the "<?php echo "{$filename}";?>" file (approx. 600MB)</h3>
                        <center>  <a href="<?php echo "/{$file}";?>"><img src="images/button_get-the-app.png" alt=""></a>  </center>
                            
<br />
                            <h3 style="margin-bottom: 0.5rem;">The MD5sum for "<?php echo "{$filename}";?>" is "<?php echo "{$md5file}";?>  
<br>

________________________________________________________________________________
______________________________________"</h3>
                            <h3>Read or Download the Installation and Use Instructions </h3>
                         <center> <a href="<?php echo "/{$pdf}";?>"><img src="images/button_read-the-file.png" alt=""></a></center>
<br /><h3& #62;____________________________________________________________________________
__________________________________________"</h3>
    
                            <h3>How To Install To A USB/CD</h3>
                            <h4>1. Download the iso file <br />
                                2. a. If burning to a USB stick use the USB image writer that comes with your distribution.  <br />
                         b. If burning to a CD, there are many Linux utilities, xfburn is one of the simplest. Install from your software
manager/centre if not installed.</h4>
                        <br />
                            <h3>How To Boot The USB/CD</h3>
                            <h4>At the manufacturer’s splash screen, press the key to get into the boot menu. This key varies across PCs, as an example for a Lenovo
                    Thinkpad it is F12. Consult your user manual to find out what the key is or google. Do not confuse the boot menu with the boot priority order
                    settings in BIOS. The boot menu is a one time selection for the device to use to boot the PC. It overrides the normal boot priority order. The next
                    time you boot, the PC will revert to the normal boot order. Virtually all BIOSs support this feature, they just do it differently.  </h4>
                        </div>
                  
                    
                        <div class="divR">                      
                            <h3>Get the "<?php echo "{$debname}";?>" file (approx. 7MB) </h3>
                         <center> <a href="<?php echo "/{$deb}";?>"><img src="images/button_download.png" alt=""></a></center><br />
                            <h3 style="color:red"><b>WARNING - DO NOT INSTALL THIS TO YOUR COMPUTER !!!</b></h3>
                            <h4 style="color:black">This .deb file is designed to be installed on a large USB drive, typically 1TB or greater, that already has an operating system installed and is intended as a backup drive.</h4>
                                
                            <h4><b>For more information <a href='download/deb_file.pdf' style='color:#ff0099;'>Click Here</a></b></h4>
                            
<br><h3& #62;____________________________________________________________________________
__________________________________________"</h3>

                            <h3>Get the "<?php echo "{$srcname}";?>" Source file (approx. 6MB) </h3>
                         <center> <a href="<?php echo "/{$src}";?>"><img src="images/button_download.png" alt=""></a></center>
                          
                        </div>
                    </div>
              </div>
          </div>                    
     </div>
</div>
</div>


The button (links) are what are doing the downloads except in the case of the pdf file, which opens in another window. How do I code this so that a new row is inserted in the table when the user clicks on the download button (link) ?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2024 - 03:29 AM