AdRock Posted July 29, 2006 Share Posted July 29, 2006 I am trying to validate my form to make usre that both the title field and the content field have something in before posting. I have managed to get the form to show an error message if the title field is empty but if the content field is empty and the title field not empty the form will post.How can I check to make usre both fields are not empty?[code]$title = addslashes($_POST['title']);$content = addslashes($_POST['content']);if (!isset($_POST['title'])) {?> <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <p class="style1"><label for="title">Please enter a title for the news item.</label> <input style="width:400px;" type="text" size="50" name="title"></p> <p class="style1"><label for="content">Please enter the content for the news item.</label> <textarea style="width:400px;" name="content" cols="30" rows="10"> </textarea></p> <input class="submit-button" style="margin-left:0" type="Submit" value="Submit"><input class="submit-button" style="margin-left:2px" type="reset" value="Reset"></form><?php}elseif (empty($title) || empty($content)) { echo $empty_fields_message;}else { // Stop the form being used from an external URL // Get the referring URL $referer = $_SERVER['HTTP_REFERER']; // Get the URL of this page $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]; // If the referring URL and the URL of this page don't match then // display a message and don't send the email. if ($referer != $this_url) { echo "You do not have permission to use this script from another URL."; exit; } // The URLs matched so send the email include_once("../includes/connection.php"); mysql_connect($host,$user,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO news VALUES ('','$title', '$content','')"; mysql_query($query) or die( "Unable to execute query" ); mysql_close(); // Display the thankyou message echo $thankyou_message; }[/code]I thought it would be to do with the [b]!isset[/b] but I don't know how to change it Link to comment https://forums.phpfreaks.com/topic/15949-form-validation/ Share on other sites More sharing options...
Guest docseussman Posted July 29, 2006 Share Posted July 29, 2006 did you try (!isset($_POST['title']) || !isset($_POST['content'])) ? Link to comment https://forums.phpfreaks.com/topic/15949-form-validation/#findComment-65592 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.