Click to See Complete Forum and Search --> : PHP/mySQL Help Needed


Mutilated1
October 19th, 2004, 02:04 PM
Hi. I need to run a query to find all occurances of "ipbhost.com" in a certain field of a table and replace it with "net" because the domain for my site has changed.

Here is the relevent section of the code I'm trying to use.



$sql_query "SELECT pid, post FROM ipb_posts";

$DB->query( $sql_query );

while ( $row = $DB->fetch_row() )
{
//echo ($row['pid'].",".$row['post']);
//echo ("<br />");

$post = str_replace("ipbhost.com","net",$row['post']);

//
// Need Help to Format this UPDATE command properly Please
//
$sql_command = "UPDATE ipb_posts SET post = '".$post."' WHERE pid = ".$row[pid];

// Doesn't work because the sql_command seems to have lots
// of ", ', and other stuff in it that screws up the update
// yet I want to keep these characters in the data
$UPDATER->query($sql_command);

// HELP!

}


The problem seems to be that $post has some ' and or "s in it that are messing up the SQL command. Yet, I want to keep those characters not throw them out.

I apologize is this is more of a mySQL question than a PHP question, but can anyone tell me the answer ?

Thanks!

Tleilaxu
October 20th, 2004, 02:48 AM
use two str_replace calls for ' and " after yours:

$post=str_replace("\'","\\\'",$post);
$post=str_replace("\"","\\\"",$post);
However I think the second call is not necessary.

PallaviDalvi
October 20th, 2004, 04:58 AM
or u can use addslashes() (http://www.php.net/manual/en/function.addslashes.php) which does the same as above, but in one call.

Mutilated1
October 20th, 2004, 12:26 PM
Thank you. addslashes worked nicely.

zolta
November 6th, 2004, 07:41 AM
I downloaded a forum from the http://www.phpbb.com
I set it up and it works, but:

my probelm is that when somebody wants to register, he'll get an e-mail, where he has to activate his account. For some reasons, the e-mail isn't sent and I've got some error avout SMTP.

What can I do?

Danii
November 6th, 2004, 08:30 AM
Does you mail service work?