Solved

& in mysql_query?

Posted on 2014-09-22
6
141 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MYSQL responding very slow 3 50
Change a button after e-mail 4 21
Session time out quickly. 6 27
How do use '  ' within this code? 4 28
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

733 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