...

View Full Version : error message: "#1062 - Duplicate entry '1' for key 1"



grandgefx
01-11-2012, 02:52 AM
Hi everyone
So I wanted to add a 'phone number' column in my inbox page
I went to MySQL database and phpMyadmin to make some changes, what I did was go to the table and

http://img341.imageshack.us/img341/5886/10954064.jpg
click on change (the pencil icon)

then I go to insert new row and click go
http://img687.imageshack.us/img687/9551/15161045.jpg

and it generate error message: "#1062 - Duplicate entry '1' for key 1"
and id_member column appear in the table

then I delete the the id_member column but it generated error when I tried to send the message

and I tried to make some changes but it messes up even more, now everytime I click on send message or kirim pesan (in my language) the data goes to the database but it nothing appear on my inbox

This is my send message box:
http://img545.imageshack.us/img545/5125/46927834.jpg

this is the php coding:

<?php
if($kirim=="ya")
{
$anton->generatetanggal();
$ip=$_SERVER['REMOTE_ADDR'];
$s="select * from `inbox` where `tgl` like '$fulldate' and `alamat_ip` like '$ip'";
$anton->kueridb($s);
$jum=0;
while($r=mysql_fetch_row($hasil))
{
$jum++;
}
if($jum<20)
{

$dari=strip_tags($dari);
$subjek=strip_tags($subjek);
$pesan=strip_tags($pesan);

$s="INSERT INTO `inbox` (
`id` ,
`dari` ,
`subjek` ,
`pesan` ,
`id_member` ,
`tgl` ,
`desc` ,
`alamat_ip`
)
VALUES (
NULL , '$dari', '$subjek', '$pesan', '$fulldate', 'id_member', '-', '$ip'
)";
$anton->kueridb($s);
if($hasil)
{

echo "<center><br><b>Data pesan Anda telah terkirim ke member tersebut ! </b></center>";
}

}


}
else
{
?>
<form action=?page=kirim_pesan&id_member=<?php echo $id_member;?>&kirim=ya method=post>
<br><br>
<table cellspacing=0 align=center bgcolor=#C4C4C4>
<TR><TD colspan=2 class=head>Kirimkan Pesan ke Pemasang Iklan</TD></TR>
<tr><TD class=x>Nama Anda</TD><TD class=x><input type=text name=dari size=22></TD></tr>
<tr><TD class=x>Subjek</TD><TD class=x><input type=text name=subjek size=22></TD></tr>
<tr><TD class=x valign=top>Pesan Anda</TD><TD class=x>

<textarea name=pesan rows=7 cols=28></textarea>
</TD></tr>
<tr><TD class=x colspan=2 align=right>
<input type=submit value="Kirimkan Pesan">
</TD></tr>

</table>
<br>
</form>
<?php
}
?>

and this is the inbox
http://img829.imageshack.us/img829/8500/73107236.jpg

and this is the php coding to send the message to it

<?php
if(empty($_SESSION['rmember']))
{
echo "<center><br><b>Maaf untuk mengakses halaman ini silahkan <a href=?page=login>login</a> jika Anda sudah memiliki akun, jika Anda belum memiliki akun, silahkan <a href=?page=register>register</a></b></center>";
require_once("inc/login.php");

}
else
{

$rmember=$_SESSION['rmember'];
$rid=$_SESSION['rid'];

?>
<h3 align="left"><img align="left" alt="" src="images/tit.png" /> &nbsp; Kotak Pesan</h3>

<?php
if($aksi=="delete")
{
$s="select * from `inbox` where `id` like '$id'";
$anton->kueridb($s);
$r=mysql_fetch_row($hasil);
$id_member=$r[5];
if($id_member==$rid)
{
$s="delete from `inbox` where `id` like '$id'";
$anton->kueridb($s);

}
}

$s="select * from `inbox` where `id_member` like '$rid'";
$anton->kueridb($s);
echo "<table align=center>
<tr>
<td class=head>Tanggal</td>
<td class=head>Pengirim</td>
<td class=head>Subjek</td>
<td class=head>Pesan</td>
<td class=head>Hapus</td>
</tr>
";
while($r=mysql_fetch_row($hasil))
{
echo "
<tr>
<td class=x valign=top>$r[4]</td>
<td class=x valign=top>$r[1]</td>
<td class=x valign=top>$r[2]</td>
<td class=x valign=top>$r[3]</td>
<td class=x valign=top><a href=?page=inbox&aksi=delete&id=$r[0]>Hapus</a></td>


</tr>
";

}
echo "</table><br><br><br><br><br><br><br><br><br><br><br><br>";
}
?>


and this is the php coding for the "inbox" where the message should be appear, can you spot any inconsistency with those 3 php codes?

<?php
if(empty($_SESSION['rmember']))
{
echo "<center><br><b>Maaf untuk mengakses halaman ini silahkan <a href=?page=login>login</a> jika Anda sudah memiliki akun, jika Anda belum memiliki akun, silahkan <a href=?page=register>register</a></b></center>";
require_once("inc/login.php");

}
else
{

$rmember=$_SESSION['rmember'];
$rid=$_SESSION['rid'];

?>
<h3 align="left"><img align="left" alt="" src="images/tit.png" /> &nbsp; Kotak Pesan</h3>

<?php
if($aksi=="delete")
{
$s="select * from `inbox` where `id` like '$id'";
$anton->kueridb($s);
$r=mysql_fetch_row($hasil);
$id_member=$r[5];
if($id_member==$rid)
{
$s="delete from `inbox` where `id` like '$id'";
$anton->kueridb($s);

}
}

$s="select * from `inbox` where `id_member` like '$rid'";
$anton->kueridb($s);
echo "<table align=center>
<tr>
<td class=head>Tanggal</td>
<td class=head>Pengirim</td>
<td class=head>Subjek</td>
<td class=head>Pesan</td>
<td class=head>Hapus</td>
</tr>
";
while($r=mysql_fetch_row($hasil))
{
echo "
<tr>
<td class=x valign=top>$r[4]</td>
<td class=x valign=top>$r[1]</td>
<td class=x valign=top>$r[2]</td>
<td class=x valign=top>$r[3]</td>
<td class=x valign=top><a href=?page=inbox&aksi=delete&id=$r[0]>Hapus</a></td>


</tr>
";

}
echo "</table><br><br><br><br><br><br><br><br><br><br><br><br>";
}
?>


everything starting to get mess up after I did "set as new row" which gave me an error message: "#1062 - Duplicate entry '1' for key 1" what does it mean?

http://img687.imageshack.us/img687/9551/15161045.jpg

and then a new column (id_member)appears on the table, which I then deleted it, but it gave me an error message on the inbox about missing id_member field, so I have to add it back tot the table (it wasn't there before).

Before the table has no "id_member" column but after I "set as new row" and get "#1062 - Duplicate entry '1' for key 1"" I have to add the id_member column to the table or the inbox give me error message about missing id_member filed

sorry for asking too much, cause I'm very new to this, I didn't create the website, so I have no idea about the coding, etc. just wanted to add 1 column.

How do the "id_member" colum get added to the table? and since I delete it soon after, I have no idea about its configuration (INT, or TEXT, etc.) but since the inbox page keep asking me to add "id_member" ever since so I have to add it to the table.

I did deleted the "id_member" from php code, because I thought it was added by the database accidently, but then I put the "id_member" back to the code since otherwise the inbox page give me error message

Sorry for my english, and long post but I try to explain it as clear as possible.

thanks

abduraooft
01-11-2012, 09:50 AM
Please post your table schema (structure)

grandgefx
01-11-2012, 10:28 AM
Please post your table schema (structure)

Hi, thank for the response
here is my table scheme:
http://img545.imageshack.us/img545/9237/53438721.jpg
http://img189.imageshack.us/img189/6849/28834757.jpg

when I type in something on the message box and send it, it shows up on the table (phpMyadmin/Mysql)
http://img141.imageshack.us/img141/8127/92679692.jpg

but nothing show up on the inbox page
http://img546.imageshack.us/img546/3473/72601982.jpg

when I type in something on the "message box" and click on "kirim pesan" or "send message"
http://img62.imageshack.us/img62/5484/46145714.jpg

it suppose to show up on inbox page...

but now nothing show up...is there any inconsistency with the php code...I did not write the code, but I did change a few thing that I probably unaware of, and now it mess up

the "id_member" wasn't there before but I have to add it since I mess up with table before, now the date is "id_member"

abduraooft
01-11-2012, 10:37 AM
Please post the textual version, not the screen shot. You may get it from the tab named "Structure"

grandgefx
01-11-2012, 11:08 AM
Hi this is the table structure print version that I copied paste it

Server: localhost - Database: k2870636_ember - Table: inbox "InnoDB free: 8192 kB"
inbox
Table comments: InnoDB free: 8192 kB

Field------- Type -----------Null Default Comments
id---------- int(11)----------No
dari---------tinytext --------No
subjek------tinytext ---------No
pesan-------text-------------No
id_member---int(11)----------No
tgl-----------tinytext --------No
desc --------tinytext --------No
alamat_ip ----tinytext --------No

Indexes: Documentation
Keyname Type Unique Packed Field Cardinality Collation Null Comment
PRIMARY BTREE Yes No id 2 A


Space usage:
Type Usage
Data 16,384 B
Index 0 B
Total 16,384 B
Row Statistics:
Statements Value
Format Compact
Rows 2
Row length 8,192
Row size 8,192 B
Next Autoindex 3
Creation Jan 11, 2012 at 09:24 AM

Open new phpMyAdmin windowOpen new phpMyAdmin window

grandgefx
01-12-2012, 03:58 PM
Hi, this is how I setup my table

id <-- BIGINT, NOT NULL (theres no NOT NULL choice, so I pick NONE), AUTO_INCREMENT <-- PRIMARY INDEX
id_member <-- BIGINT, NOT NULL (same here, I pick NONE) <-- INDEX
tgl <-- DATETIME
dari
alamat_ip
subjek
pesan

but the result for tgl or date is : 0000-00-00 00:00:00
see the image:
http://img405.imageshack.us/img405/920/11993353.jpg

and when it showed up on inbox page:
http://img259.imageshack.us/img259/263/36692968.jpg

the date or tanggal is 4, which is the id_member.... can you help me figure out what is wrong?
this is the php code for send message, I don't want to change the code too much since I'm not the writer of this code, and it used to work. Maybe there is something inconsistency with the code, such as comma, or some missing line

<?php
if($kirim=="ya")
{
$anton->generatetanggal();
$ip=$_SERVER['REMOTE_ADDR'];
$s="select * from `inbox` where `tgl` like '$fulldate' and `alamat_ip` like '$ip'";
$anton->kueridb($s);
$jum=0;
while($r=mysql_fetch_row($hasil))
{
$jum++;
}
if($jum<20)
{
$dari=strip_tags($dari);
$subjek=strip_tags($subjek);
$pesan=strip_tags($pesan);

$s="INSERT INTO `inbox` (
`id` ,
`dari` ,
`subjek` ,
`pesan` ,
`tgl` ,
`id_member` ,
`desc` ,
`alamat_ip`
)
VALUES (
NULL, '$dari', '$subjek', '$pesan', '$fulldate', '$id_member', '-', '$ip'
)";
$anton->kueridb($s);
if($hasil)
{

echo "<center><br><b>Data pesan Anda telah terkirim ke member tersebut ! </b></center>";
}

}


}
else
{
?>
<form action=?page=kirim_pesan&id_member=<?php echo $id_member;?>&kirim=ya method=post>
<br><br>
<table cellspacing=0 align=center bgcolor=#C4C4C4>
<TR><TD colspan=2 class=head>Kirimkan Pesan ke Pemasang Iklan</TD></TR>
<tr><TD class=x>Nama Anda</TD><TD class=x><input type=text name=dari size=22></TD></tr>
<tr><TD class=x>Subjek</TD><TD class=x><input type=text name=subjek size=22></TD></tr>
<tr><TD class=x valign=top>Pesan Anda</TD><TD class=x>

<textarea name=pesan rows=7 cols=28></textarea>
</TD></tr>
<tr><TD class=x colspan=2 align=right>
<input type=submit value="Kirimkan Pesan">
</TD></tr>

</table>
<br>
</form>
<?php
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum