NeoAshura
asked on
PHP QUERY HELP
Hi Experts,
I currently have the following Query.
However if a name for example is Cooke & Son LTD
It does not return the correct value.
Here is my query how can i change it so it displays Cooke & Son from the database.
I currently have the following Query.
However if a name for example is Cooke & Son LTD
It does not return the correct value.
Here is my query how can i change it so it displays Cooke & Son from the database.
$sql = "
SELECT *
FROM customer
LEFT JOIN notes
ON customer.customer_name = notes.customer_name
WHERE customer.customer_name = '" . $val . "'";
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You would have to think about special chars, try using amp; instead of & in that query.
ASKER
Hi Roads,
$sql = "
SELECT *
FROM customer
LEFT JOIN notes
ON customer.customer_name = notes.customer_name
WHERE customer.customer_name = 'MRS amp; ANNA NORRIS'";
Did not work please note the amp; in between MRS and ANNA
$sql = "
SELECT *
FROM customer
LEFT JOIN notes
ON customer.customer_name = notes.customer_name
WHERE customer.customer_name = 'MRS amp; ANNA NORRIS'";
Did not work please note the amp; in between MRS and ANNA
Does this one in any way apply to your situation ?
https://www.experts-exchange.com/questions/23221903/Problem-Ampersand-in-MySQL-query-of-a-PHP-file-not-retrieving-data.html
If not, this will work I guess
http://php.net/manual/en/function.mysql-real-escape-string.php
https://www.experts-exchange.com/questions/23221903/Problem-Ampersand-in-MySQL-query-of-a-PHP-file-not-retrieving-data.html
If not, this will work I guess
http://php.net/manual/en/function.mysql-real-escape-string.php
OK,
Can you echo out the contents of $val just before the query is run to see if it is being stored correctly.
In theory
WHERE customer.customer_name = '" . $val . "'";
and
WHERE customer.customer_name = 'Cooke & Sons LTD';
should be exactly the same if it is
Can you echo out the contents of $val just before the query is run to see if it is being stored correctly.
In theory
WHERE customer.customer_name = '" . $val . "'";
and
WHERE customer.customer_name = 'Cooke & Sons LTD';
should be exactly the same if it is
$sql = sprintf("SELECT * FROM customer LEFT JOIN notes ON customer.customer_name = notes.customer_name WHERE customer.customer_name = '%s' ",mysql_real_escape_string($val));
Have tried using LIKE search instead of this ?
$sql = "
SELECT *
FROM customer
LEFT JOIN notes
ON customer.customer_name = notes.customer_name
WHERE customer.customer_name LIKE '" %. $val .% "'";
$sql = "
SELECT *
FROM customer
LEFT JOIN notes
ON customer.customer_name = notes.customer_name
WHERE customer.customer_name LIKE '" %. $val .% "'";
ASKER
@ OnALearning Curve the echoed value of WHERE customer.customer_name = '" . $val . "'";
was
MRS
when obviously it should be MRS & ANNA NORRIS
@Roads : Thanks for the attemept but the sprintf did also not work.
was
MRS
when obviously it should be MRS & ANNA NORRIS
@Roads : Thanks for the attemept but the sprintf did also not work.
OK,
So it looks as though we have an issue when the string is being passed to $val
How is $val being defined?
can you post the code that handles that?
Cheers,
Mark.
So it looks as though we have an issue when the string is being passed to $val
How is $val being defined?
can you post the code that handles that?
Cheers,
Mark.
Looks like Roads_Roads could have nailed it with that link.
It seems to go in exactly the same direction I was starting to head.
It seems to go in exactly the same direction I was starting to head.
ASKER
Yes i have looked at the link,
the val is passed through a get clause in the url
here is the code below
<input type="button" onclick="var val = document.getElementById('d dlCompanie s').option s[document .getElemen tById('ddl Companies' ).selected Index].val ue; var url = 'mobilenum.php?val=';url+= val;window .location= url;" value="Submit..." />
i read on the link something about:
escapedStr = window.escape(str)
url=url+"?q="+escapedStr
but was not sure where to put this.
the val is passed through a get clause in the url
here is the code below
<input type="button" onclick="var val = document.getElementById('d
i read on the link something about:
escapedStr = window.escape(str)
url=url+"?q="+escapedStr
but was not sure where to put this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Roads hit the nail on the head, Points will be awarded all round for time and effort.
All is greatly appreciated.
All is greatly appreciated.
Thanks for the points, very generous
to be fair Roads_Roads got there with the answer and deserved them all
I'll accept them anyway ;)
Cheers,
Mark.
to be fair Roads_Roads got there with the answer and deserved them all
I'll accept them anyway ;)
Cheers,
Mark.
ASKER
Time as well as answers are appreciated.
Time is money in this world. so I appreciate all relevant attempts to help me
Time is money in this world. so I appreciate all relevant attempts to help me
Thank you all gentlemen.
ASKER
any ideas?