0
<div class="container">
        <form action="" method="post" class="row mt-4 g-3">
            <div class="col-6">
                <label for="ad" class="form-label">Yazar Adı</label>
                <input type="text" class="form-control" name="ad">
            </div>
            <div class="col-6">
                <label for="sad" class="form-label">Instagram</label>
                <input type="text" class="form-control" name="sad">
            </div>
            <div class="col-6">
                <label for="dtarih" class="form-label">Katılma Tarihi</label>
                <input type="date" class="form-control" name="dtarih">
            </div>

            <div class="col-6">
                <label for="sinif" class="form-label">Fotoğraf</label>
                <input type="file" class="form-control" name="sinif">
            </div>
      
            <div class="col"> Alanı:
                <label for="" class="form-label">Kişisel Gelişim
                    <input type="radio" name="cins" value="K">
                </label>
                <label for="" class="form-label">Spritualizm
                    <input type="radio" name="cins" value="E">
                </label>
            </div>
            <button type="submit" name="kaydet" class="btn btn-primary">Kaydet</button>
        </form>
    </div>
    </main>

    <?php
    if($_POST['kaydet']) // Gönder butonuna basılmışsa 
    {   
        include "baglan.php";

        $yazaradi=$_POST['yazaradi'];
        $alani=$_POST['alani'];
        $instaadres=$_POST['instaadres'];
        $katilma_tarihi=$_POST['katilma_tarihi'];
        $fotograf=$_POST['fotograf'];

        $sorgu=$baglan->prepare("INSERT INTO yazarlar SET 
            yazaradi = ?,
            alani = ?,
            instaadres = ?,
            katilma_tarihi = ?,
            fotograf = ?
        ");

        $kaydet = $sorgu->execute(array($yazaradi,$alani,$instaadres,$katilma_tarihi,$fotograf));

        if ($kaydet)
            echo "Bilgiler Kaydedildi";
        else    
            echo "Kayıt Sırasında Hata oluştu";
    }
    ?>

I tried lot of things but I can't solve the problem. The error is:

Warning: Undefined array key "katilma_tarihi" in ... on line 53 ( ! )

Warning: Undefined array key "instaadres" in ... on line 52

etc. And it's erroring not for 2 ids, it keeps erroring every id. I want to save the data.

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • 3
    `and there's no reason`...there's always a reason. PHP can't lie to you. If (as it seems) you start from the assumption that your code must be correct, then you're not going to succeed in solving the problem. – ADyson May 03 '23 at 12:19
  • You don't show your form, but look at it and make sure that there are inputs named with those missing array keys within the form. – aynber May 03 '23 at 12:19
  • `print_r($_POST)` gives what? `if($_POST['kaydet'])` should also use an `isset` or `empty` check otherwise that too can throw the notice. – user3783243 May 03 '23 at 12:20
  • Anyway clearly the problem is that $_POST doesn't contain any entry called "katilma_tarihi" or "instaadres". That will be because whatever submitted the POST data to PHP didn't include any items with those names in the data. Did you submit the data to PHP through a HTML form, perhaps? Or a JS/AJAX request? Or maybe you're testing it via Postman, for example? We don't know, but you need to go and look at the client-side code to find the problem. If you need more help with it, post that code here so that we've got a [mre] of the issue, but I doubt it will be hard to find, once you start looking. – ADyson May 03 '23 at 12:21
  • If "every id" means your HTML has these as `id`s not `name`s that would be an issue. Need to see HTML. – user3783243 May 03 '23 at 12:22
  • 1
    Thanks for adding the HTML. As we suspected, there are no fields named katilma_tarihi or instaadres in the HTML form. Where do you _expect_ that these values would come from, and why? – ADyson May 03 '23 at 12:23
  • i'm sorry everyone i forgot to add html codes :( thanks :(( – hande korkmaz May 03 '23 at 12:24
  • P.S. `i tried everything on internet`...please don't make outlandish and absurd claims...it adds nothing to your question and is just a distraction. Clearly you didn't try "everything on the internet" because 1) that would take more than your lifetime and 2) if you had, you'd have solved it, because lots of people have asked about the same error before, and received the same kind of answers. And it doesn't give us any information about what you actually _did_ try in reality. :-) – ADyson May 03 '23 at 12:25
  • 1
    Unrelated fyi: the `for` attribute on a label should point to an `id` of the related element. (You don't use `id`s) – brombeer May 03 '23 at 12:29
  • 1
    That's great. So how did you solve it? – ADyson May 03 '23 at 12:31
  • 1
    Looks like typo name attribute for `katilma_tarihi` appears to be `dtarih`. – user3783243 May 03 '23 at 12:53
  • @user3783243 maybe. and the instaadres? – ADyson May 03 '23 at 12:57
  • 1
    Probably `instaadres ` is `instagram` so `name="sad ` – user3783243 May 03 '23 at 13:04

0 Answers0