Advertisement

04.07.2008 at 06:09AM PDT, ID: 23301175
[x]
Attachment Details

Assistance needed modifing PHP code

Asked by ST3VO in PHP Scripting Language

Tags:

Hi experts,

I have some further issues with some code and due to my little php knowledge cannot solve myself.

As a reference to what it's all about, here is a link to where it came from:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23299631.html#a21292840

The code fine but there are lots of images and whenever I click on one it's updating all the record counts in the table.

slouko, gives an explaintion to what the problem is for you experts to have a guide on where to go from here.

Hope you can help!

Thanks

ST3VO


Start Free Trial
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:
44:
45:
46:
47:
48:
49:
50:
<?php
 
header("Content-type: image/jpg");
 
// get id, and exit if it doesn't exist
$id = (isset($_GET['id'])) ? (int) $_GET['id'] : FALSE;
if(!$id) exit;
 
//connect to db first
// Connecting, selecting database
 
// db info
$db_host = 'localhost'; 
$db_user = 'root'; 
$db_pwd = 'password';
$database = 'TheDatabase'; 
 
if (@mysql_connect($db_host, $db_user, $db_pwd) and mysql_select_db($database))
{
  // this is no longer needed because of typecasting above
#  if(is_numeric($id)){ // make sure id is a number before db
 
  // no need to escape or typecast an input, because it's done already
  $sql = "SELECT image_thumbnail FROM image_admin WHERE id=$id LIMIT 1";
  $result = mysql_query($sql);
  if (mysql_num_rows($result)==0) exit;
  $row = mysql_fetch_row($result); // 'coz you use associated names in the query, you know the order, just use the index
  echo $row[0];
  // this query is soooo small, this is not really necessary
#  mysql_free_result($result);
 
  // this is useless
/*  //then do as below:
  $sql = "SELECT click_count FROM img_click_stats WHERE image_id=$id LIMIT 1";
  $result = mysql_query($sql);
  if (mysql_num_rows($result)==0) exit;
  $row = mysql_fetch_row($result);
*/
  $sql = "UPDATE img_click_stats SET click_count=click_count+1 WHERE image_id=$id LIMIT 1";
  mysql_query($sql);
  // check against affected rows, if none, insert new
  if (mysql_affected_rows() == 0)
  {
    $query = "INSERT INTO img_click_stats (image_id,click_count) VALUES ($id,1)";
    mysql_query($query);
  }
#mysql_free_result($result);
#}
}
?>
[+][-]04.07.2008 at 07:28AM PDT, ID: 21297216

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 08:11AM PDT, ID: 21297671

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 08:31AM PDT, ID: 21297876

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 08:56AM PDT, ID: 21298146

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 09:02AM PDT, ID: 21298186

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 09:03AM PDT, ID: 21298195

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 09:08AM PDT, ID: 21298218

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.07.2008 at 01:00PM PDT, ID: 21300073

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 02:15AM PDT, ID: 21303549

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 04:10AM PDT, ID: 21303979

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 04:19AM PDT, ID: 21304021

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 05:55AM PDT, ID: 21304668

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 06:22AM PDT, ID: 21304895

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 07:10AM PDT, ID: 21305415

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 07:14AM PDT, ID: 21305447

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: PHP
Sign Up Now!
Solution Provided By: julianH
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.08.2008 at 07:56AM PDT, ID: 21305870

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 08:18AM PDT, ID: 21306106

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 12:10AM PDT, ID: 21365395

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628