Jump to content

Php MySQL GET FROM WHERE problem.


SennNathan

Recommended Posts

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>';
Link to comment
https://forums.phpfreaks.com/topic/292225-php-mysql-get-from-where-problem/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.