Jump to content

stopping blank values from being submitted


kirkh34

Recommended Posts

hello, i have a compose message file with a form that inserts data into tables, i'm trying to figure out how to make an error appear if they have left a title or body blank, i'm not sure why this isn't working, here is the code

<?php

session_start();


include_once "scripts/connect_to_mysql.php";

$logout = "";
$login_table = "";

$message_title= $_POST['message_title'];
$message_content= $_POST['message_content'];
$to_user= $_POST['to_user'];
$from_user= $_POST['from_user'];

if (isset ($_POST['submit'])){



if((!$message_title) || (!$message_content)){  

if (!$message_title){  
$msgToUser = "You need a title!";	
include_once "msgToUser.php";


}  

if(!$message_content){  
$msgToUser = "You need a body!";	
include_once "msgToUser.php";

}
} 
}

else {

$sql = mysql_query("INSERT INTO message_rec (to_user, message_content, message_title) 
     VALUES('$to_user','$message_content','$message_title')")  
or die (mysql_error()); 
$sql = mysql_query("INSERT INTO message_sent (from_user, message_content, message_title) 
     VALUES('$from_user','$message_content','$message_title')")  
or die (mysql_error()); 

$msgToUser = "Your message has been sent";	
include_once "msgToUser.php";	

}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.