Solved

& in mysql_query?

Posted on 2014-09-22
6
143 Views
Last Modified: 2014-09-22
I have this query:

SELECT * from subcategory where prim = 'Waterworks and Corrosion' and category = 'Chlorine & Water Testing' order by so

When I run this "manually" against the database, it returns, correctly, 4 rows.

When I do the identical query in php, it returns zero rows. The php code is:

$pqrysc = "SELECT * from subcategory where prim = '" . $prd['pdesc'] . "' and category = '" . $cat . "' order by so";
echo $pqrysc . "<br>";
$pressc = mysql_query ($pqrysc, $Link);
$npsc = mysql_num_rows($pressc);
echo "num subcats = " . $npsc . "<br>";

the echo num subcats equals 0.

Does the & in the query cause an issue with mysql_query?

There are hundreds of other cases  where there is no & in the category where the mysql_query returns correctly.

I am aware that is code is not the latest correct interface between php & MySQL
0
Comment
Question by:Richard Korts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40337192
Makes no difference, what do you get when you:

echo $pqrysc;
0
 

Author Comment

by:Richard Korts
ID: 40337279
To Gary,

I get this:

SELECT * from subcategory where prim = 'Waterworks and Corrosion' and category = 'Chlorine & Water Testing' order by so

I copied the echoed version to phpmysql to do a "manual" sql, works fine.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40337289
Are you sure $Link is connecting to the right database?

p.s.
You need to get off mysql_query - obsolete (nearly)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40337302
1. Set error_reporting(E_ALL);
2. use var_dump() to check the values of $Link and $pressc and $npsc
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40337305
And be sure to look at all of these outputs with "view source."  Your browser will render the ampersand from the character entity &amp; but your database will not find & == &amp;
0
 

Author Closing Comment

by:Richard Korts
ID: 40337359
The &amp; was the issue; I did str_replace, etc. & it FIXED it.

Thanks Ray,
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question