0

my code partially works in ELSE part below. What I mean partially is it doesn't INSERT INTO table but since all verification stages are correct, it redirects to thanks page.

What I normally expect is both. Insert into table A N D then go to thanks page.

I thought my situation is about the prepared statement so I studied http://php.net/manual/en/mysqli.quickstart.prepared-statements.php but I couldn't solve my case. I am getting NO notice, warning or error. but my table is still empty. Can you help with my fault(s) please?

Thanks

BR

    header( "HTTP/1.1 303 See Other" );

if ($_SESSION['hatalar'] != '')
{
    $sonraki_sayfa = sitenin_koku.'yazılar/'.$_SESSION['spesifik_yazi_url'];
    header('Location: ' . $sonraki_sayfa);
}
else //verification passed. save the comment + redirect to thanks page.
{
    /* YORUMU TABLOYA YAZDIRALIM  */
    $sorgum = "INSERT INTO tb_yorumlar (kolon_yorumcu_isim, kolon_statu, kolon_yorum, kolon_hangi_yazara, kolon_hangi_basliga, kolon_yorum_tarihi, kolon_ip) VALUES (?, ?, ?, ?, ?, NOW(), ?)";

    if ($beyan = $db_baglanti->prepare($sorgum)) 
        {
            /* give their values to parameters  */ 
            $bindparametre1 = $_POST['yf-isim'];
            $bindparametre2 = 'onay';
            $bindparametre3 = $_POST['yf-mesaj'];
            $bindparametre4 = $_SESSION['spesifik_yazi_yazar'];
            $bindparametre5 = $_SESSION['spesifik_yazi_baslik'];
            $bindparametre6 = $_SERVER['REMOTE_ADDR'];

            /* bind parameters */
            if (!$beyan -> bind_param("ssssss", $bindparametre1, $bindparametre2, $bindparametre3, $bindparametre4, $bindparametre5, $bindparametre6))
            {echo "parametre atama hatası: (" . $beyan->errno . ") " . $beyan->error;}

            /* execute statement */
            if (!$beyan->execute())
            {echo "Gerçekleştirme hatası: (" . $beyan->errno . ") " . $beyan->error ;}
        }
    else {echo "Hazırlama hatası: (" . $db_baglanti->errno . ") " . $db_baglanti->error;}

    /* TEŞEKKÜR SAYFASINA YÖNLENDİRELİM */
    $sonraki_sayfa = sitenin_koku.'yorumunuz-için-teşekkür-ederim';
    header('Location: ' . $sonraki_sayfa);

}
6
  • What is the structure of the table you're inserting into Commented Mar 24, 2013 at 21:40
  • is there any short sql command to paste the result because my table is a little bit long to write Commented Mar 24, 2013 at 21:42
  • Are you sure the variables are all being assigned values? Commented Mar 24, 2013 at 21:43
  • I couldn't understand. If not assigned, then how can I insert the specific right values Commented Mar 24, 2013 at 21:46
  • Check my answer - I think you may be dealing with some null values here. The code looks fine. Commented Mar 24, 2013 at 21:49

1 Answer 1

1

I would comment out the header location part (see below) and echo out the values - make sure that the values you're inserting are actually filled (not null).

if ($beyan = $db_baglanti->prepare($sorgum)) {
    /* give their values to parameters  */
    $bindparametre1 = $_POST['yf-isim'];
    $bindparametre2 = 'onay';
    $bindparametre3 = $_POST['yf-mesaj'];
    $bindparametre4 = $_SESSION['spesifik_yazi_yazar'];
    $bindparametre5 = $_SESSION['spesifik_yazi_baslik'];
    $bindparametre6 = $_SERVER['REMOTE_ADDR'];

    if (!$beyan->bind_param("ssssss", $bindparametre1, $bindparametre2, $bindparametre3, $bindparametre4, $bindparametre5, $bindparametre6)) {
        echo "parametre atama hatas?: (" . $beyan->errno . ") " . $beyan->error;
    }

    if (!$beyan->execute()) {
        echo "Gerçekles,tirme hatas?: (" . $beyan->errno . ") " . $beyan->error ;
    }
}
else {
    echo "Haz?rlama hatas?: (" . $db_baglanti->errno . ") " . $db_baglanti->error;
}

/* TES,EKKÜR SAYFASINA YÖNLENDI.RELI.M */
$sonraki_sayfa = sitenin_koku.'yorumunuz-için-tes,ekkür-ederim';
//header('Location: ' . $sonraki_sayfa);

echo $bindparametre1 . "<br>";
echo $bindparametre2 . "<br>";
echo $bindparametre3  . "<br>";
echo $bindparametre4  . "<br>";
echo $bindparametre5  . "<br>";
echo $bindparametre6  . "<br>";
Sign up to request clarification or add additional context in comments.

6 Comments

after I tried, 2 notices and 1 error. Error is (1048) Column 'kolon_hangi_yazara' cannot be null. AND 2 notices=> notice 1: Undefined index: spesifik_yazi_yazar in ... on line 85 . Notice 2: Undefined index: spesifik_yazi_baslik in ... on line 86
@AndreChenier Make sure you add session_start() to the top of any PHP page where you want to use $_SESSION variables
it is strange because I already started session. If I again add top of page the session_start(), page gives Notice: A session had already been started.
@AndreChenier Right, you don't want it more than once. I was just making sure you had it. So, it seems as though you have some null parameters (that is what I had thought). Go back to your other pages and make sure your SESSION vars are being set properly
so I have to find out why my session variables are null. Thank you Evan.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.