• Help
  • Search
  • Login
  • Register
  • Home

Forum: web design and graphics community

Celestial Star Forum > Web Development > Coding > Preview It (32) PHP help...?
Pages: 1 [2]
« previous next »
  Print  
Author Topic: Preview It (32) PHP help...?  (Read 6899 times)
puretaurus21
Guest
Preview It (32) PHP help...?
« Reply #15 on: January 22, 2005, 04:49:17 PM »

Okay, I don't really get it :S. I tried experimenting and I made this  

Code:
$id = trim($_GET['id']);

$mode = mysql_escape_string($_GET['type']);

if (!isset($type) || empty($type))
{   $type = 'index';   }

switch($type)
{  
     case 'templates';

$q="SELECT download from templates where id='$id'";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

while ($row=mysql_fetch_array($result))
{
$download = $row['download'];

$q2="update templates set counter=counter+1 where id='$id'";
$result2= mysql_query($q2) or die
("Could not execute query : $q2." . mysql_error());

if ($result2) // updated counter so let user download file
{
header('Location: '.$download );
} #end result2

} #end while

   break;

   case 'avatars';

$q="SELECT download from avatars where id='$id'";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

while ($row=mysql_fetch_array($result))
{
$download = $row['download'];

$q2="update avatars set counter=counter+1 where id='$id'";
$result2= mysql_query($q2) or die
("Could not execute query : $q2." . mysql_error());

if ($result2) // updated counter so let user download file
{
header('Location: '.$download );
} #end result2

} #end while

break;

}


I uploaded that code but it didn't work. I really didn't get you about what it say on the code you told before about the update query thing because theres two :S
Logged
Melfina
Administrator
Valkyrie Randgris
*****
Posts: 1289



View Profile WWW
Preview It (32) PHP help...?
« Reply #16 on: January 22, 2005, 06:35:42 PM »

You only need to add the connection stuff there. I really don't think you need to add the $id = trim($_GET['id']); thing there. Try first with it and remove it if it doesn't work well:


Code:
<?php

$id 
= trim&#40;$_GET['id'&#93;&#41;;

$type = mysql_escape_string&#40;$_GET['type'&#93;&#41;; 

if &#40;!isset&#40;$type&#41; || empty&#40;$type&#41;&#41; 
&#123;   $type = 'index';   &#125; 

switch&#40;$type&#41; 
&#123;  
     
case 'templates';

$hostname="localhost";
$user="yourusernamehere";
$pass="yourpasshere";
$dbase="yourdatabasenamehere"; 
$connection = mysql_connect&#40;"$hostname" , "$user" , "$pass"&#41;;
$db = mysql_select_db&#40;$dbase , $connection&#41;;

$q="SELECT download from templates where id='$id'";
$result= mysql_query&#40;$q&#41; or die
&#40;"Could not execute query &#58; $q." . mysql_error&#40;&#41;&#41;;

while &#40;$row=mysql_fetch_array&#40;$result&#41;&#41;
&#123;
$download = $row['download'&#93;;

$q2="update templates set counter=counter+1 where id='$id'";
$result2= mysql_query&#40;$q2&#41; or die
&#40;"Could not execute query &#58; $q2." . mysql_error&#40;&#41;&#41;;

if &#40;$result2&#41; // updated counter so let user download file
&#123;
header&#40;'Location&#58; '.$download &#41;;
&#125; #end result2

&#125; #end while

   
break; 

   case 
'avatars';

$hostname="localhost";
$user="yourusernamehere";
$pass="yourpasshere";
$dbase="yourdatabasenamehere"; 
$connection = mysql_connect&#40;"$hostname" , "$user" , "$pass"&#41;;
$db = mysql_select_db&#40;$dbase , $connection&#41;;


$q="SELECT download from avatars where id='$id'";
$result= mysql_query&#40;$q&#41; or die
&#40;"Could not execute query &#58; $q." . mysql_error&#40;&#41;&#41;;

while &#40;$row=mysql_fetch_array&#40;$result&#41;&#41;
&#123;
$download = $row['download'&#93;;

$q2="update avatars set counter=counter+1 where id='$id'";
$result2= mysql_query&#40;$q2&#41; or die
&#40;"Could not execute query &#58; $q2." . mysql_error&#40;&#41;&#41;;

if &#40;$result2&#41; // updated counter so let user download file
&#123;
header&#40;'Location&#58; '.$download &#41;;
&#125; #end result2

&#125; #end while

break; 

&
#125; 

?>
Logged


MySpace  ~ MySpace Codex ~ Rune Nifelheim
puretaurus21
Guest
Preview It (32) PHP help...?
« Reply #17 on: January 23, 2005, 02:55:54 AM »

Oh thanks, Melfina! It worked very well. Thank you for helping me, I'll make sure to credit you :D
Logged
Arwen
Incubus
**
Posts: 60



View Profile WWW
Preview It (32) PHP help...?
« Reply #18 on: July 18, 2006, 09:11:57 AM »

Thanks for posting the tutorial, BUT I think I'm stuck! I created a table in my MySQL database made two files (view.php and download.php), uploaded them to my server AND now I'm stuck! What do I do next? Please, help!!!!!!!!!!!!
Logged

Free Wordpress Themes
Blackstone
Administrator
Valkyrie Randgris
*****
Posts: 821

Oh look! People!


View Profile
Preview It (32) PHP help...?
« Reply #19 on: July 18, 2006, 01:58:53 PM »

Erm, how are you stuck? Can you give us some more details?
Logged
Arwen
Incubus
**
Posts: 60



View Profile WWW
Preview It (32) PHP help...?
« Reply #20 on: July 18, 2006, 03:11:43 PM »

Well, just like I said, I created a table in my MySQL database, created two files (view.php and download.php), uploaded them to my server and I don't know what to do next. Do I need to add my .zip files to the database or something...?  :?
Logged

Free Wordpress Themes
Blackstone
Administrator
Valkyrie Randgris
*****
Posts: 821

Oh look! People!


View Profile
Preview It (32) PHP help...?
« Reply #21 on: July 18, 2006, 03:20:01 PM »

You need to enter information into your database. It all really depends on how you've set up the databases and the PHP files.
Logged
Pages: 1 [2]
  Print  
« previous next »
 
Jump to:  

  • Welcome, Guest
  • Members login
  • Register for free

General

  • General
  • New members
  • Announcements
  • Support / Suggestions

Art boards

  • Creative mediums
  • Requests and offers
  • Tutorials
  • Celestial Star tutorials

Web development

  • Coding
  • Web design
  • Advertisements / affiliation

Off-topic

  • The non-sense
  • Ententainment

Go up
eXTReMe Tracker
  • Valid XHTML
  • Valid CSS
Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC | Seo4Smf v0.2 © Webmaster's Talks
Loading...