How can I use special characters in MySQL [duplicate] - php

This question already has answers here:
How can I prevent SQL injection in PHP?
(27 answers)
quick function to replace ' with \' in php
(3 answers)
Closed 9 years ago.
How can I insert special characters like ♣ and é into a sql table?
When I try it I get the error below:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '] ♣ us3rnamé', '123456789',
'http://blabla.com/blabla/', 'http://' at line 1
The data type is text. I guess that shouldn't matter.

Try addslashes in php documentation

You probably need to tell the database you want to use a different character set. Try sending a query with SET NAMES 'utf8' right after you connect, and before you insert anything.

Related

MYSQL Insert strips backslash escape character from json string [duplicate]

This question already has answers here:
How can I prevent SQL injection in PHP?
(27 answers)
Closed 4 years ago.
I'm trying to insert data into a mysql database, with the code below.
Problem is, my json code containing the value "R\u00f8nde" is changed to "Ru00f8nde" after I insert it into the database.
What is the best way to avoid this?
INSERT INTO jos_payplans_user(user_id, params) VALUES ('24882', '{"modtager":"Anders And","adresse":"Paradisaeblevej 111","postnr":"1234","by":"R\u00f8nde","telefon":"12345678","user_notes":""}')
In json itself avoid the slashes and insert in db
echo json_encode($value, JSON_UNESCAPED_SLASHES);

Mysql escape ' and \ [duplicate]

This question already has answers here:
How can I prevent SQL injection in PHP?
(27 answers)
Closed 4 years ago.
How can I select a row in MySQL db where the value of a column contains ' and \ ?
For example, I want to select a column that matches this types of string:
https://www.mayoclinic.org/diseases-conditions/hirschsprung\'s-disease/symptoms-causes/syc-20351556
What can I do to achieve what I want?
This should work, both characters must be escaped into the query:
SELECT * FROM `urls` WHERE text LIKE "%\\\\\'%"

update using get the records from html form code not working [duplicate]

This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
This is the php code thats getting the record from view
the html code
the update code which z not working
First Read This Documentation
Notice the WHERE clause in the UPDATE syntax: The WHERE clause
specifies which record or records that should be updated. If you omit
the WHERE clause, all records will be updated!
$sql = "UPDATE table SET field = '$variable',field2 = '$variable2'";
In Your code problem is in your update query. check that manualy.

MYSQL does not work [duplicate]

This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
How can I prevent SQL injection in PHP?
(27 answers)
Closed 5 years ago.
Currently working in PHP to do this. If needed I can send across my full php code
Error: UPDATE `WWM_Login` SET `Username`=RyzeAlchemist1,`Email`=smadger#live.co.uk,`FirstName`=test,`MiddleName`=test,`LastName`=test,`DiscordID`=#RyzeAlchemist#6043,`P_openCompletedOrders`=1,`P_openCurrentOrders`=1,`P_openRequestedOrders`=1,`P_openCreateAnOrder`=1,`P_OpenEditUsers`=0,`P_CreateStaff`=1,`P_CreateClient`= WHERE UserID = ''
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '#live.co.uk,`FirstName`=test,`MiddleName`=test,`LastName`=test,`DiscordID`=#Ryze' at line 1
Code:
UPDATE `WWM_Login` SET `Username`=$uid,`Email`=$email,`FirstName`=$firstname,`MiddleName`=$middlename,`LastName`=$lastname,`DiscordID`=$DiscordID,`P_openCompletedOrders`=$field[1],`P_openCurrentOrders`=$field[2],`P_openRequestedOrders`=$field[3],`P_openCreateAnOrder`=$field[4],`P_OpenEditUsers`=$field[5],`P_CreateStaff`=$field[6],`P_CreateClient`=$field[7] WHERE UserID = '$id'

php image upload in database [duplicate]

This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 8 years ago.
error in
INSERT into 'cd' (`id`,`image`)
VALUES ('1',LOAD_FILE('image/1.png')) == ---->
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ''cd' (`id`,`image`) VALUES ('1',LOAD_FILE('image/1.png'))' at
line 1
You should use backticks instead of quotes ' around your tablename (cd)
Backticks are most likely to be find on the top left of your keyboard (above the TAB), but this can be different for different keyboard-layouts.

Categories