ID Counter problems

This is a discussion on "ID Counter problems" within the PHP Forum section. This forum, and the thread "ID Counter problems are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 18th, 2006, 17:23
Reputable Member
Join Date: May 2006
Location: Scotland
Age: 18
Posts: 229
Thanks: 0
Thanked 0 Times in 0 Posts
ID Counter problems

I made a simple little download management system to add download title, description, demo, download count, download link + id.

So far it works to display everything apart from the link I am not sure about. How do I get the id link onto the page instead of what ive done. I need it to count the number of times the link is clicked with id in it. I have made it add the id and have the count displaying but not sure how to get it to count the id. IE what link it should be. Sorry I cant explain it much but hes the page which displays the data:

http://www.dating.jamroll.net/downloads.php

PHP: Select all

<?php
 $username 
"-----";
$password "----";
$host "localhost";
$database "dating_downloads";

mysql_connect($host,$username,$password) or die("Error connecting to Database!
mysql_error());

mysql_select_db($database) or die("Cannot select database!
mysql_error());

$getdownloads mysql_query("SELECT * FROM downloads ORDER BY id DESC"); //Retrieves all of the Data from the downloads table in your database
while($row mysql_fetch_assoc($getdownloads))
{
print(
"
$row[title] - Downloaded $row[count] Times<br/>
$row[description]<br/>
<a href=$row[demo]>View</a></span>
<a href=$row[url]/$row[id]>Download</a> </span><p/>"
);
}
?>
My downloads.php /\

PHP: Select all

<?php require_once('Connections/cssconntect.php'); ?>
<?php
function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO downloads (url, title, description, demo) VALUES (%s, %s, %s, %s)",
                       
GetSQLValueString($_POST['url'], "text"),
                       
GetSQLValueString($_POST['title'], "text"),
                       
GetSQLValueString($_POST['description'], "text"),
                       
GetSQLValueString($_POST['demo'], "text"));

  
mysql_select_db($database_cssconntect$cssconntect);
  
$Result1 mysql_query($insertSQL$cssconntect) or die(mysql_error());

  
$insertGoTo "index.html";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

mysql_select_db($database_cssconntect$cssconntect);
$query_Recordset1 "SELECT url, title, description, demo FROM downloads";
$Recordset1 mysql_query($query_Recordset1$cssconntect) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);



mysql_free_result($Recordset1);
?>
<form method="post" name="form1" action="<?php echo $editFormAction?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Url:</td>
      <td><input type="text" name="url" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Title:</td>
      <td><input type="text" name="title" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" valign="top">Description:</td>
      <td><textarea name="description" cols="50" rows="5"></textarea>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Demo:</td>
      <td><input type="text" name="demo" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insert record"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
my add.php


PHP: Select all

<?php
 $username 
"----";
$password "-------";
$host "localhost";
$database "dating_downloads";

mysql_connect($host,$username,$password) or die("Error connecting to Database!
mysql_error());

mysql_select_db($database) or die("Cannot select database!
mysql_error());

if (
$id) {//if an id has been queried then...

$go =  MYSQL_QUERY("UPDATE downloads SET count = count + 1 WHERE ID = $home[id]");


if(!
$go) { die("Error!"); }//if there is a problem, slit wrists
$home MYSQL_FETCH_ARRAY($go);//define home


MYSQL_QUERY("UPDATE v4downloads SET count = count + 1 WHERE ID = $home[id]");//update table downloads, by adding 1 to the count of the id specified
MYSQL_FREE_RESULT($go);


header("Location: $home[url]");//redirect to the url specified for the specific id
}
?>
my downloadfile.php/\ not sure what its for. All help is GREATLY APPRECIATED. If you need to ask addition question or find msn easier add me on mikkaclarke@hotmail.com.
Reply With Quote

  #2 (permalink)  
Old Nov 20th, 2006, 06:07
Up'n'Coming Member
Join Date: Nov 2006
Location: United Kingdom
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to scribbz
Re: ID Counter problems

Personally, I would just increment the count of the file downloads in your database when you actually send the download to the user i.e. directly before you send the Location: header to initiatiate the file download. I really can't see the need for add.php at all to be honest, it should just be a few lines that are initiated directly before the file download is initiated.

But then again, maybe I've missed something..it's very confusing code to me.
Reply With Quote
Reply

Tags
counter problems

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Age Counter acrikey JavaScript Forum 4 Jun 2nd, 2008 12:37
Counter confused Website Planning 6 May 21st, 2007 03:27
hit counter? skyfire400 Web Page Design 6 Mar 7th, 2006 14:00
A PHP web counter? k3nshin PHP Forum 19 Feb 19th, 2004 22:35
print "$counter times 2 is ".($counter*2)."<br>" gwx03 PHP Forum 6 Dec 10th, 2003 10:50


All times are GMT. The time now is 01:52.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43