PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$projectname = $_POST['pname1'];
if (isset($_REQUEST['submit'])) {
# THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE
$query = "INSERT INTO conmg.Job_ID (Job_ID, Job_Name) VALUES (NULL, '$projectname')";
if($result = mysql_query($query)) {
echo "$projectname has been added, please fill in the details below:";
} else {
echo "ERROR: ".mysql_error();
}
}
Is there anyway to display an error message if the projectname field was left empty? because right now even if the field is empty it gets added to the database.
Validation on the client side is only a good idea if you're going to double check it on the server side.
You're better off just using server side validation and halfing the work (unless you're an exceptional case and want to minimise page requests). Just use something like
if (isset($projectname))
{
mysql_query $query;
echo "$projectname has been added, please fill in the details below:";
}
else if (!$projectname)
{
echo "Project name was not inserted!";
}
else
{
echo "ERROR: ".mysql_error();
}