Empty form field no insertion

Hi guys,

Is it possible to stop an insertion if a form field is empty?
I have a form with multiple insertion to three different tables. One of the fields might actually be empty in most cases and the code as it is now inserts a blank ‘cname’ field and the correct $exid if the name field is blank. Since this is for people who is not very used to fill out forms I need to show the field from the start.
This is the form field in question:

<b>Kurator(er):</b><br />
<input type="text" name="cname[]" size="60"><br/>
<input type="hidden" name="exhibitid[]" value="<?php echo "$exid"; ?>">

This it the insertion code:

	$len = count($_POST['cname']);
	for ($i=0; $i < $len; $i++)

foreach ($_POST['cname'] as $i=>$cname) {
if ($_POST['cname'] != "") //checks if the field is empty, right?
echo '<p>No curator added</p>';
} else {
$sql3 = "INSERT INTO curator SET
  if (@mysql_query($sql3)) {
    echo '<p>En kurator er lagt til / curator added!</p>';

I’m not getting the empty fields check working. As the code is by now it’s not inserting anything at all.
If the cname field is empty I want no insertion and a message that “No curator was added”. If the cname field is not empty I want the insert array to continue.
Appriciate any help! Thanks!

you should use javascript to initially do this check and then double check in php later on.
<form onsubmit=“return theChecker()” method=“POST” action=“?whatever”>
…form contents here…

in the javascript function:
function theChecker() {
if (blankfield) return false;
else return true;

Please note the above is pseudo code. If you need more info just shout!

…and then once the form has been submitted then do a check in php to see if values are blank:

$val1 = $_POST[“val1”];
if ($val1==“”) header(“Location: http://blabalba.com/?msg=BLANK+ITEM!”);

I was hoping I could stop the insert in just php because there is no alternative for the user. For some users this field will stay empty.

I’ll rather make a script that deletes all rows with empty cname field.

Well then why don’t you just check if it can be empty for that user, and if not then don’t insert?