Jump to content

Php MySQL GET FROM WHERE problem.


SennNathan
Go to solution Solved by mac_gyver,

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
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.