Duplicate entries in mySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nukleus011
Forum Newbie
Posts: 2
Joined: Mon Mar 24, 2014 6:54 pm

Duplicate entries in mySQL

Post 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]')";



?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Duplicate entries in mySQL

Post by Celauran »

Could you elaborate on what's going wrong? What errors are you encountering?
nukleus011
Forum Newbie
Posts: 2
Joined: Mon Mar 24, 2014 6:54 pm

Re: Duplicate entries in mySQL

Post 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>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Duplicate entries in mySQL

Post 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.
Post Reply