Forum Moderators: coopster
i have a Text area box for sending mail ..i just want that uwhen i enter text i want to include some field name here then at the time of sending extract these fields name from here take value from database then display value in place of field name..
See the example of text ..The Value with % % sign is field names..Please help me
hi dear %PERS_name%,
how r u , %PERS_name% i am sending u your details : like
company name : %PERS_company% ,
last name : %PERS_last_name%
Address : %PERS_address1%
City : %PERS_city%
Post Code : %PERS_postcode%
$text = $_POST['email_text']; //text from form
$replace = [url=http://us2.php.net/manual/en/function.array.php]array[/url]("%PERS_name%","%PERS_last_name%","%PERS_company%","%PERS_address1%","%PERS_city%","%PERS_postcode%");
//connect to mysql; select db
$query = "select * from table where col = 'something'";
$result = [url=http://us2.php.net/manual/en/function.mysql-query.php]mysql_query[/url]($query) or [url=http://us2.php.net/manual/en/function.die.php]die[/url]([url=http://us2.php.net/manual/en/function.mysql-error.php]mysql_error[/url]);
$row = [url=http://us2.php.net/manual/en/function.mysql-fetch-array.php]mysql_fetch_array[/url]($result); //should be one result
$replace_with = [url=http://us2.php.net/manual/en/function.array.php]array[/url]($row['name'],$row['last_name'],$row['company'],$row['address1'],$row['city'],$row['postcode']);
[url=http://us2.php.net/manual/en/function.mysql-close.php]mysql_close[/url]();
$text = [url=http://us2.php.net/manual/en/function.str-replace.php]str_replace[/url]($replace,$replace_with,$text);
echo $text;
I think this should work as you want, although I haven't tested it. Good luck!