![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| 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: * 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 |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#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! |
|
|
|
| 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 |
|
|
#2 (permalink) |
|
Design Team Member
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 |
|
|
|
|
|
#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 |
|
|
|
|
|
#4 (permalink) |
|
Design Team Member
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 |
|
|
|
|
|
#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 |
|
|
|
|
|
#7 (permalink) | |
|
Design Team Member
|
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:
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 | |
|
|
|
|
![]() |
| Thread Tools | |
|
|