-3

I am in prototype stage with my site.

Since prepared statements are more secure & the new way to talk with mysql db, I decided to use them and read the related sections in php.net but all examples in php.net are given with placeholders like where name = ?.

Below I need no placeholder I suppose but I couldn't achieve printing my output.

I have no output from my db.

I have notices that are:

Notice: Undefined variable: row in ... on line 16
Notice: Undefined variable: row in ... on line 16
Notice: Undefined variable: row in ... on line 16
Notice: Undefined variable: row in ... on line 16

What should I do? Can you help me please.

Thank you, regards

in my index.php

//mysql bağlantısı
    global $db_baglanti;
    $db_baglanti = new mysqli(vt_host, vt_user, vt_password, vt_name);
    if ($db_baglanti->connect_errno) 
    {
        echo "MySQL bağlantısı kurulamadı: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }

    if (!$db_baglanti->set_charset("utf8")) 
    {
        printf("utf8 karakter setinin yüklenmesinde problem oluştu: %s\n", $db_baglanti->error);
    } 
    else 
    {
        $db_baglanti->set_charset("utf8");
    }

in an included page

$sorgum = "SELECT kolon_baslik, kolon_yazi FROM tb_yazilar";


if ($beyan = $db_baglanti->prepare($sorgum)) 
{

    /* execute statement */
    $beyan->execute();



    /* fetch values */
    while ($beyan->fetch()) {
        echo $row['kolon_baslik'].'<br /><br />'.$row['kolon_yazi'].'<br /><br />';
    }

    /* close statement */
    $beyan->close();
}
Wes Cossick
  • 2,923
  • 2
  • 20
  • 35
Andre Chenier
  • 1,166
  • 2
  • 18
  • 37
  • This [PHP error reference](http://stackoverflow.com/q/12769982/367456) might be of help for you. – hakre Mar 10 '13 at 13:46

2 Answers2

0

From the almighty manual: http://www.php.net/manual/en/mysqli-stmt.fetch.php

Note that all columns must be bound by the application before calling mysqli_stmt_fetch().

and from the first example:

/* execute statement */
$stmt->execute();

/* bind result variables */
$stmt->bind_result($name, $code);

/* fetch values */
while ($stmt->fetch()) {
    printf ("%s (%s)\n", $name, $code);
}

What you are missing is $beyan->bind_result($kolon_baslik, $kolon_yazi); and use these variables instead of nonexistent $row array.

dev-null-dweller
  • 29,274
  • 3
  • 65
  • 85
0

thanks, I found answer at this link: http://php.net/manual/en/mysqli-stmt.fetch.php.

Working code is:

if ($beyan = $db_baglanti->prepare($sorgum)) 
{

    /* execute statement */
    $beyan->execute();

    /* bind result variables */
    $beyan->bind_result($name, $code);

    /* fetch values */
    while ($beyan->fetch()) {
        //printf ("%s (%s)\n", $name, $code)
        echo $name.'<br /><br />'.$code.'<br /><br />';
    }

    /* close statement */
    $beyan->close();
}

I learnt that I have to bind mysql results to variables and then I print that binded variables values. related code is: $beyan->bind_result($name, $code);

Andre Chenier
  • 1,166
  • 2
  • 18
  • 37