processing a form with if empty messages

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

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

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
    $sql = "INSERT STATEMENT HERE";
    mysql_query($sql);
    // if successful query assign a success message to the $msg variable
 }        
echo $msg;  

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests