Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-18-2006, 06:48 PM   PM User | #1
mikka23
New Coder

 
Join Date: Aug 2006
Posts: 58
Thanks: 1
Thanked 0 Times in 0 Posts
mikka23 is an unknown quantity at this point
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 Code:
<?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 Code:
<?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 Code:
<?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.
mikka23 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:07 AM.


Advertisement
Log in to turn off these ads.