Solved

& in mysql_query?

Posted on 2014-09-22
6
128 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
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 …

743 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