Solved

& in mysql_query?

Posted on 2014-09-22
6
135 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 109

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 109

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

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.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

810 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