Page 1 of 1

Duplicate entries in mySQL

Posted: Mon Mar 24, 2014 7:22 pm
by nukleus011
I'm trying to make a code to verify that the entry exists for the user name (kl_korisnicko_ime), but somewhere wrong. Help me!

Code: Select all

<?php
 if(isset($_POST['submit']))
    {
    	$kl_korisnicko_ime= $_POST['kl_korisnicko_ime'];
$dbc=mysqli_connect("localhost","root","123","stamparija");
 $check=mysqli_query($dbc,"select * from clients where kl_korisnicko_ime='$kl_korisnicko_ime'");
   $checkrows=mysqli_num_rows($check);
   if($checkrows>0){echo "Klijent postoji.";}  
else{  
    //insert results from the form input
    $query = "INSERT IGNORE INTO klijenti(kl_korisnicko_ime) VALUES('$kl_korisnicko_ime')";

    $result = mysqli_query($dbc, $query) or die('Error querying database.');

    mysqli_close($dbc);
    }
    echo "Klijent dodan u bazu.";};

$query="INSERT INTO klijenti (kl_korisnicko_ime, kl_sifra, kl_naziv_firme, kl_adresa_firme, kl_br_telefona_firme, kl_fax_firme, kl_mail_adresa_firme, kl_kontakt_osoba, kl_pozicija_u_firmi, kl_broj_telefona_kontakt_osoba, kl_mail_adresa_kontakt_osoba)
VALUES
('$_POST[kl_korisnicko_ime]','$_POST[kl_sifra]','$_POST[kl_naziv_firme]','$_POST[kl_adresa_firme]','$_POST[kl_br_telefona_firme]','$_POST[kl_fax_firme]','$_POST[kl_mail_adresa_firme]','$_POST[kl_kontakt_osoba]','$_POST[kl_pozicija_u_firmi]','$_POST[kl_broj_telefona_kontakt_osoba]','$_POST[kl_mail_adresa_kontakt_osoba]')";



?>

Re: Duplicate entries in mySQL

Posted: Mon Mar 24, 2014 8:54 pm
by Celauran
Could you elaborate on what's going wrong? What errors are you encountering?

Re: Duplicate entries in mySQL

Posted: Tue Mar 25, 2014 6:29 am
by nukleus011
There is no message after entering into a labels.


<html>
<body>


<form action="insert_kl.php" method="post" action='#' >
Korisničko ime:<label> <input type="text" name="kl_korisnicko_ime" required/></label>
Šifra: <label><input type="text" name="kl_sifra" required/></label>
Naziv firme: <label><input type="text" name="kl_naziv_firme" required/></label>
Adresa firme: <label><input type="text" name="kl_adresa_firme" required/></label>
Broj telefona firme:<label> <input type="text" name="kl_br_telefona_firme" required/></label>
Faks firme: <label><input type="text" name="kl_fax_firme" ></label>
E-mail firme:<label> <input type="text" name="kl_mail_adresa_firme" required/>></label>
Ime i prezime kontakt osobe:<label> <input type="text" name="kl_kontakt_osoba" required/>></label>
Pozicija u firmi: <label><input type="text" name="kl_pozicija_u_firmi" required/></label>
Broj telefona kontakt osobe:<label> <input type="text" name="kl_broj_telefona_kontakt_osoba" required/></label>
E-mail kontakt osobe:<label> <input type="text" name="kl_mail_adresa_kontakt_osoba" required/></label>
<input type="submit" value="pošalji">
</form>

</body>
</html>

Re: Duplicate entries in mySQL

Posted: Tue Mar 25, 2014 7:09 am
by Celauran
Do you have error reporting enabled? Have you checked your PHP logs? Have you checked mysqli_error()? "It doesn't work" really doesn't give us anything to work with.