1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simple: Passing PHP var into SQL fails MySqli query

Discussion in 'Programming/Internet' started by Chenelle, Sep 12, 2018.

  1. Chenelle

    Chenelle Guest

    After reading through stackoverflow for a few hours and trying various suggestions I can't seem to get a simple sql statement to work.

    I am using the latest XAMPP localhost with Apache for PHP and MySQL.


    id | name | transaction |

    1 | David | 1234V |

    In PhpMyAdmin, the following non variable sql returns 1 rows. However, the variable sql returns a nonfunctional resource.

    I've tried various re-arrangements of the sql statement and syntaxes for the $mysqli->query();

    Am I missing something in php.ini or something?

    $trans = "SELECT * FROM `name` WHERE `transaction` = '{$passed[variable]}'";

    if($statement = $mysqli->prepare("$trans")){

    while ($statement->fetch()) {
    printf("%s %s\n",$id,$name,$transaction);


    This new code printed nothing.

    Login To add answer/comment

Share This Page