-1

I am trying to assign a value to a variable through a form created in html

Form returns place holder website_features and based on the value being good or bad, i want it to return numeric 4 or 2 Tried the below code with error Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\e-commerce2\feedback.php Any help is appreciated

$Website_score= if ($_POST['website_features']='GOOD')
                                      {echo '4'}
                                      else {echo '2'};
jagann
  • 11
  • 2

1 Answers1

0

You can't directly assign an if operation to a variable.

Depending on your requirements (it's a little hard to tell what you're trying to do), you could try…

$Website_score = 0;

if ($_POST['website_features'] == 'GOOD') {
    $Website_score = 4;
} else {
    $Website_score =  2;
};

echo $Website_score;
John Parker
  • 54,048
  • 11
  • 129
  • 129
  • Hi . Thank you for the reply. I am trying to create a calculated field based on feedback. If user feedback is good , then 4 is assigned as score which I’m logging into phpmyadmin. Your code is stopping at the else statement . – jagann Apr 03 '20 at 17:26
  • @jagann Apologies - there was a missing semi-colon. (Fixed now.) To be honest I’d recommend trying to find some PHP tutorials to follow before tackling a problem like this - having a have a good grasp of the basics will save you a lot of time. – John Parker Apr 04 '20 at 18:50