checking a blank textarea

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!

Moderator: General Moderators

Post Reply
bxm_3
Forum Newbie
Posts: 13
Joined: Sun Nov 20, 2005 6:23 pm

checking a blank textarea

Post by bxm_3 »

Code: Select all

<?php
if(($ID==""))
{
 header("Location:view_job1.php"); 
 exit();
}
?>
<html>
<head>
<title>Update Job Details</title>
<script language="javascript">
function check(form1)
{
   var errors=new Array();
 if(document.form1.NAME.value=="")
 {
  errors.push("Please enter the vacancy title.");
 } 
  if(document.form1.VACANCY.value=="")
 {  
  errors.push("Please enter the vacancy description.")   
 }
  
 if(document.form1.NAME.value!="")
 {
  if(document.form1.NAME.value.length>50)
  {
   errors.push("Too much information for the vacancy name.") 
  }
 }

 if(document.form1.VACANCY.value!="")
 {
  errors.push("Not Please enter the vacancy description.") 
  if(document.form1.VACANCY.value.length>65500)
  {
   errors.push("Too much information for the vacancy description.") 
  }
 }
 if(errors.length>0)
 {
  var msgs="The following error(s) occured:\n";
  //alert(msgs);
 }
 if(errors.length>0)
 {
  var msg="The following error(s) occured:\n";
  //var msgs="The following error(s) occured:\n";
  for(i=0;i<errors.length;i++)
  {
  //   msg+=errors[i]+"\n";
       //alert(msgs);
       msg+=errors[i]+"\n";
  // msg+=errors[3]+"\n";
     alert(msg);
     
  }
 }
 if(document.form1.NAME.value=="")
 {
   //alert("Please enter the vacancy title.");
   document.form1.NAME.focus();
   document.form1.NAME.select();
   return false;    
 }
 if(document.form1.NAME.value!="")
 {
  if(document.form1.NAME.value.length>50)
  {
   //alert("Too much information for the vacancy name.") 
   document.form1.NAME.focus();
   document.form1.NAME.select();
   return false;  
  }
 }
 if(document.form1.VACANCY.value=="")
 {    
   //alert("Please enter the vacancy description.");
   document.form1.VACANCY.focus();
   document.form1.VACANCY.select();
   return false;
 }
 if(document.form1.VACANCY.value!="")
 {
  //alert("Not Please enter the vacancy description.");
  if(document.form1.VACANCY.value.length>65500)
  {
   //alert("Too much information for the vacancy description.") 
   document.form1.VACANCY.focus();
   document.form1.VACANCY.select();
   return false;
  }
 }
  
  var string11,string12,string1,string2

  string11=document.form1.NAME.value
  string12=string11.replace(/[(&'#"£%)]/g,"-")
  document.form1.NAME.value=string12

  string1=document.form1.VACANCY.value
  string2=string1.replace(/[(&'#"£%)]/g,"-")
  document.form1.VACANCY.value=string2
}
</script>
</head>
<body>
<?php
# connect to mysql
$conn=@mysql_connect("mysql.hosts.co.uk","","*******")
or die("Could not connect to the database.");

# connect to database
$rs=@mysql_select_db("");


$sql="select * from JOB where ID='$ID'";

$rs=@mysql_query($sql);
?>

<?php

while($row=mysql_fetch_array($rs))
{
  
$ID=$row[ID];
$NAME=$row[NAME];
$VACANCY=$row[VACANCY];
?>

<br>
<form name="form1" action="update_jobs.php" method="post" onSubmit="return check(this)">
<table>
<tr>
<td>
ID</td><td><input type=text size="50" name=ID value="<?php echo $ID ?>" readonly></td></tr>
<tr><td>
Name</td><td><input type="text" size="50" name="NAME" value="<?php echo $NAME ?>"></td></tr>
<tr>
<td>
Vacancy</td><td><textarea  rows="4" cols="45" name="VACANCY"> <?php echo $VACANCY ?>
</textarea></td></tr>
<tr><td>
<input type="submit" name="submit" value="submit"></td></tr>
</form>
<br>

<br>

<?php
 } 
?>
</body>
</html>

Code: Select all

<?php
if(($NAME=="")or($VACANCY==""))
{
 header("Location:view_job1.php"); 
 exit();
}
?>
<?php
# connect to mysql
$conn=@mysql_connect("mysql.hosts.co.uk","*****","**********")
or die("Could not connect to the database.");

# connect to database
$rs=@mysql_select_db("*******");
$rss=@mysql_select_db("***********");


$sql="select * from EVENTS order by ID desc limit 1";

## posts in the last day
##$sqls="select * from FEEDBACK1 where TO_DAYS(NOW()) - TO_DAYS(TIME) <1";


$rs=@mysql_query($sql);

$num=mysql_numrows($rs);
##echo $num;

##$num++;

while($row=mysql_fetch_array($rs))
{
  if($num!=0)
  {

   ##echo $row["ID"];
   $row["ID"]++;
   ##echo $row["ID"];
   $nums=$row["ID"];
  }
  else
  {
   $nums=1;
  }

}
?>


<?PHP
##$sqls="insert into EVENTS (ID,EVENT,ADDRESS,DATE,TIME_START,PLACE,MAP_LINK,DESCRIPTION,TIME)
##values('$nums','$EVENT','$ADDRESS','$DATE','$TIME_START','$PLACE','$MAP_LINK','$DESCRIPTION',NOW())";
$sqls="update JOB set NAME='$NAME',VACANCY='$VACANCY'where ID='$ID'";
 $rsS=@mysql_query($sqlS);
 $rss=@mysql_query($sqls,$conn) or die("Could not execute insertion.");
 if($rss)
 {
  
  echo"Here is the information you have updated to the database.";
  echo"<BR>";
  echo"<TABLE>";
  echo"<TR>";
  echo"<TD>";
  echo"<B>NAME</B>";
  echo"</TD>";
  echo"<TD>";
  echo $NAME;
  echo"</TD>";
  echo"</TR>";
  echo"<TR>";
  echo"<TD>";
  echo"<B>VACANCY</B>";
  echo"</TD>";
  echo"<TD>";
  echo $VACANCY;
  echo"</TD>";
  echo"</TR>";
  echo"</TABLE>";
 }

?>
In the top code. I have selected a row of code to be updated. Some of the information is placed on textfields while some is placed on textarea. If I remove the information from a textarea , there is no detection of a blank textarea, and the page which recieves the blank page does not detect a blank area so I have a field in my row on the database. What is the problem? I can detect a non blank textarea and a blank text field. I can detect a blank textarea if it is new information to be inserted.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your text area isn't actually blank, but has white space characters in it.. try using strlen() against a trim() of the information.
Post Reply