Forums

PHP

This topic is locked

wants people to be able to purchase & download in

Posted 20 Jul 2006 22:22:03
1
has voted
20 Jul 2006 22:22:03 robert alessandrini posted:
I am using Dreamweaver 8 running on my computer with Windows XP Home. My hosting server is Linux and I use PHP and mySQL. I currently have an application Isaiahrecords.com that has the Arthur’s Music page build in a dynamic way.

Right now you can go and purchase the entire album. When this is purchased the album is mailed to the person buying. The artist wants people to be able to purchase & download individual songs. They must purchase a minimum number of songs.

My problem is how do I get them to purchase them and then let them download the song and do it so they cannot go back and download it again after a period of time.

Any suggestions would be appreciated

Replies

Replied 21 Jul 2006 15:16:20
21 Jul 2006 15:16:20 Roddy Dairion replied:
Have a table called songs_bought, then a table called songs.
In songs_bought you will need to keep the user_id, the song_id, date_ordered. In songs you keep the songs individually but have album_id, song_id, song, available.
Now when the user logs in and goes to buy a song you insert data in the table songs_bought in its respective fields. Now to show the users the songs that he didn't buy you do a query.
First select from the table songs_bought where you have a matching user_id the code would be like this
<pre id=code><font face=courier size=2 id=code>select * from songs_bought where user_id = ".$user_id</font id=code></pre id=code>
execute the query. In the while loop run another query this the songs query
<pre id=code><font face=courier size=2 id=code> select * from song</font id=code></pre id=code>
execute the query. In the while loop then you do a check
<pre id=code><font face=courier size=2 id=code>
if ($row_songs_bought['song_id'] != $row_songs['song_id')
{
echo $row_songs['song'];
}
</font id=code></pre id=code>
Now you'll have all the songs that the user didn't buy.
Now don't just think of the solution but think of the issue as well. What happens if i've bought a song, then my pc crashed i lost everything so now am looking to get this song again. Do i have to go and buy it again? If yes i can't because you're only displaying the songs that hasn't been bought already. Try to think of a way around this as well. <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>

* $user_id should be stored in a session from when the user has logged in

Reply to this topic