0

I'm trying to insert a duplicate primary key in my signup page, its supposed to show an error saying I've already signed up, but it gives the duplicate entry error instead, do note that my primary key isn't auto incremented (most solutions are suggesting to do this) as the user needs to give their own id (similar to an identification card, where all the numbers are accustomed to one person only)

this is my current database

the idpeserta is my current primary key, and im trying to insert the same one on my signup page.even when all the other details are different except idpeserta, it still will give the duplicate entry error like this

My code is as below

 if (isset($_POST['id'])) {
    $idpeserta = $_POST['id'];
    $nama = $_POST['nama'];
    $nomhp = $_POST['nomhp'];
    
    #MASUK REKOD KE DLM TABLE
    $daftar1= "INSERT INTO peserta (idpeserta,nama,nomhp)
    VALUES ('$idpeserta','$nama','$nomhp')";
    
    #LAKSANA ARAHAN SQL
    $hasil1 = mysqli_query($con, $daftar1);
    
    #MESEJ JIKA BERJAYA
    if ($hasil1) {
      session_start();
      $_SESSION["idpeserta"]=$idpeserta;
      echo "<script>alert('Pendaftaran berjaya');
      window.location='dashboard.php'</script>";
      } else {
      echo "<script>alert('Pendaftaran gagal, Anda Mungkin sudah mendaftar');
      window.location='index.php'</script>";
    }
  }

is the } else { statement wrong ? should i replace it with something else ? any help would be appreciated

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Sidkey
  • 9
  • 1

0 Answers0