Sorry for posting again. :| I'm working on this simple evaluation system for our final requirement in this subject. it's working now. my problem is I want to have an error checking (if it's the right term for that). if they leave one textbox blank?

the flow will be, if one textbox leaves blank and when you click submit the output will be "All fields required." then if all fields are filled the output will be "Thank you for your cooperation" then the data entered will be saved to the database.

The action of my submit button is RESULT.PHP
here is the code for it

<?php

$a=$_POST['a'];
$b=$_POST['b'];
$c=$_POST['c'];
$d=$_POST['d'];
$totala=($a+$b+$c+$d/4)*.10;

$e=$_POST['e'];
$f=$_POST['f'];
$g=$_POST['g'];
$h=$_POST['h'];
$i=$_POST['i'];
$j=$_POST['j'];
$totalb=($e+$f+$g+$h+$i+$j/6)*.25;

$l=$_POST['l'];
$m=$_POST['m'];
$n=$_POST['n'];
$o=$_POST['o'];
$p=$_POST['p'];
$q=$_POST['q'];
$r=$_POST['r'];
$s=$_POST['s'];
$t=$_POST['t'];
$totalc=($l+$m+$n+$o+$p+$q+$r+$s+$t/9)*.25;

$u=$_POST['u'];
$v=$_POST['v'];
$w=$_POST['w'];
$x=$_POST['x'];
$totald=($u+$v+$w+$x/4)*.15;

$y=$_POST['y'];
$z=$_POST['z'];
$aa=$_POST['aa'];
$totale=($y+$z+$aa/3)*.15;

$bb=$_POST['bb'];
$cc=$_POST['cc'];
$dd=$_POST['dd'];
$ee=$_POST['ee'];
$ff=$_POST['ff'];
$gg=$_POST['gg'];
$totalf=($bb+$cc+$dd+$ee+$ff+$gg/6)*.10;

$totalg=($totala+$totalb+$totalc+$totald+$totale+$totalf)/6;

$con = mysql_connect("localhost","-----","-----");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("----", $con);

$sql="INSERT INTO evaluate (Fname, Date, Subject, TotalA, TotalB, TotalC, TotalD, TotalE, TotalF, TotalG)
VALUES ('$_POST[faculty]','$_POST[date]','$_POST[subject]',$totala,$totalb,$totalc,$totald,$totale,$totalf,$totalg)";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Sucessful! Thank you very much for Your kind cooperation";

mysql_close($con)
?> 
<br /><br />
<a href="evaluate.html">Back</a>

my problem is. how will i enter the code for error checking? with those multiple fields? Sorry i can't quite figure out how. i have this idea :

<?php
$e=$_POST['a'];
$f=$_POST['b'];


if ($e=="" && $f==""){
	echo"All fields required";}
else{
	echo "Thank you for your kind cooperation!";
}
?>

but then it's for 2 textbox only and i don't use database here. aww.

Recommended Answers

All 6 Replies

Member Avatar for P0lT10n

use javascript... if all okey, submit !

use javascript... if all okey, submit !

thanks! :) it's okay now. :)

Member Avatar for P0lT10n

;)

Miss Indie, how did you do it?! how to check textboxes with empty and reload the page without removing you entered in other field . ..

Anyone can help please need it .. .!

Using jquery:

$(":checkbox").each(function() {
   if($(this).val() === "")
    alert("Empty Fields!!");
});

using java script:-

<script>
var value=getElementById('inputboxid').value ;
if(value==''){
alert('input box is empty');
}
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.