473,657 Members | 2,411 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 4454
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

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

Similar topics

1
1578
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 comes up: "The page cannot be displayed" - The browser can't find the file, because it is looking for http://file2.php instead of http://teachercards.org//file2.php Any help would be greatly appreciated. TIA
1
3245
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 code fails at "objConn.Open()" with the error: System.Data.OleDb.OleDbException: Could not find installable ISAM. Can somebody please help me out? I'm still a learning programmer, so if someone can point out my mistakes, it'll be great! Thanks! ...
2
1854
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 from a mysql text-table. How and where do I attack this problem? :confused: Thanks! :cool:
3
1385
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
3012
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 to insert these data? Please help me. Thanks for your help in advance. Best,
3
7402
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 and 10. I can display either the first row or all the rows using the below code: $row = mysql_fetch_array($result) or die(mysql_error()); echo $row. " - ". $row. " <img src=images/arlon.jpg /> ". $row. " - ". $row;
2
4798
by: Nilanjan Sanyal | last post by:
how to retrieve hindi text from mysql database using php
0
1470
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 mysql-connector-c++-1.1.0-win32.msi in my Windows XP. I got a Script from net , but it will not Work... Do you please Explain how to Insert and select data in C++ with the help of a Code and other things related to the Driver(mysql-connector-c++-1.1.0-win32.msi). ...
0
8399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8606
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4159
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.