Solved

& in mysql_query?

Posted on 2014-09-22
6
130 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 108

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 108

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now