Jump to content

Duplicate entry '0' for key 1


grlayouts

Recommended Posts

Duplicate entry '0' for key 1

 

any idea what that means? the code i have is

 

<?php 
// include config file
$todo='SELECT * FROM `tagboard` order by id desc LIMIT 50'; 
$solution=mysql_query($todo); 
while ($place = mysql_fetch_array($solution)) 
{ 
$id=$place["id"]; 
$comments=$place["comments"]; 
?> 
<b><? echo "$place[name]"; ?></b><? echo ": $comments<br>" ; ?> 
<? 
}?> 

 

<?php 
if ($post = '') 
{ 
die ("Please fill all fields. Click <a HREF=../stats.php>here</a> to return."); 
} 
$comments = "$post"; 


//include config file
$todo="INSERT INTO tagboard (id,name,comments,date) VALUES('','$user','$comments',now())"; 
$solution = mysql_query($todo) or die (mysql_error()); 
if ($solution) 
{ 
?> 
<meta http-equiv="refresh" content="0;url=../stats.php" > 
<? 
} ?>

 

and the form

 


<iframe src="chat/view.php" name="tag" width="179" height="130" frameborder=0 marginwidth="0" marginheight="0"></iframe>
	<form method="POST" ACTION="chat/todo.php">
	<? $name = $stat[user] ?>
          <textarea NAME="post" cols="27" rows="3"></textarea> 
<br> 
<input TYPE="submit" value="Submit"></form>

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

Well, if you have the ID set as primary key, then you cant have two ids that are the same.  In your script you set the ID for all as '' (or empty).

 

I would recommend setting the id to auto increment, then in your insert query:

 

$todo="INSERT INTO tagboard (name,comments,date) VALUES('$user','$comments',now())";

 

If you have the id as primary key and set to autoincrement, you dont need to define it in the insert query.

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.