473,503 Members | 12,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to retrieve data containg ampersand from mysql table using php

28 New Member
Expand|Select|Wrap|Line Numbers
  1. $CAT='Bath & Body';
  2. sql="select * from Products where Category = '$CAT';
  3. $result=mysql_query($sql);
  4.  
When I am running above code , I got an error. When I am removing '&' from $CAT , it is working fine. I wish to know how to include ampersand in mysql data.

Thanks in advance
Mar 8 '08 #1
10 4437
Markus
6,050 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. $CAT='Bath & Body';
  2. sql="select * from Products where Category = '$CAT';
  3. $result=mysql_query($sql);
  4.  
When I am running above code , I got an error. When I am removing '&' from $CAT , it is working fine. I wish to know how to include ampersand in mysql data.

Thanks in advance
Try preceeding it with a backslash
[php]
$CAT = "something \& something else";
[/php]
Mar 8 '08 #2
benoypaul
28 New Member
Sorry. It is not working
Mar 8 '08 #3
Markus
6,050 Recognized Expert Expert
Sorry. It is not working
Strange
What error do you get?
Mar 8 '08 #4
benoypaul
28 New Member
I am using this php code in a javascript function. I got the error "object expected". When removing ampersand from $CAT or commenting $sql stament, then code is working properly.
Mar 8 '08 #5
Markus
6,050 Recognized Expert Expert
I am using this php code in a javascript function. I got the error "object expected". When removing ampersand from $CAT or commenting $sql stament, then code is working properly.
Can you please show the full code
using the proper code tags
Mar 8 '08 #6
benoypaul
28 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2. function removeAllOptions(selectbox)
  3. {
  4.     var i;
  5.     for(i=selectbox.options.length-1;i>=0;i--)
  6.     {
  7.         //selectbox.options.remove(i);
  8.         selectbox.remove(i);
  9.     }
  10. }
  11.  
  12.  
  13. function addOption(selectbox, value, text )
  14. {
  15.     var optn = document.createElement("OPTION");
  16.     optn.text = text;
  17.     optn.value = value;
  18.  
  19.     selectbox.options.add(optn);
  20. }
  21.  
  22.  
  23. function SelectEditProduct()
  24. {
  25. removeAllOptions(document.editproducts.productname);
  26. addOption(document.editproducts.productname,"","select");
  27. <?php
  28. include_once("database.php");
  29. $sql="select * from ProductCategory ";
  30. $result1=mysql_query($sql) ;
  31. while ($rows1=mysql_fetch_row($result1))
  32. {
  33. echo "if(document.editproducts.categoryname.value == '$rows1[1]'){";
  34.  
  35. $sql="select * from Products where Category ='$rows1[1]'";  // THIS LINE SHOWS ERROR
  36. //$sql="select * from Products where Category='Bath \& Body'";
  37.  
  38. $result=mysql_query($sql);
  39. while ($rows=mysql_fetch_row($result))
  40. {
  41.  echo "addOption(document.editproducts.productname,'$rows[1]', '$rows[2]');";
  42. }
  43. echo "}";  
  44. }
  45.  
  46. ?>
  47.  
  48. }
  49.  
  50.  
ProductCategory table contains some data with ampersand ($rows1[1]). This causes errors
Mar 8 '08 #7
Markus
6,050 Recognized Expert Expert
Can you show me the output you get on the page source?
I'm still not understand your problem.
Is the error with javascript or php?
Mar 8 '08 #8
benoypaul
28 New Member
It is a javascript error. When we removing $sql ="..." statement, there is no errors. URL of this code is http://www.markdickson.com/adminpanel/editproduct.php

Error occur when we changing productcategory
Mar 8 '08 #9
Markus
6,050 Recognized Expert Expert
It is a javascript error. When we removing $sql ="..." statement, there is no errors. URL of this code is http://www.markdickson.com/adminpanel/editproduct.php

Error occur when we changing productcategory
If it's a javascript error, you should ask in the javascript forum.
Mar 8 '08 #10
benoypaul
28 New Member
Thanks a lot for your help
Mar 8 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1572
by: Willoughby Bridge | last post by:
I am trying to post from a form to table using the code below from file2.php and having two problems: 1. The data is not being posted to the table 2. After submit is pressed the following message...
1
3241
by: funcSter | last post by:
I want to retrieve data from an Excel file like how I would with a database. I understand that I would have to use OLE DB. Somehow I think I cannot get the connection string right, as the bit of...
2
1849
by: jenese | last post by:
Hi! I've searched the forum and the net for the answer of, probably an easy question for the experienced.... I need to limit the amount of text to 50 first characters when looping out the data...
3
1380
by: cool84 | last post by:
I have a problem to retriew thr .txt file in the mysql table into the temp folder. anyone know how to do it ?
2
3001
by: djdarpan | last post by:
Hi, Can anyone help me! I have multiple auto generated input fields(e.g. values are 1 to 10) in a form and I want to insert all input fields data in one column of MySQL table. Is there any way...
3
7395
by: printline | last post by:
Hello All I need a little help with a phph script to display some specific data from a mysql table. I have a mysql table with 4 columns and 10 rows. I want to display fx. data from row 4, 6, 8...
2
4791
by: Nilanjan Sanyal | last post by:
how to retrieve hindi text from mysql database using php
0
1416
by: amskape | last post by:
Hi Pals, I am Anes , from Kerala ,India. I am a PHP Programmer Basically but have interest and now studying C++ , I plan to take data from MySql in C++, for that I install...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.