Support » Plugins » Hacks » MySQL query returns null when ran from template file

  • Hello all,

    Okay i have a template file which im using for some customer PHP code but for some reason my mysql query keeps returning null where it shouldn’t. Can anyone see why??

    Heres the code?

    // Database variables
    DEFINE ('DB_USER', 'test');
    DEFINE ('DB_PASSWORD', 'test');
    DEFINE ('DB_HOST', 'localhost');
    DEFINE ('DB_NAME', 'testdatabase');
    // Make the connection
    $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
    $q = "SELECT * FROM <code>test</code>";
    $result = mysqli_query($dbc, $q);
    if(mysqli_num_rows($result)==0){
     echo"No results<br>";
    }
    echo"Start<br>";
    if($result)
    {
     while ($row = $result->fetch_assoc())
     {
     $test = $row['email'];
     echo"result: $test";
     }
    }
    echo"<br>End<br>";
    mysqli_close($dbc);

    Are you even able to make mysql querys from templates?

    Thanks

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I can’t imagine why you couldn’t do this from a template, but I haven’t done this, so I could be wrong.

    Do you really have a table named “test“? Seems rather unlikely, which would explain why you are not getting anything returned.

Viewing 1 replies (of 1 total)
  • The topic ‘MySQL query returns null when ran from template file’ is closed to new replies.