SennNathan Posted November 2, 2014 Share Posted November 2, 2014 This is my code it always returns null i know that there is info in the table but it never works $sql = 'SELECT * FROM $user WHERE ticker = "$ticker"'; $resultsql = mysqli_query($conp,$sql); $row = mysqli_fetch_array($resultsql); echo $row[ticker]; var_dump($row); echo '<br>'; Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted November 2, 2014 Solution Share Posted November 2, 2014 unless you have a database table named, literally, $user, with the $ as part of the table name, your query is failing due to an error. 1) you need to ALWAYS test if your queries have actually ran without any errors before you try to use any of the data from your query. mysqli_query() will return a false value, that can be tested, when the query has failed due to an error. you can use msyqli_error($conp) to find out what the actual error with the sql query statement is. 2) if $user and $ticker are php variables, php variables are NOT parsed and replaced with their value when used inside of overall single-quoted strings. you would need to use double-quotes around the $sql = "..."; string to get php variables inside the string to be replaced with their value. 3) you should also use single-quotes around the '$ticker' variable, since double-quotes inside of an sql query statement can be configured to mean they indicate a column name, whereas single-quotes inside of a msyql query statement will always mean a literal siting value. 4) you should have php's error_reporting set to E_ALL and display_errors set to ON to get php to help you. the mysqli_fetch_array() statement, along with the $row references, are throwing php errors to alert you to the fact that the query failed due to an error. Quote Link to comment Share on other sites More sharing options...
SennNathan Posted November 2, 2014 Author Share Posted November 2, 2014 Thanks for the help this works $resultsql = mysqli_query($conp,"SELECT * FROM ".$user." WHERE ticker = '".$ticker."'"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.