473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to insert string into mysql contains double backslash

Expand|Select|Wrap|Line Numbers
  1. $str="james//bond";
  2. $str= mysqli_real_escape_string($con,$str);
  3. //insert query
after successful insert in database it value shows as "james/bond"

how I can insert exact string? anyone pls help.
Jun 5 '15 #1
14 10728
try "james"+@"\\Bond"; I think it should work fine.
Jun 5 '15 #2
computerfox
276 100+
Try this?

Expand|Select|Wrap|Line Numbers
  1. $str="james\/\/bond";
  2. $succ=$mysqli->query($sql);
  3.  
Jun 6 '15 #3
Luuk
1,047 Expert 1GB
That dos not happen here....

Expand|Select|Wrap|Line Numbers
  1. mysql> create table actor(name varchar(40));
  2. Query OK, 0 rows affected (0.40 sec)
  3.  
  4. mysql> insert into actor values ("James//Bond");
  5. Query OK, 1 row affected (0.07 sec)
  6.  
  7. mysql> select * from actor;
  8. +-------------+
  9. | name        |
  10. +-------------+
  11. | James//Bond |
  12. +-------------+
  13. 1 row in set (0.04 sec)
  14.  
  15. mysql>
Jun 6 '15 #4
Luuk
1,047 Expert 1GB
oh wait, I see what I did wrong......

"James Bond" is not an actor..... ;)
Jun 6 '15 #5
computerfox
276 100+
Yeah... you also didn't do it in PHP, which doesn't answer his question. Try running the same querying in PHP and you will get the same result as the OP.
Jun 6 '15 #6
Luuk
1,047 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.         error_reporting(E_ALL);
  3.         $m = new mysqli("localhost","test","test","test");
  4.         $actor = "Roger//Moore";
  5.         $sql = "INSERT INTO actor VALUES ('$actor')";
  6.         $result = $m->query($sql);
  7.  
  8.         $sql = "SELECT * FROM actor";
  9.         if ($result = $m->query($sql)) {
  10.                 while ($obj = $result->fetch_object())
  11.                 {
  12.                         echo $obj->name."\n";
  13.                 }
  14.         }
  15.         $result->close();
  16. ?>
  17.  
running this (from the command-line)
Expand|Select|Wrap|Line Numbers
  1. luuk@opensuse:~/tmp> php actors.php
  2. James//Bond
  3. Roger//Moore
  4. luuk@opensuse:~/tmp>
  5.  
Jun 7 '15 #7
Luuk
1,047 Expert 1GB
and also if I use real_escape_string
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.         error_reporting(E_ALL);
  3.         $m = new mysqli("localhost","test","test","test");
  4.         $actor = "Ursula//Andress";
  5.         $actor = $m->real_escape_string($actor);
  6.         $sql = "INSERT INTO actor VALUES ('$actor')";
  7.         $result = $m->query($sql);
  8.  
  9.         $sql = "SELECT * FROM actor";
  10.         if ($result = $m->query($sql)) {
  11.                 while ($obj = $result->fetch_object())
  12.                 {
  13.                         echo $obj->name."\n";
  14.                 }
  15.         }
  16.         $result->close();
  17. ?>
  18.  
running this:
Expand|Select|Wrap|Line Numbers
  1. luuk@opensuse:~/tmp> php actors.php
  2. James//Bond
  3. Roger//Moore
  4. Ursula//Andress
  5. luuk@opensuse:~/tmp>
Jun 7 '15 #8
computerfox
276 100+
harintfs, were you able to get it to work?
Jun 7 '15 #9
Luuk
1,047 Expert 1GB
MUST I remind you, that the subject of this message is NOT the same as what is tried in the example ?

The subject is about 'backslashes' (a.k.a. '\')
The example is showing 'slashes' (a.k.a. '/')

Next code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.         echo "A\\B \n";
  3.         echo "A//B \n";
  4.         echo "A\B \n";
  5.         echo "A/B \n";
  6. ?>
  7.  
will print:
Expand|Select|Wrap|Line Numbers
  1. A\B
  2. A//B
  3. A\B
  4. A/B
  5.  
Jun 7 '15 #10
computerfox
276 100+
@Luuk, if you look at his code, which I'm sure you did, he just has slashes.
He never mentions "backslashes" in his first post other than the title. Could it be that he misspoke ;-)

Please read the question instead of assuming the question from the title. Since you seem to know exactly what they are asking for, please show me in his first post where he mentions "backslashes" thanks.
Jun 7 '15 #11
Luuk
1,047 Expert 1GB
@computerfox: let's wait for harintfs and what he has to say about slashes and backslashes...

I was reading the question, not the title ,when I gave some working code.

But what harintfs describes is the same as what happens to my example
Expand|Select|Wrap|Line Numbers
  1. echo "A\\B";
which produces
Expand|Select|Wrap|Line Numbers
  1. A\B
so, one should not just read question, but also read title
Jun 7 '15 #12
computerfox
276 100+
Depends how you look at it. Usually if we're lucky to have an example, that's what we should go with, but I agree, let's wait for the OP to clarify what they wanted.
Jun 7 '15 #13
but how about to inserting a location file in variable from "LoadFromFile" in MySQL?
Mar 10 '20 #14
You need to escape your backslash :

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO gender
  2. (sex, date) VALUES (
  3. 'male are allowed \\ female are not allowed',
  4. "2012-10-06")
Mar 10 '20 #15

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

Similar topics

13
by: usgog | last post by:
I need to implement a function to return True/false whether String A contains String B. For example, String A = "This is a test"; String B = "is is". So it will return TRUE if String A includes two...
3
by: Vincent Texier | last post by:
Hello, I want to send 3 chars in hexa code to the serial port. So I type in a tkinter entry : "\x20\x01\x21" The string is set in a StringVar(). When I read the stringVar, I get :...
1
by: Christine | last post by:
I was wondering if it is possible to convert an array that is of type string to type double so that matrix operations can be performed on it? I have a string array because I needed to split the...
9
by: Coleen | last post by:
Hi All :-) I found the way to get my column sum (Thanks Cor I did it a little different, but the result is what I wanted) I used: dt_stat_report_3b.Columns.Add(New DataColumn("Sum",...
3
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code)...
4
by: Milsnips | last post by:
Hi there, i'm trying to do a string replace on something like the following string MyString = myinput; myinput = myinput.Replace("src="../content/","http://www.site.com/content/") but, the...
3
by: Waruna | last post by:
Is there a way to block insert into mysql(5.0) using c api of mysql db.. i.e. say there is a table with 2 columns, one contains char other int then i want to insert 500 records at once,, as i...
1
maheshwag
by: maheshwag | last post by:
If I have to insert with two sql table and the place of string is as below: // Single Record Insert String AA=”Insert into aa(date)values(@date)”; //Multiple Record Insert with...
1
by: vanitha asokan | last post by:
how to insert '\' in mysql database using java code
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.