How to update mysql with a download link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gcupat
Forum Newbie
Posts: 3
Joined: Sun Jan 17, 2010 5:42 pm

How to update mysql with a download link

Post by gcupat »

Hi, I am fairly new to PHP and I know this may seem elementary. But all I really need to do is have a download link update field in a mysql table.

Here are the steps:

1. user fill out the form, by default the field in the MYSQL that says "download" automatically fills out as "no"
2. The user goes through to the thank you page and from here they can click to download a PDF file or they can read additional information where at the end of that they can choose to download the PDF file then.

In BOTH download links, I just need to change the mysql field called "download" from "no" to "yes". Obviously it would have to update only the user who filled out that form.

Any help would be greatly appreciated.
mellowman
Forum Commoner
Posts: 62
Joined: Sat Nov 22, 2008 5:37 pm

Re: How to update mysql with a download link

Post by mellowman »

seems to me your just trying to change a field in the database when they go to a particular page :D

SO here is some code to do that...by that i mean change a specific row in a field

Hopefully you store the username of the person in a session...so change the session variable to whatever u store it as :] and its blue
You will also want to change the database info to your own which is in red
then
you want to change whats colored in green to what you called the row were it saids yes or no...i just called it download

Code: Select all

 
<?php
session_start();
 
$login = $_SESSION["[color=#0000FF]USERNAME[/color]"];
$change = "yes";
 
 
@$DB =  new mysqli('[color=#FF0000]YOURSERVER[/color]','[color=#FF0000]DATABASENAME[/color]','[color=#FF0000]PASSWORD[/color]','[color=#FF0000]USERNAME[/color]');
if (mysqli_connect_errno())
{
    echo 'Please login!!: ' . mysqli_connect_error();
}
else
{
$Query = "UPDATE $login SET [color=#80FF00]download[/color] ='$change'";
 
$Result = $DB->query($Query);
 
    //$Result->free();
    $DB->close();
}
 
?>
 
hope this answered your question
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How to update mysql with a download link

Post by califdon »

I really don't understand your application. It sounds like you're trying to update your database AND give the user a choice of documents to download, in the same script. That's possible, of course, but it doesn't make any sense to me. Those are unrelated operations. If it were me, I would separate the two operations and not try to address both of them in the same form and script.
mellowman
Forum Commoner
Posts: 62
Joined: Sat Nov 22, 2008 5:37 pm

Re: How to update mysql with a download link

Post by mellowman »

it seems to me...that this is one operation...here are the answers to both of his questions

Code: Select all

1. user fill out the form, by default the field in the MYSQL that says "download" automatically fills out as "no"
There are settings in your phpmyadmin were u set the default value of row...

Code: Select all

2. The user goes through to the thank you page and from here they can click to download a PDF file or they can read additional information where at the end of that they can choose to download the PDF file then.
I just posted the solution in a post above this one :mrgreen:
gcupat
Forum Newbie
Posts: 3
Joined: Sun Jan 17, 2010 5:42 pm

Re: How to update mysql with a download link

Post by gcupat »

Hi mellowman,

Thanks for the code, and I think it might work for what I am doing.

But ideally I would to be able to track when someone downloads a PDF, so the link is not really going to a "page" but would be calling a PDF file that is on the server, (and forgive me, I am sure there is a better way of doing this). But this is why I would like the actual link to be the one that triggers the UPDATE to the MYSQL database. Is that possible or maybe there is a better way?

I hope that makes sense.
gcupat
Forum Newbie
Posts: 3
Joined: Sun Jan 17, 2010 5:42 pm

Re: How to update mysql with a download link

Post by gcupat »

califdon wrote:I really don't understand your application. It sounds like you're trying to update your database AND give the user a choice of documents to download, in the same script. That's possible, of course, but it doesn't make any sense to me. Those are unrelated operations. If it were me, I would separate the two operations and not try to address both of them in the same form and script.
gcupat wrote:I am sorry, let me clairify, the user already fills out a form requesting for the PDF file, and an email is sent to them with that PDF in it, BUT what I need to have happen is on the "thank you" page that the user goes to, I need to have a link that basically opens that PDF file from the server, where they can download that same PDF without actually going to their email inbox for my SEO department to do their tracking om whether or not that link was clicked on.

I am probably not doing this right for this download, and I am sure there is a better way, but at this point I am just not sure what that is.

Thanks
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: How to update mysql with a download link

Post by McInfo »

See the example on this page: http://www.php.net/manual/en/function.readfile.php

Edit: This post was recovered from search engine cache.
Post Reply