Function echo not working

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
jauson
Forum Contributor
Posts: 111
Joined: Wed Oct 05, 2011 12:59 am

Function echo not working

Post by jauson »

session_start();
include 'conn.php';
echo 'Welcome Back: <strong>'.$_SESSION['username'].'</strong>';


if (isset($_POST['id'])&&isset($_POST['DateApplied'])&&isset($_POST['LeaveType'])&&isset($_POST['LeaveFrom'])
&&isset($_POST['LeaveTo'])&&isset($_POST['CC'])&&isset($_POST['To'])&&isset($_POST['Message'])&&isset($_POST['Subject'])){

$id =$_POST['id'];
$DateApplied =$_POST['DateApplied'];
$LeaveType =$_POST['LeaveType'];
$LeaveFrom =$_POST['LeaveFrom'];
$LeaveTo =$_POST['LeaveTo'];
$CC =$_POST['CC'];
$To =$_POST['To'];
$Message=$_POST['Message'];
$Subject =$_POST['Subject'];


if (!empty($To)&&!empty($CC)&&!empty($Message)&&!empty($Subject)){
echo 'OK';
} else {
echo 'NOT OK';
}



}

hi please help. function not empty not working. echo "NOT OK" i didnt see when i hit submit.

heres my html code.



<?

if (isset($_SESSION['username']) == true){

$username = $_SESSION['username'];
$query = mysql_query("SELECT * FROM `employeeleavedetails` WHERE `username`='$username'");

}
while ($count = mysql_fetch_assoc($query)){
?>


<html>
<center>
<table>
</center>
<form action="LeaveApplication.php" method="POST">
<table border="1" align="center" width="450" bgcolor="GRAY">
<tr>
<td colspan="1" bgcolor="GOLD" align="center"><font size="2"><strong> Applicant </font></strong></td>
</tr>
<tr>
<td><font size="2" color="white"> Employee ID:</font>
<font color="White">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="assignedID" value="<?php echo $count['assignedID']?>" size="3" readonly></font>
<input type="hidden" name="id">
<tr>
<td>
<font size="2" color="white"> Employee Name: </font> <font color="white">&nbsp; <input type="text" name="FullName" value="<?php echo $count['FullName']?>" readonly></font>
</td>
</tr>
</td>
</tr>
<tr>
<td colspan="4" bgcolor="GOLD" align="center"><font size="2"><strong> Employee Leave Information </font></strong></td>
<tr>
<td><font size="2" color="white"> Date Applied: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="DateApplied" value="<?php echo date("Y/m/d"); ?>" readonly></font>
<input type="hidden" name="DateApplied"/>
</tr>
<td><font size="2" color="white" name="LeaveType"> Type of Leave: &nbsp;&nbsp;&nbsp;</font>
<select name="">
<option value="Annual Leave"> Annual Leave </option>
<option value="Sick Leave"> Sick Leave </option>
<option value="Vacation Leave"> Vacation Leave </option>
</select>
</tr>
<td><font size="2" color="white"> Leave From: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font>
<input type="text" name="LeaveFrom" value="<?php echo date("Y/m/d") ?>">
<tr>
<td><font size="2" color="white"> Leave To: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font>
<input type="text" name="LeaveTo" value="<?php echo date("Y/m/d") ?>">
<tr>
<td colspan="4" bgcolor="GOLD" align="center"><font size="2"><strong> This information will be sent via Email </font></strong></td>
<tr>
<td><font size="2" color="white"> Recommending Officer:<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="CC">Ex. my.supervisor@yahoo.com</font>
</tr>
<tr>
<td><font size="2" color="white"> Approve By: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="To">Ex. hr.manager@yahoo.com </font>
</tr>
<tr>
<td><font size="2" color="white"> Subject: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="Subject"></font>
</tr>
<tr>
<td><font size="2" color="white"> Remarks: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font>
<textarea cols="45" rows="5" name="Message"></textarea>
</tr>
<center><font size="2">Annual Leave: <strong><?php echo $count['AnnualLeave']?></strong>
<font size="2">Sick Leave: <strong><?php echo $count['SickLeave']?></strong>
<font size="2"> Vacation Leave: <strong><?php echo $count['VacationLeave']?></strong> </font></center>
</table>
<br>
<center>
<input type="Submit" value="Apply">
<input type="Button" value="Reset">
<input type="Button" value="Exit" onclick="window.location='logout.php'">
</center>
<br>
</form>
<? }
mysql_close(); ?>
</html>
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Function echo not working

Post by twinedev »

The subject says that function echo isn't working, yet in the middle of a bunch of code you put a note about a problem with empty.

I would suggest that you edit your post and put the question at the top, and then in the editor use the

Code: Select all

 button to wrap the code you pasted. Trying to read a ton of code like that is very difficult (especially on my tired eyes)

Also in the middle you mention something about [b]empty[/b], try checking the manual for it to see what all evaluates as empty:

http://php.net/empty

Usually that is where there is a misunderstanding, that you think something should come back as empty when it doesn't.

-Greg
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Function echo not working

Post by social_experiment »

Code: Select all

if (!empty($To)&&!empty($CC)&&!empty($Message)&&!empty($Subject)){
echo 'OK';
} else {
echo 'NOT OK';
}
Probably because one of your variables is empty. Try doing print_r($_POST) to see if all your $_POST fields are populated. Could be a spelling mistake in a field name etc, have a closer look at the code :)

I was also about to tell you (OP) to wrap the code but i saw twinedev already did. Not only does wrapping the code make it easier to read but it also increases your chances of getting helped exponentially. Myself for example will often completely give the code a skip just because it's not wrapped so i would guess many others also have similar ideas towards unwrapped code. Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply