Jump to content

Super2

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Posts posted by Super2

  1. Duplicate entry '' for key 1

     

    That error states that there is already an entry in the table for key 1 that is empty. A variable is not being populated.

     

    Also an IP address is not a good idea for a primary key, keep that id in there as IP's are not always unique to users.

    so ? U suggest to use id as Primary key ? I checked in the DB

    ip 	data 	impresiq 	uniq
    //*HERE is empty	13.07.2007 	0 	0
    	85.187.187.179 	13.07.2007 	0 	1

    I have some error in the IF statement i think, but i can`t find it....

    I want it like that:

    If the ip is new it is recorded in  'ip' and unique is being set to 1.

    Or if it is not new > impresiq/refreshes is being increased:

    if ($ip == $row['ip']){
    
    $impresiq = $row['impresiq'] + 1;
    $query ="UPDATE `visitor` SET impresiq = '$impresiq' WHERE ip = '$ip' ";
    $do = mysql_query($query) or die("Greshka3:".mysql_error()); 
    
    }else{
    $query = "INSERT INTO  `visitor` (ip , uniq, data) VALUES ('$ip', '1', '$data')";
    $do = mysql_query($query) or die("Greshka2:".mysql_error()); 
    }
    

  2. I tried making ip Primary key and using

    if ($ip == $row['ip']){
    
    $impresiq = $row['impresiq'] + 1;
    $query ="UPDATE `visitor` SET impresiq = '$impresiq' WHERE ip = '$ip' ";
    $do = mysql_query($query) or die("Greshka3:".mysql_error()); 
    
    }else{
    $query = "INSERT INTO  `visitor` (ip , uniq, data) VALUES ('$ip', '1', '$data')";
    $do = mysql_query($query) or die("Greshka2:".mysql_error()); 
    }
    

    But it gives me and error....

    Duplicate entry '' for key 1
  3. Hey guys,

     

    I was just wondering in how do I exit an html frameset as I have a link which has to redirect back to the index page as shown below, which should not have the frames.

    Any help would be great thanks.

     

    header("location:index.php");
    

    Is that gonna work:

    <FORM>

    <INPUT type="button" value="Click here to go back" onClick="history.back()">

    </FORM>

    or

    <a href="#" onClick="history.go(-1)">Back</a>

  4. You still have to give it 4 values though right?

     

    Just do:

    $query = "INSERT INTO  `visitor` (id, ip , uniqe, date) VALUES (NULL, '$ip', '1', '$date')";

     

    If it is an auto_increment.

    You need to put quotes around the values you pass in too.

    Is the word 'uniqe' suppose to be 'unique'?

    Yeah it is supposed to :D but i already used everywhere that  ;D

     

    Now i`m using:

    $ip = $_SERVER['REMOTE_ADDR'];
    $date = date("d.m.Y");
    
    $query = "SELECT * FROM `visitor`";
    $res = mysql_query($query) or die("Greshka ".mysql_error());
    while($row = mysql_fetch_array($res)) {
    
    if($date == $row['date']){
    
    if ($ip != $row['ip']){
    
    $query = "INSERT INTO  `visitor` (ip , uniqe, date) VALUES ('$ip', '1', '$date')";
    $do = mysql_query($query) or die("Greshka2:".mysql_error()); 
    
    }elseif($row['uniqe'] == 1) {
    $impresiq = $row['impresiq'] + 1;
    $query ="UPDATE `visitor` SET impresiq = '$impresiq' WHERE ip = '$ip' ";
    $do = mysql_query($query) or die("Greshka3:".mysql_error()); 
    }
    
    }
    }

     

    But again there are no signs of live.... The strange is that it returns no error.....

     

    p.s. id is auto_increment

    ps2. That is my table:

    $insert = "CREATE TABLE `visitor` (
    `id` int(20) NOT NULL auto_increment,
    `ip` varchar(255) default NULL,
    `date` varchar(10) default NULL,
    `impresiq` varchar(255) default NULL,
    `uniqe` varchar(255) default NULL,
    PRIMARY KEY (`id`)
    )";
    

  5. Hi guys,

    I`m new to this forum :)

    I`m trying to make a php counter, but it just didn`t work...

    Here is my code. It returns no error, but it is not working :(

    
    $ip = $_SERVER['REMOTE_ADDR'];
    $date = date("d.m.Y");
    
    $query = "SELECT * FROM `visitor`";
    $res = mysql_query($query) or die("Greshka ".mysql_error());
    while($row = mysql_fetch_array($res)) {
    
    if($date == $row['date']){
    
    if ($ip != $row['ip']){
    
    $query = "INSERT INTO  `visitor` (id, ip , uniqe, date) VALUES ($ip, 1, $date)";
    $do = mysql_query($query) or die("Greshka2:".mysql_error()); 
    
    }else{
    $impresiq = $row['impresiq'] + 1;
    $query ="UPDATE counter SET count = '$count' WHERE ip = '$ip' ";
    $do = mysql_query($query) or die("Greshka3:".mysql_error()); 
    }
    
    }
    }
    echo $impresiq." refreshes<br/>\n";
    echo "Ip-to vi e ".$ip."<br/> na";
    echo $date;
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.