/    Sign up×
Community /Pin to ProfileBookmark

Insert variable into form

Hello again.

I have a search form that returns results. These results are displayed in a table. Each row in the table has a checkbox.
The checkbox is assigned a certain value.
This table is ALSO a form that will lead to a certain action.
This action is – sending an SMS to that row’s user.

I would like to be able to insert the user’s first name into the SMS message.

The action that sends the SMS messages starts like this:

[CODE]set_time_limit (0);
$textMessage = urlencode($_GET[‘textMessage’]);
$textMessage1 = $_GET[‘textMessage’];
$number = count($cb);
$todayDate = date(“Y-m-d”);
$todayTime = date(“H:i:s”);

foreach ($cb as $val) {

1)the action that sends the SMS messages….
2)write data into database (e.g. log the sent sms etc…)

}[/CODE]

As you can see I have to URLENCODE the text that is provided by the user in the form in order for it to go through, but I am also keeping a non–encoded version of the text message so that I can log it into the database.

The following code will successfully fetch the firstName for each $val (mobilePhone).

[code=php]$sqlgetfname = “SELECT `firstName`,`mobilePhone` FROM `Results` WHERE `mobilePhone` = ‘$val'”;
$queryfname = mysql_query($sqlgetfname) or die(‘ERROR: ‘.mysql_errno().’, ‘.mysql_error());
$fnamerow = mysql_fetch_array($queryfname);
$fname = $fnamerow[‘firstName’];[/code]

What do I have to do in order to supply my user with a certain variable, that if inserted into the textMessage box will include the recipient’s firstName in the message.
For example = instead of sending “Hello your account is active” to 50,000 people, I could send “Hello %variable%, your account is active, and %variable% will change according to the recipient’s firstName.

Thanks for your help.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@GarySJun 13.2006 — If that's your only variable, then this would be easiest:

$textMessage = 'Hello ' . $fname . ', ' . $textMessage;
Copy linkTweet thisAlerts:
@MeniauthorJun 14.2006 — That's the thing... $fname is not always going to be THERE.

I want the user to be able to enter text freely into the text box, and provide him with a variable that he can use for the firstName wherever he wants...
Copy linkTweet thisAlerts:
@GarySJun 14.2006 — Oh now I get it.

"Hello %variable%, your..." would be one way... using regular expressions to find the % ... % variables?
Copy linkTweet thisAlerts:
@MeniauthorJun 14.2006 — perhaps I should have mentioned that I am fairly new to PHP and to programming as a whole.

Would you care to elaborate?

How would I implement this in my code?

Thanks!
Copy linkTweet thisAlerts:
@GarySJun 14.2006 — Here's how you might do it just using a search and replace:

[code=php]
$textMessage= 'Hello %firstname%, your account is active. %salutation%';
echo '<p>' . $textMessage;


$firstName='Peter';
$salutation='Thanks!';

$textMessage=str_replace('%firstname%',$firstName,$textMessage);
$textMessage=str_replace('%salutation%',$salutation,$textMessage);

echo '<p>' . $textMessage;

[/code]
Copy linkTweet thisAlerts:
@MeniauthorJun 14.2006 — Worked like a charm

? ? ?

Thanks!
Copy linkTweet thisAlerts:
@GarySJun 14.2006 — Excellent!
×

Success!

Help @Meni spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...