i'm not an expert in mysql but i need to find and replace the data
<h2 class="ui-box-title">Product Description</h2>
<div class="ui-box-body">
<p> </p> <h2 style="padding: 5.0px;">
<div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;">
i try to use this command
SELECT *
FROM `oc_product_description`
WHERE `description` LIKE '%<h2 class="ui-box-title">Product Description</h2> <div class="ui-box-body"> <p> </p> <h2 style="padding: 5.0px;"> <div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;"> %'
LIMIT 0 , 30
but it return 0 results
i need to find and replace the value with "" in my table description how to do that? and if i search using this command
SELECT *
FROM `oc_product_description`
WHERE `description` LIKE '% <h2 class="ui-box-title">Product Description</h2>%'
LIMIT 0 , 30
it will return the results Showing rows 0 - 29
please advise need help from expert. appreciated. thanks
Spacing of the code in database may be different from the given one.
You could do something like this:
<?php
$1 = '<h2 class="ui-box-title">Product Description</h2>';
$2 = '<div class="ui-box-body">';
$3 = '<p> </p> <h2 style="padding: 5.0px;">';
$4 = '<div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;">';
$connect= mysqli_connect("localhost","root","","db"); //edit parameters
$query = "SELECT *
FROM `oc_product_description`
WHERE `description` LIKE '%".$1."%' AND `description` LIKE '%".$2%."'`description` LIKE '".%$3%."' AND `description` LIKE '%".$4%."'
LIMIT 0 , 30";
$query = mysqli_query($connect,$query);
if(mysqli_num_rows($query)==1){echo 'Found the correct string!<br>';
$assoc = mysqli_fetch_assoc($query);
echo $assoc['description'];
}
else if(mysqli_num_rows($query)>1){echo 'Found too much results!';}
else{echo 'Found nothing!';}
?>
You could have escaped html strings before the insertion in the database. Replace
$1 = '<h2 class="ui-box-title">Product Description</h2>';
$2 = '<div class="ui-box-body">';
$3 = '<p> </p> <h2 style="padding: 5.0px;">';
$4 = '<div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;">';
$connect= mysqli_connect("localhost","root","","db"); //edit parameters
With
$connect= mysqli_connect("localhost","root","","db"); //edit parameters
$1 = mysqli_real_escape_string($connect,'<h2 class="ui-box-title">Product Description</h2>');
$2 = mysqli_real_escape_string($connect,'<div class="ui-box-body">');
$3 = mysqli_real_escape_string($connect,'<p> </p> <h2 style="padding: 5.0px;">');
$4 = mysqli_real_escape_string($connect,'<div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;">');
If you still don't get the expected result, it is possible that you had used htmlspecialchars()
, maybe in addition to mysqli_real_escape_string()
.
Edit variables $1,$2,$3 and $4 adding htmlspecialchars
, if it doesn't work try to remove mysqli_real_escape_string
.
You can try this:
UPDATE oc_product_description SET description = REPLACE(description, '<h2 class="ui-box-title">Product Description</h2><div class="ui-box-body"><p> </p> <h2 style="padding: 5.0px;"><div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;">', '')
WHERE description LIKE ('%<h2 class="ui-box-title">Product Description</h2><div class="ui-box-body"> <p> </p><h2 style="padding: 5.0px;"><div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;"> %');
but before trying that just keep a backup of the table.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.