Fernando Souza
Fernando Souza

Reputation: 1779

Passing 2 fields values for the same variable in jphpmailer.php

how can I assign two different fields values for the same variable in jphpmailer.php? Here is my present code:

$reg_name = isset($_POST['lname']) ? htmlspecialchars($_POST['lname']): "";

I want to add one more field to it, like "fname", but my knowledge in php still not enough to solve it grammatically right.

$reg_name = isset($_POST['lname','fname']) ? htmlspecialchars($_POST['lname','fname']):

Upvotes: 0

Views: 36

Answers (2)

shubhangee
shubhangee

Reputation: 539

Give a try with below code if it can solve your problem...

$reg_name = '';
if(isset($_POST['fname']))
{
   $reg_name = htmlspecialchars($_POST['fname']);
}

if(isset($_POST['lname'])){
    if($reg_name){
       $reg_name.=' '.htmlspecialchars($_POST['lname']);
    }else{
       $reg_name=htmlspecialchars($_POST['lname']);
   }
}

echo $reg_name;

Upvotes: 2

Sinto
Sinto

Reputation: 3997

Are you trying to do this:

echo $reg_name = (isset($_POST['fname']) ? htmlspecialchars($_POST['fname']): "").' '.(isset($_POST['lname']) ? htmlspecialchars($_POST['lname']): "");

Creating array as:

$reg_name['fname'] = isset($_POST['fname']) ? htmlspecialchars($_POST['fname']): "";

$reg_name['lname'] = isset($_POST['lname']) ? htmlspecialchars($_POST['lname']): "";

print_r($reg_name);

Upvotes: 2

Related Questions