processing a form with if empty messages

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
php-forum Active User
php-forum Active User
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Tue Jan 22, 2013 12:51 am

You don't need to exit, you just need to assign the text to a variable and then echo the variable (not sure where you are getting score2 from either as nothing in your code so I have added it in as I think it should be)

Code: Select all

$msg = '';
$score1 = $_POST['score1'];
$score2 = $_POST['score2'];
if (empty($score1)) {
    $msg = "You haven't entered a score for score1";
} elseif (empty($score2)) {
    $msg = "You haven't entered a score for score2";
} else {       
    #connection here
    // if successful query assign a success message to the $msg variable
echo $msg;  

Post Reply