Hello I need a quick fix, i m paypaling 10$ to the one who get it right The question is simple, i have this html code in a mysql field, i want to remove it with a mysql query or using the php way, because of the ' and " . No time to search, first one who post here the working query gets it I have a test database so i can try around use thistable as table and thisfield as your field. You can either get this code removed of replaced with a br tag
<?php //Your connection above $text = mysql_real_escape_string(file_get_contents("http://www.schlogo.net/test.txt")); mysql_query("DELETE FROM thistable WHERE thisfield='".$text."'"); ?> This might work
flakas123 : PHP Parse error: syntax error, unexpected T_VARIABLE $text = mysql_real_escape_string(file_get_contents("http://www.schlogo.net/test.txt"));
Well, this line is successfuly executed on my localhost Do you open a connection to your MySQL server? If not: <?php @mysql_connect("host", "user", "password"); @mysql_select_db("database"); $text = mysql_real_escape_string(file_get_contents("http://www.schlogo.net/test.txt")); $query = mysql_query("DELETE FROM thistable WHERE thisfield='".$text."'"); if(!$query) echo "Query is not complete".mysql_error(); else echo "Query is complete"; ?> Code (markup): By the way - you might mistyped the connection before or something like that (maybe forgot a semicolon mark?)
Just tested it with your data - query completed, test deleted. If it doesn't work - I don't know. Works for me though...
mmm maybe because there are other information in the field (that i don t want to be deleted ) you r query is only looking for field equal to the text not containing, is it true?
@mysql_connect("host", "user", "password"); @mysql_select_db("database"); $text = mysql_real_escape_string(file_get_contents("http://www.schlogo.net/test.txt")); $query = mysql_query("SELECT thisfield FROM thistable WHERE thisfield LIKE "%$text%"); $delete = mysql_fetch_assoc($query); $newText = str_replace($text, "", $delete['thisfield']); mysql_query("UPDATE thistable SET thisfield = $nextText WHERE thisfield LIKE "%$text%"); PHP: ?>
@mysql_connect("host", "user", "password"); @mysql_select_db("database"); $text = mysql_real_escape_string(file_get_contents("http://www.schlogo.net/test.txt")); $query = mysql_query("SELECT primaryfield, textfield FROM thistable WHERE textfield LIKE '%$text%'"); while($data = mysql_fetch_array($query)){ $newText = str_replace($text,"", $data['textfield']); mysql_query("UPDATE thistable SET thisfield = '$newText' WHERE thisfield='".$data['primaryfield']."'"); } PHP:
error :/ [Wed Apr 07 01:53:49 2010] [error] [client 205.151.64.76] PHP Parse error: syntax error, unexpected '"' in /var/www/vhosts/stockportables.fr/httpdocs/db.php on line 2
Hello, what is primaryfield ? i have tablename and fieldname that would be your textfield and thistable
primaryfield is your unique field, if you don't have it than PLEASE BACKUP YOUR DATA FIRST Method 1 @mysql_connect("host", "user", "password"); @mysql_select_db("database"); $text = mysql_real_escape_string(file_get_contents("http://www.schlogo.net/test.txt")); $query = mysql_query("SELECT textfield FROM thistable WHERE textfield LIKE '%$text%'"); while($data = mysql_fetch_array($query)){ // Temporary Value $newText = str_replace($text,"", $data['textfield']); // Update to current field mysql_query("UPDATE thistable SET thisfield = '$newText' WHERE thisfield='".$data['textfield']."'"); } PHP: Method 2 @mysql_connect("host", "user", "password"); @mysql_select_db("database"); $text = mysql_real_escape_string(file_get_contents("http://www.schlogo.net/test.txt")); $query = mysql_query("SELECT textfield FROM thistable WHERE textfield LIKE '%$text%'"); while($data = mysql_fetch_array($query)){ // Temporary Value $newText = str_replace($text,"", $data['textfield']); // Delete the current field mysql_query("DELETE FROM thistable WHERE thisfield='".$data['textfield']."'"; // Than new insert to table mysql_query("INSERT INTO thistable(thisfield) VALUES ('$newtext')"); } PHP: Can I see you table structure?
Hello, MySQL is not procedural language, so this should be something like that: error_reporting(0); $newText='bla'; //Set your replacement text here. mysql_connect("host", "user", "password") or die("MySQL error 1"); mysql_select_db("database") or die("MySQL error 2"); $text = file_get_contents("http://www.site.com/test.txt") or die("Error fetching file http://www.site.com/test.txt") $text = mysql_real_escape_string($text); mysql_query("UPDATE IGNORE TableName SET thisfield=REPLACE(thisfield,'$text','$newText')") or die(mysql_error()); PHP: Let me know does this meet your needs. Regards
@mysql_connect("host", "user", "password"); @mysql_select_db("database"); $text = mysql_real_escape_string(file_get_contents("http://www.schlogo.net/test.txt")); $query = mysql_query("SELECT `thisfield` FROM `thistable` WHERE `thisfield` LIKE '%$text%'"); $delete = mysql_fetch_assoc($query); $newText = str_replace($text, "", $delete['thisfield']); mysql_query("UPDATE `thistable` SET `thisfield` = '$nextText' WHERE `thisfield` LIKE '%$text%'); PHP: