Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

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

    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


    click on change (the pencil icon)

    then I go to insert new row and click go


    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:


    this is the php coding:
    Code:
    <?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


    and this is the php coding to send the message to it
    Code:
    <?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?
    Code:
    <?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?



    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
    Last edited by grandgefx; 01-11-2012 at 06:40 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Please post your table schema (structure)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    grandgefx (01-12-2012)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Please post your table schema (structure)
    Hi, thank for the response
    here is my table scheme:



    when I type in something on the message box and send it, it shows up on the table (phpMyadmin/Mysql)


    but nothing show up on the inbox page


    when I type in something on the "message box" and click on "kirim pesan" or "send message"


    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"
    Last edited by grandgefx; 01-11-2012 at 11:34 AM.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Please post the textual version, not the screen shot. You may get it from the tab named "Structure"
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    grandgefx (01-12-2012)

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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

  • #6
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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:


    and when it showed up on inbox page:


    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
    Code:
    <?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
    }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •