user3286482
user3286482

Reputation: 161

How to properly use variables in PHP

Here is the portion of my PHP code that I'm trying to work with:

$usersname = $_POST["usersname"];
$usersemail = $_POST["usersemail"];
$usersphone = $_POST["usersphone"];
$mailsubject = "New Customer Quote - Form Submission";
$usersbusiness = $_POST["usersbusiness"];
$userswebsite = $_POST["userswebsite"];
$usersbudget = $_POST["usersbudget"];
$usersmessage = $_POST["usersmessage"];

This is specifically what I am trying to change:

$mailsubject = "New Customer Quote - Form Submission";

I would like to change "Form Submission" to whatever the customer entered as their budget. Here is that I tried doing but apparently doesn't working:

$mailsubject = "New Customer Quote - $_POST["usersbudget"]";

I know this is something that's probably extremely simple, I just can't seem to figure out what's happening with it...

Upvotes: 0

Views: 43

Answers (4)

Brandon
Brandon

Reputation: 1605

As an alternative to concatenation suggested by the other answers, you can use curly braces:

$mailsubject = "New Customer Quote - {$_POST['usersbudget']}";

Make sure you replace the double quotes with single quotes though; you can't have double quotes inside double quotes the way you have it in your question.

Upvotes: 0

Muaaz Khalid
Muaaz Khalid

Reputation: 2249

Its Simple...

Please use

$mailsubject = "New Customer Quote - ". $_POST["usersbudget"];

instead

Upvotes: 0

Joel Hernandez
Joel Hernandez

Reputation: 1897

You should use a "." for string concatenation as

$mailsubject = "New Customer Quote - " . $_POST["usersbudget"];

Upvotes: 0

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

$mailsubject = "New Customer Quote - $_POST["usersbudget"]";

should be

$mailsubject = "New Customer Quote - ".$_POST["usersbudget"];

You need to concatenate.

Upvotes: 2

Related Questions