Page 1 of 1

Need a little help, SQL PHP

Posted: Wed Oct 12, 2011 8:29 am
by aravona
I've got a query which runs fine except for 2 rows which are not being picked up.

The two with the problem have an & in the name.

This is the query:

Code: Select all

$name2 = wpsc_category_name();
							$query2 = "select id from wp_wpsc_product_categories where name = '" .$name2. "'";
							echo $query2;
				$result2 = mysql_query($query2);
				echo $result2;
				$category2 = mysql_fetch_array($result2);
				 echo $category2['id']; 
The issue is that the two category names with an ' & ' in are not being picked up.

Any ideas why this would be? As if I query:

[text]select * from wp_wpsc_product_categories where name = 'This & That'[/text]

The query runs fine in my phpmyadmin.

Help would be wonderful.

Kinda regards,

Aravona

Re: Need a little help, SQL PHP

Posted: Wed Oct 12, 2011 11:00 am
by AbraCadaver
Do: echo $query2; and then view the source in the browser. Does it say: This & That

Re: Need a little help, SQL PHP

Posted: Wed Oct 12, 2011 11:02 am
by ouchiko
A few things to check:

1. Go direct to the db through a client [HeidiSQL] and make sure that the data doesnt have any funny characters
2. Make sure that $name2 is NOT encoded - it's more than possible that when you PRINT it it comes out fine but in the query it might appear as & or & or some such

A good solution would be addslahes(urldecode($name2))