I just want to insert one row with my form but MySQL is showing 3 rows, one of them is mine and two of them is just null.
Here is my code.
Form
<form method="post" id="contactform" action="iletisim-basarili.php">
<input type="text" name="isim" placeholder="İsim" class="formcontact"><br>
<input type="text" name="soyisim" placeholder="Soyisim" class="formcontact"><br>
<input type="text" name="telefon" placeholder="Telefon Numarası" class="formcontact"><br>
<input type="text" name="eposta" id="eposta" placeholder="E-Posta Adresi" class="formcontact"><br>
<input type="text" name="konu" id="konu" placeholder="Konu" class="formcontact"><br>
<textarea type="text" name="mesaj" id="mesaj" rows="8" placeholder="Mesajınız" class="form--contact--textarea"></textarea><br>
<div class="validred"></div><br>
<input type="submit" name="submit" class="button-form" value="Formu Gönder" />
</form>
PHP
<?php
require ('config.php');
$isim = trim( $_POST['isim']);
$soyisim = trim( $_POST['soyisim']);
$telefon = trim( $_POST['telefon']);
$eposta = trim( $_POST['eposta']);
$konu = trim( $_POST['konu']);
$mesaj = trim( $_POST['mesaj']);
$kaydet = mysql_query( "INSERT INTO contact SET
isim = '$isim',
soyisim = '$soyisim',
telefon = '$telefon',
eposta = '$eposta',
konu = '$konu',
mesaj = '$mesaj'
");
if( mysql_affected_rows()) {
echo "<h3 class='green'>destek talebini kaydettik.</h3><br><h4 class='text'>en kısa sürede"." <b>$destekmail</b>"." üzerinden seninle iletişime geçeceğimizden hiç şüphen olmasın.</h4>";
}
?>
This is function check wather submit button press or its self posted page.So you need to check for submit button.
<?php
require ('config.php');
//Check before form is submitted.
if(isset($_POST['submit'])){
$isim = trim( $_POST['isim']);
$soyisim = trim( $_POST['soyisim']);
$telefon = trim( $_POST['telefon']);
$eposta = trim( $_POST['eposta']);
$konu = trim( $_POST['konu']);
$mesaj = trim( $_POST['mesaj']);
$kaydet = mysql_query( "INSERT INTO contact SET
isim = '$isim',
soyisim = '$soyisim',
telefon = '$telefon',
eposta = '$eposta',
konu = '$konu',
mesaj = '$mesaj'
");
if( mysql_affected_rows()) {
echo "<h3 class='green'>destek talebini kaydettik.</h3><br><h4 class='text'>en kısa sürede"." <b>$destekmail</b>"." üzerinden seninle iletişime geçeceğimizden hiç şüphen olmasın.</h4>";
}
}
?>