how do i deal with missing string in MySQL? [closed] - mysql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I want to insert data into my table but when I press "enter" nothing happens and the next sentence starts with '>.
I know it means missing string but I don't see it
this is my code
INSERT
INTO events
VALUES
('13', '2021.03.13',
'vet',
'Dehidration. Spider's body loses more fluids than it does take in. If spider is not threated, it can get worse and become a serious problem.',
'10',
'5');
then it shows "'>"
how to deal with this?

The fourth value that you are entering contains a ' which is closing the string early, try this;
INSERT
INTO events
VALUES
('13', '2021.03.13',
'vet',
'Dehydration. Spider\'s body loses more fluids than it does take in. If spider is not threated, it can get worse and become a serious problem.',
'10',
'5');
In this case the \ lets the database know that you want to store the character ', instead of ending the string early.

Please use this mysqli_real_escape_string(db_connection, $your_string)
OR
you may write single quote like this => \'

Related

Remove escape symbols in string using mysql command [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a MySQL column with data looking like this,
I need to convert the column to the JSON format via convert(somecolumn,JSON). However, it seems that I first need to remove the escape symbols (e.g., \"). I did some search and found that mysql_real_escape_string will do the job (from this question).
But if I understand correctly, mysql_real_escape_string is a PHP command. Is there any native MySQL command that do similar thing as mysql_real_escape_string (something like convert(mysql_native_function(somecolumn),JSON))?
Use REPLACE. For harder things REGEXP_REPLACE.
SELECT REPLACE(somecolumn, '\"', '"')
SELECT REGEXP_REPLACE('"..."', '(^"|"$)', '')
The latter will unquote the entire string, as ^ is the start, and $ the end.
BTW I would actually correct all the data in the table once. (After a backup.)
The mysql library is old.. if you really need to use something like it - use mysqli
the mysql_real_escape_string is not as secure as you would think it to be, see this: https://security.stackexchange.com/questions/8028/does-mysql-escape-string-have-any-security-vulnerabilities-if-all-tables-using-l
That said you're much better off by not using any of them but using Php PDO and replacing something like:
$data = [
'name' => $name,
'surname' => $surname,
'sex' => $sex,
];
$sql = "INSERT INTO users (name, surname, sex) VALUES (:name, :surname, :sex)";
$stmt= $pdo->prepare($sql);
$stmt->execute($data);
it will take care of the 'escaping' problems for you.
more examples here: https://phpdelusions.net/pdo_examples/insert

how to edit my links (sort and change by starting alphabet) in sql database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
The community reviewed whether to reopen this question 11 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
i have a database (mysql) with links like:
mysite.com/Movies/Abajan_1080p.mp4
mysite.com/Movies/Abajan_720p.mp4
mysite.com/Movies/Abajan_480p.mp4
mysite.com/Movies/Bahman_1080p.mp4
mysite.com/Movies/Bahman_720p.mp4
mysite.com/Movies/Bahman_480p.mp4
....
i sorted my files by creating directories by alphabets (A,B,...)
so i need to change links:
mysite.com/Movies/A/Abajan_1080p.mp4
mysite.com/Movies/A/Abajan_720p.mp4
mysite.com/Movies/A/Abajan_480p.mp4
mysite.com/Movies/B/Bahman_1080p.mp4
mysite.com/Movies/B/Bahman_720p.mp4
mysite.com/Movies/B/Bahman_480p.mp4
is there a simple solution to edit database? to edit all links like that?
Thanks a lot
You can use the function SUBSTRING_INDEX() to get the filename and then concatenate the path:
UPDATE tablename
SET col = CONCAT(
'mysite.com/Movies/',
LEFT(SUBSTRING_INDEX(col, '/', -1), 1),
'/',
SUBSTRING_INDEX(col, '/', -1)
)
Replace col with your column's name.
See the demo.
Results:
col
mysite.com/Movies/A/Abajan_1080p.mp4
mysite.com/Movies/A/Abajan_720p.mp4
mysite.com/Movies/A/Abajan_480p.mp4
mysite.com/Movies/B/Bahman_1080p.mp4
mysite.com/Movies/B/Bahman_720p.mp4
mysite.com/Movies/B/Bahman_480p.mp4

how to remove spaces from a field in mySQL db? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a database where i store my photos title, tags, and their path on sever some of the records have names like:
photo 1234.png. I need to make them like photo1234.png
Why can't I use a query like
UPDATE tblPhoto a
set a.photoLink = replace(a.photoLink , ' ', '')
where a.photoLink like '% %';
And which is the best way to rename them in Linux Server, can I use php ?
You don't need where clause
UPDATE tblPhoto SET photoLink = REPLACE(photoLink , ' ', '');
For replacing the file name on your Linux Server you can try to look in this answer.
https://stackoverflow.com/a/2709619/7921383
Use php method for example:
$old_name="Hello World";
echo str_replace(" ","",$old_name);
//output Helloworld

Error when inserting datetime into SQL [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am having a problem inserting a datetime into SQL. my statement is...
INSERT INTO `booking.com`.`last_sign_in` (`personID`, `browser`,
`deviceType`, `deviceOS`, `location`, `time`) VALUES ('1', 'chrome
61', 'desktop', 'windows 10', 'Belfast', '20171114 10:34:09 AM');
When I try to run this insert statement I get the error...
all help appreciated!!
Try this
INSERT INTO `booking.com`.`last_sign_in` (`personID`, `browser`, `deviceType`, `deviceOS`, `location`, `time`)
VALUES (1, 'chrome 61', 'desktop', 'windows 10', 'Belfast', '2017-11-14 10:34:09');
The dates have been changed to the correct format (dashes added and the AM removed) also, it looks like you're trying to add the string value '1' into the PersonID column which I am assuming is int so I have changed that to an int value based on that assumption

How to fetch mysql data having brackets? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to fetch mysql data having round brackets e.g. ABCD(XYZ). When I run query
"SELECT * FROM tablename WHERE Column = 'ABCD(XYZ)'"
it returns an empty result. Please suggest a way. Thanks in advance!
this should work:
INSERT INTO `tablename` (`Column`) VALUES ('ABCD(XYZ)');
SELECT * FROM `tablename` WHERE `Column` = 'ABCD(XYZ)'";
Maybe 'ABCD(XYZ)' is not exactly the value of your data (for example if you inserted some whitespaces before or after it.)
You can try it with a like to find that out:
SELECT * FROM `tablename` WHERE `Column` LIKE '%ABCD(XYZ)%'";
Another possibility is that your value has been converted with htmlentities and you saved something like this:
'ABCD&40;XYZ&41;'
&40; Left parenthesis
&41; Right parenthesis