Hello,
Is there a code that will prevent or notify the encoder not to allow blank field?
Please advise. Thanks.
Hello,
Is there a code that will prevent or notify the encoder not to allow blank field?
Please advise. Thanks.
The stuff in bold is confusing me so.
Are you asking if there is a way PHP can check for blank form fields?
Sorry for the wrong grammar.
Let me say this way.
Example
Name: _____
Address: ______
Phone Number: _____
If there are any field that is black or not filled up. It will return an error like this.
Error:
I hope this is clear. Thank you.
Yes. Instead of using java script.
Easy
All you have to do is check if the input element is empty by calling its ID from the $_POST array.
So if you have a form field control such as:
<input type="text" name="personName" id="fullName" />
And the person clicks a submit button with the following code below:
<intput type="submit" name="sendData" id="checkEmpty" />
All one has to do is:
[php]
<?php // If form is submitted (sending data to server) if(isset($_POST['checkEmpty'])) { // Check if control fullName is not set or is empty if(!isset($_POST['fullName']) || $_POST['fullName'] === "") { //Print out a message to the user that a field is empty print("We can't greet you properly if we don't know your name!"); } } [/php]Here is my code.
In here I need the system not to accept blank field. This also include the publisher must have a content.
[code]<?php
$errorMessage = ‘’;
if (isset($_POST[‘submit’])){
include ‘db.php’;//Connect to database
$title=$_POST[‘title’] ;
$author= $_POST[‘author’] ;
$name=$_POST[‘name’] ;
$copy=$_POST[‘copy’] ;
$title_search = mysql_query(“SELECT Title FROM books WHERE Title=’$title’ AND Author=’$author’”);
if(mysql_num_rows($title_search) != 0) {
$errorMessage = ‘Record Already Exist!
’;
$errorMessage = $errorMessage . ‘Testing another error message.’;
}else {
$ins = mysql_query(“INSERT INTO books
(Title, Author, PublisherName, CopyrightYear) VALUES (’$title’, ‘$author’, ‘$name’, ‘$copy’)”);
if($ins) { // make sure the insert was sucessfull before clearing data
unset($_POST[‘title’]);
unset($_POST[‘author’]);
unset($_POST[‘name’]);
unset($_POST[‘copy’]);
}
}
}
mysql_close($conn);
?>
Title: | ||||||||
Author | ||||||||
Publisher Name |
- Select -
<?php
include 'db.php';
|
I successfully made it to work. Just made it simple.
see the code below
[php] if( $_POST[foperator] == ‘’)
{
$errorMessage = $errorMessage . ‘Operator field is required! Who handled this lot?
’;
}
if( $_POST[fprocess] == '0')
{
$errorMessage = $errorMessage . '<font color="red">Please select what process this lot came from</font><br>';
}
if( $_POST[fmodel] == '0')
{
$errorMessage = $errorMessage . '<font color="red">Please select what model is the lot. If the model do not exist, please add it using <b>Add model name menu</b></font><br>';
}
if( $_POST[flotno] == '')
{
$errorMessage = $errorMessage . '<font color="red">Lot Number cannot be blank!</font><br>';
}
if( $_POST[finput] == '' or $_POST[finput] == 0)
{
$errorMessage = $errorMessage . '<font color="red">Input field must have a value and not zero or blank!</font><br>';
}
[/php]