Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 10-05-2009, 05:44 PM   #1 (permalink)
Registered User
 
Join Date: May 2007
Location: British Columbia, Canada
Posts: 53
OS: vista


PHP and mySQL glitch

Hi people

Please look at the following...I will not give you all the code involved but I narrowed it down to this...

Code:
<?php


$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }



mysql_select_db("Persons", $con);



$result = mysql_query("SELECT * FROM  hits_on_musicpage");
$pagehit_total = mysql_num_rows($result);


//this echo always reports 2 times the rows that should be in the database

echo $pagehit_total;


echo "<table border='1' align=center>
<tr>
<th>IP</th>
<th>Host</th>
<th>Month</th>
<th>Day</th>
<th>Year</th>
</tr>";


while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['ip'] . "</td>";
  echo "<td>" . $row['host'] . "</td>";
  echo "<td>" . $row['month'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
echo "</tr>";
  }
echo "</table>";

mysql_close($con);

?>

Thank you so much for your help!
BrentC is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 10-06-2009, 04:05 AM   #2 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros


Re: PHP and mySQL glitch

Hey, can we see the result of that page?
If it's returning twice the amount of rows in the table then what is in the table and how is it structured?

Does the second echo (the one that echoes the row of data, for each entry) echo twice the amount or is it working fine?

I know it sounds random and nitty-gritty (or OCD) but your sql query has an extra space in it, i'm pretty sure whitespace doesn't matter in mysql but i can't remember so there might be something there.

Cheers,
Jamey
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-06-2009, 04:26 PM   #3 (permalink)
Registered User
 
Join Date: May 2007
Location: British Columbia, Canada
Posts: 53
OS: vista


Re: PHP and mySQL glitch

here is the code that populates the database...

Code:
$ip = $_SERVER['REMOTE_ADDR'];
$host = gethostbyaddr($ip);
$mtime = date('m');
$dtime = date('d');
$ytime = date('Y');
$htime = date('H');
$mintime = date('i');
$stime = date('s');

$host_trimmed = substr($host, 0, 16);

mysql_select_db("Persons", $con);


$sql="INSERT INTO hits_on_musicpage (month, day, year, ip, host) VALUES ('$mtime', '$dtime', '$ytime', '$ip', '$host_trimmed')";

The output from all this is just a simple table but with two rows for every hit (Insersion).

Here is the url for the SELECT page

24.67.40.54/select-musicpage-hits.php
BrentC is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-06-2009, 04:32 PM   #4 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,879
OS: Vista, various linux distros


Re: PHP and mySQL glitch

I don't see a problem with any of the code (as long as the population script is cut down there)...

Could you try opening up mysql.exe and selecting all the entries, since they're all repeated there might be something going on there.

Cheers,
Jamey
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-06-2009, 05:13 PM   #5 (permalink)
Registered User
 
Join Date: May 2007
Location: British Columbia, Canada
Posts: 53
OS: vista


Re: PHP and mySQL glitch

I don't know how to open mysql.exe...

The code that follows population code above is some html
BrentC is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-07-2009, 05:17 PM   #6 (permalink)
Registered User
 
Join Date: May 2007
Location: British Columbia, Canada
Posts: 53
OS: vista


Re: PHP and mySQL glitch

I have found that when someone outside of my network downloads my page the database app works ok. Just when I access the page on my server that it is saved twice.

Also, I have another mySQL app and it works fine either way....

Brent
BrentC is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-08-2009, 11:48 AM   #7 (permalink)
Design Team Member
 
Redcore's Avatar
 
Join Date: Aug 2007
Location: Jamestown, CA
Posts: 715
OS: Linux Mint 7

My System

Re: PHP and mySQL glitch

This is a pretty bizarre problem. Your code is really simple and appears to be correct. After Googling it a bit, I found something that might help explain...

Quote:
Browsers will request a page twice for several reason - FF when it applies the visitor's character encoding choice, IE when it requests your favicon.ico file, all browsers if you have a URL rewrite rule that is either missing or has a trailing slash on a folder (I don't remember which)...

There are two common ways to detect and prevent the double database insert -

1) If something about the data is unique so that one of the values will only exist once in the database, make that column a unique key so that the second insert will produce a duplicate key error and won't insert the second time, or

2) Use a session variable to detect that the form processing code has already been executed once. Set some session variable when the query executes and test if this variable is set at the start of the form processing code. Skip the form processing code if the variable is already set.

The reason printing the query does not show you anything in this case is because the page is requested/refreshed and unless you are very fast you won't see the two copies of the page being displayed.
http://codingforums.com/showpost.php...83&postcount=5

This looks like it would be the cause of your issue since you run this INSERT script every time someone accesses that page. The first suggestion is the one you should go with. Create a UNIQUE INDEX with columns (month, day, year, ip) and then any duplicated entries should be ignored.
__________________
Free Resources
PC Protection - Comodo Firewall | AVG Anti-Virus | WinPatrol | Ad-Aware | Spybot S&D | SpywareBlaster |
Web Design/Programming - KompoZer
(Editor) | Paint.NET (Graphic) | GIMP+GIMPShop (Graphic) | FileZilla (FTP Client) | Free Hosting |
Redcore is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


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 Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 04:18 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85