Jump to content

Variables not retrieved properly.


Kimochi

Recommended Posts

Please look at the following code.

 

function product_differs($model, $quantity, $price)
{
	echo $price.'<br />';
	$q = 'SELECT * FROM `products` WHERE `products_model`="'.addslashes($model).'" AND `products_quantity`='.$quantity.' AND `products_price`='.$price;
	$differs_query = mysql_query($q) or die(mysql_error().' - '.$q);
	if(mysql_num_rows($differs_query) == 0)
	{
		$old_query = mysql_query('SELECT * FROM `products`,`products_description` WHERE `products`.products_model="'.addslashes($model).'" AND `products`.products_id=`products_description`.products_id') or die(mysql_error().'3');
		return mysql_fetch_array($old_query);
	}
	else return false;
}

 

When I run this code with a variable I know to contain ">5", it gets echoed as 1 on the "echo $price.'<br />';" line, then the mysql_query uses the value ">5" which causes an SQL error (I cannot remove the ">", as when I use functions to do so the variable gets read as "1"), and then when I echo $q with the die() function I get a value of 1 again. This happens with the $price variable outside this function. It is retrieved from a text file.

 

Any idea what's going on?

Link to comment
https://forums.phpfreaks.com/topic/120996-variables-not-retrieved-properly/
Share on other sites

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.