Wolverine68 Posted June 24, 2008 Share Posted June 24, 2008 I'm trying to setup a feedback form that prints out a response based on the rating that the user enters. No matter what number I put in, the response that prints out is the response that's suppose to print when a 1 is entered. The html and php code are shown below. <html> <body> <?php if ($_POST['num'] = 1) { echo "We're sorry to hear you're not pleased. How can we improve?"; } else if ($_POST['num'] = 2) { echo "That's not a very good rating. We will do our best to improve."; } else if ($_POST['num'] = 3) { echo "That's not bad, but I'm sure we could do better."; } else if ($_POST['num'] = 4) { echo "Thank you for the good rating."; } else if ($_POST['num'] = 5) { echo "We're glad to hear you are so pleased with our service and look forward to serving you in the future!"; } else { echo "You entered an invalid value, try again."; } ?> </body> </html> <html> <body><form action="practicephp.php" method="post"> Enter a number to rate our service: <input type="text" name="num"> <input type="submit" value="submit"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/111587-solved-using-ifelse-in-a-request-form/ Share on other sites More sharing options...
tpimental Posted June 24, 2008 Share Posted June 24, 2008 They should be "elseif" not "else if" Link to comment https://forums.phpfreaks.com/topic/111587-solved-using-ifelse-in-a-request-form/#findComment-572773 Share on other sites More sharing options...
Wolverine68 Posted June 24, 2008 Author Share Posted June 24, 2008 You're right. Thanks for pointing that out. Still have the same problem though. Link to comment https://forums.phpfreaks.com/topic/111587-solved-using-ifelse-in-a-request-form/#findComment-572775 Share on other sites More sharing options...
tpimental Posted June 24, 2008 Share Posted June 24, 2008 The "=" signs should be "==" (2 equal signs) Link to comment https://forums.phpfreaks.com/topic/111587-solved-using-ifelse-in-a-request-form/#findComment-572786 Share on other sites More sharing options...
Wolverine68 Posted June 24, 2008 Author Share Posted June 24, 2008 Thanks. Link to comment https://forums.phpfreaks.com/topic/111587-solved-using-ifelse-in-a-request-form/#findComment-572790 Share on other sites More sharing options...
hitman6003 Posted June 24, 2008 Share Posted June 24, 2008 They should be "elseif" not "else if" Either way works... In PHP, you can also write 'else if' (in two words) and the behavior would be identical to the one of 'elseif' (in a single word) -- http://www.php.net/control-structures.elseif Link to comment https://forums.phpfreaks.com/topic/111587-solved-using-ifelse-in-a-request-form/#findComment-572791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.