Need a little help, SQL PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Need a little help, SQL PHP

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Need a little help, SQL PHP

Post by AbraCadaver »

Do: echo $query2; and then view the source in the browser. Does it say: This & That
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
ouchiko
Forum Commoner
Posts: 35
Joined: Sun Oct 09, 2011 6:54 pm
Location: London

Re: Need a little help, SQL PHP

Post 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))
Post Reply