grlayouts Posted April 23, 2007 Share Posted April 23, 2007 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 More sharing options...
sanfly Posted April 23, 2007 Share Posted April 23, 2007 In your tagboard table, what are the characteristics of the id field? eg: is it the primary key? Autoincrement? Link to comment https://forums.phpfreaks.com/topic/48375-duplicate-entry-0-for-key-1/#findComment-236499 Share on other sites More sharing options...
grlayouts Posted April 23, 2007 Author Share Posted April 23, 2007 yeah aint got the auto increment on.. but also its not posting properly, the comments are coming up blank. Link to comment https://forums.phpfreaks.com/topic/48375-duplicate-entry-0-for-key-1/#findComment-236502 Share on other sites More sharing options...
sanfly Posted April 23, 2007 Share Posted April 23, 2007 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. Link to comment https://forums.phpfreaks.com/topic/48375-duplicate-entry-0-for-key-1/#findComment-236503 Share on other sites More sharing options...
grlayouts Posted April 24, 2007 Author Share Posted April 24, 2007 i keep getting please fill in all fields. Link to comment https://forums.phpfreaks.com/topic/48375-duplicate-entry-0-for-key-1/#findComment-236512 Share on other sites More sharing options...
sanfly Posted April 24, 2007 Share Posted April 24, 2007 Hmmm, Well, it should be something along the lines of if(!$_POST['post']) rather than ($post = '') BUT, im not sure you can use the field name post, you may need to try changing it to 'message' or 'thePost' or something Link to comment https://forums.phpfreaks.com/topic/48375-duplicate-entry-0-for-key-1/#findComment-236518 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.