Jump to content

Duplicate entry '0' for key 'PRIMARY'


averageah64

Recommended Posts

This is my error in my Vote script: Duplicate entry '0' for key 'PRIMARY'.

I did changned in phpmyadmin but he automaticly go's to 0 and everytime I wanna vote I get this error.

 

Here's my website code:

<?php
        session_start();
        require_once 'assets/config/config.php';
        $pageName = "Runelab - Vote Server";
?>
<?php include 'assets/templates/overall/overallHead.php'; ?>
<?php include 'assets/templates/navHead.php'; ?>
		<div id="res_content" >
		<h2>Vote Your Server</h2>

<center>
<p>Server name you want to vote.</p>
<?php
$note = '<form method="GET" action="vote.php"><input name="servername"/><input type="submit" value="Vote" /></form>';
$variable = "";
$ip = $_SERVER['REMOTE_ADDR'];
include('assets/config/config.php');

if(isset($_GET['servername'])){
	
	
	
$sn = $_GET['servername'];
$username = mysql_real_escape_string($row['username']);

 $SQL = "SELECT * FROM id WHERE ip = '$ip'";
 $result = mysql_query($SQL);
 
while ($db_field = mysql_fetch_assoc($result)) {
$variable = $db_field['edate'];
}

$dates = date("Ymd");
if($variable == $dates){
header( 'location: votes.php?action=false' );
die();
} else {
mysql_query("DELETE FROM id WHERE ip = '$ip' AND Name='$sn'");
}

$query = mysql_query("SELECT * FROM clients WHERE servername='$sn'"); 
if(mysql_num_rows($query) != 0)
 {
 $SQL = "SELECT * FROM clients WHERE servername='$sn'";
 $result = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($result)) {
$votes = $db_field['Votes'];
$newvotes = $votes + 1;
mysql_query("UPDATE clients SET votes = votes + 1 WHERE servername = '$sn'");
$date = date("Ymd");
mysql_query("INSERT INTO id
(ip, edate, Name) VALUES('$ip', '$date', '$sn')") 
or die(mysql_error());
header( 'location: votes.php?action=true' );
die();
 }
 
 
 
 }
 }
 else
 {
$note = '<form method="GET" action="vote.php"><input name="servername" /><input type="submit" value="Vote" /></form>';
}
?>


<?php
echo $note;

?></center></div>
<?php include 'assets/templates/overall/overallFoot.php'; ?>

 

and Here's mysql code:

 

CREATE TABLE IF NOT EXISTS `id` (
  `ID` int(255) NOT NULL,
  `ip` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `edate` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `Name` varchar(255) COLLATE latin1_general_ci NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

 

Link to comment
https://forums.phpfreaks.com/topic/275834-duplicate-entry-0-for-key-primary/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.