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";	

}


?>

Link to comment
Share on other sites

well the submit is under isset().. it's the next part down that's not working, if i leave an empty title or body it still says "message has been sent" and data is put into the table as blanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.