Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP MySQL - Only inserting once
Old 02-22-2008, 04:49 PM PHP MySQL - Only inserting once
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
I have a script, that registers anyone that visits the URL, and it redirects to proper url, used to register visits on some links I have. (at the moment one)

Having problems with it though. I have made it insert new data into my MySQL database, and its supposed to do this every time someone visits the URL, although it only inserts a set once, and then stops working.

PHP Code:
<?php 

include('db.php');



    
dbConnect();
    
$sql "select filename from dlstats";
    
$result mysql_query($sql);
    
$rows mysql_num_rows($result);
    
    for (
$x=0;$x<$rows;$x++) {
    
$urlarray[$x] = mysql_result($result,$x);
    }
    
    
$request $urlarray['purchase'];
    
    
        
header("Location: http://www.gks.uk.com/buy"); 
    
// if ($REMOTE_ADDR == '82.35.196.185'){    
    
    
        
    
date_default_timezone_set('GMT');
    
$datetime date('d M Y h:i:s a');
    
$querystat "INSERT INTO dlstats SET FileCode='purchase', IP='$REMOTE_ADDR', DateTime='$datetime', StatNo=StatNo+1";
    
$resultstat mysql_query($querystat);
    if (!
$result){ 
        echo(
"Database Error2");    
    }
    
    
    


if (isset(
$showme)){
    
dbConnect();
    
$query "SELECT totalhits FROM dlcount WHERE FileCode = $showme";
    
$result mysql_query($query);
    
$hitcount mysql_result($result,0);
    echo(
$hitcount);
}

// else echo 'IP Skipped (because its mine) '; } 


?>
db.php just contains my database configuration.

Can someone please tell me why its only adding data once. And possibly lead me to a fix.
Gilligan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-22-2008, 08:56 PM Re: PHP MySQL - Only inserting once
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You have the wrong syntax on your sql insert command. Here is an example:

Code:
INSERT INTO table_name
(field_1, field_2, field_3)
VALUES(
  'Value for field 1',
  'Value for field 2',
  'Value for field 3'
)
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 02-23-2008, 06:27 AM Re: PHP MySQL - Only inserting once
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Okay, i've edited it, but it still only inserts once.

[EDIT]I changed a column in the MySQL database to be auto_increment, and thats works now.[/EDIT]
Gilligan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP MySQL - Only inserting once
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27154 seconds with 12 queries