Jump to content

Recommended Posts

i am working on a page where office staff enters info on scheduling a doctor for on-call duty. the page has info like  date, shift, Doctors name(Provider) and Location fields and a Add button.

 

staff selects the date from the calendar, selects a shift from the drop-down, selects a Provider and Location from the drop-down boxes.

 

When page loads, shift drop-down box defaults to the first value(Shift 1) and Provider and Location fields are defaulted to blank. These fields are to be made mandatory. i am trying what i did on othre screens and it doesnt seem to work here. if i hit the Add button without choosing values for these two fields(just leaving them blank) all validations are skipped.

 

i am attaching the code here:

admit_stat <?PHP

//File for database information

//require_once ("phpInclude/config.php");
require_once ("../config.php");

//File to verify authenticated user

include ("phpInclude/cookie.php");
$messages=$_GET["message"];


	$month = date("M");

	$month_number = date("n");

	$year = date("Y");

	$numberofdays = date("t");

	$month_day = date("j");

	$date = "$year-$month_number-$month_day";
	$today="$month_number/$month_day/$year";
	//echo "$today";



function option_select($month_year_day, $t)

{

	if($month_year_day == $t)

	{

		print "<option value=$t selected>$t</option>";

	}

	else

	{

		print "<option value=$t>$t</option>";

	}

}


$message = "";

$goodMessage = "";




if(isset($_POST["action"]))

{
	$Year = $_POST["year"];

	$month = $_POST["Month"];

	$day = $_POST["Day"];

	$wDay=$_POST["wDay"];


	$oncall_id=$_POST["oncall_id"];

	$date = $Year."-".$month."-".$day;
	$date1 = $month."/".$day."/".$Year;
	//echo "$date";
	$time = $_POST["shift"];
	//echo "$time";
	$phy_id = $_POST["phy_id"];
	//echo "$phy_id";
	$gr_loc = $_POST["gr_loc"];
	//echo "$gr_loc";
	//print("LOC IS...: " .$gr_loc);
	if ($gr_loc == "")
	{
		$gr_loc = 1;
	}

	$timedisplay = $_POST["shift"];

	mysql_query("SET AUTOCOMMIT=0");

	$query = "SELECT oncall_id FROM oncall WHERE oncall_id='$oncall_id' ";

	$result = mysql_query($query);

	$num_rows = mysql_num_rows($result);

	print("");


	if($num_rows > 0)

	{

		$row = mysql_fetch_array($result);

		$oncall_id = $row["oncall_id"];

		$queryupdate=(" UPDATE oncall

					   SET

					   oncall_phy_id = '$phy_id',
					   oncall_org_id = '$gr_loc',
					   oncall_time =  '$time',
					   oncall_date = '$date',
					   oncall_day = '$wDay'

					   WHERE oncall_id ='$oncall_id' ");
		$resultupdate=mysql_query($queryupdate);
		if (! $resultupdate){
							 $error= "Error 500";
							 echo "here";
							}

		else{
			$message = "On-Call Schedule has been changed.<br>Here is a list of the last 5 schedules added.<br><br>Click on Add On-Call to add another schedule or View-on-Call:Day or View-on-Call:Month to view existing On-Call schedules. ";
			}
	}

	else

	{


		  $queryz="INSERT INTO oncall  (oncall_phy_id, oncall_org_id, oncall_time, oncall_date, oncall_day) VALUES ('$phy_id','$gr_loc','$time','$date', '$wDay')";
			//echo "$queryz";
			$resultz = mysql_query($queryz);

			if (! $resultz){
							$error= "Error 501";
							}

		  else{
		  		$message= "<font class=goodTXT><b>On-Call Schedule has been added.</b></font><br>Here is a list of the last 5 schedules added.<br><br>Click on <b>Add On-Call to add another schedule<b> or <b>View-on-Call:Day or View-on-Call:Month<b> to view existing On-Call schedules. ";
		 		}
		//echo "Here1";

	}

	if (isset($error))
	{
		$message = "Please try again later - Database $error";
		//echo "$error";
		mysql_query("ROLLBACK");
		mysql_close();
		//exit;
	}
	else
	{
		mysql_query("COMMIT");
		//print("Success");
	}
 	header("Location: oncall.php?"."message=".$message );
}

$query="select oncall_id, oncall_phy_id, oncall_org_id, oncall_day, oncall_time, date_format(oncall_date, '%m/%d/%Y') as date from oncall where oncall_date='$date' ";



if($phy_id != 0)

{

	$query .= " AND oncall_phy_id='$phy_id' ";

}


$query_location="SELECT org_name from orgs where org_ID='$location'";
$resultz=mysql_query($query_location);
$rowz=mysql_fetch_array($resultz);
$org_namez=$rowz["org_name"];

$query .= " AND oncall_org_id='$location' ";




$query .= " order by oncall_date ASC";

$result = mysql_query($query);

$num_rows = mysql_num_rows($result);


$querylistdt="SELECT Date_Format(oncall_date, '%m/%d/%Y') as oncall_date, oncall_time, phy_fname, phy_lname,org_name from oncall oc, phy_det pd,orgs o
			  where oc.oncall_phy_id = pd.phy_id
			  and oc.oncall_org_id = o.org_id
			  order by oncall_id desc limit 5
			 ";

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>ABC</title>

<link rel='stylesheet' type='text/css' href='css/styleSheet.css'>

<SCRIPT language="JavaScript" src="js/tree.js">

</SCRIPT>

<SCRIPT language="JavaScript" src="js/validateSSN.js"></SCRIPT>
<SCRIPT language="JavaScript" src="date-picker.js"></SCRIPT>

<SCRIPT language="JavaScript">

function validate()
{
var err_msg = new Array();

var i=0;

var j=0;

var bigstring = "Please correct the following errors:\n";

var loginID = "";

var pass = "";

var count = 0;

var aMatch = false;

var aBlank = false;

var AppDate = document.oncall.datebox.value;
var aDate = AppDate.split("/");
var aMonth = aDate[0];
var aDay = aDate[1];
var aYear = aDate[2];

var ADate = new Date(aYear, (aMonth - 1), aDay);
var Today = new Date();
var TodayDay = Today.getDate();
var TodayMon = Today.getMonth()+1;
var TodayYear = Today.getYear();

//alert(aMonth);
var ADate = new Date(aYear, (aMonth - 1), aDay);
var TodayDate = new Date(TodayYear, TodayMon-1, TodayDay);

if (ADate < TodayDate)
{
	err_msg[i] = "Entered date cannot be less than today's date.";
	i++;
}

if ((TodayMon == '1') || (TodayMon == '3') || (TodayMon == '5') || (TodayMon == '7') || (TodayMon == '8') || (TodayMon == '10') || (TodayMon == '12'))
{
	if (TodayDay > 31)
	{
		err_msg[i] = TodayMon . " has only 31 days";
	}
}

if (oncall.physician.value == "")
	{
		err_msg[i] = "Preferred Provider cannot be blank.";
		i++;
}

if (i>0)
{

	for (j=0; j<err_msg.length; j++)
	{
		count = j + 1;

		bigstring = bigstring + "\n" + count +". " + err_msg[j];
	}

	alert (bigstring);

	return false;
}
else
{

	return true;

}

}

</SCRIPT>


</head>



<BODY>

<table width="900" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="4" bgcolor="#FFFFFF">
      <div align="left"><font color="#FFFFFF"><b>
        </b></font></div>
      <div align="right"><font color="#FFFFFF"><img src="images/title_barom.jpg" width="900" height="69"></font></div></td>
  </tr>
  <tr>
    <td align="left" valign="top" width="276"> <table width="276" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="left" valign="top"><div align="center"><font color="#006699"><img src="images/clear.gif" height="15" width="1"><b><?PHP print($group_name); ?><br>
              User: </b><?PHP print($USER_NAME); ?></font></div></td>
        </tr>
        <tr>
          <td align="left" valign="top"> <SCRIPT language="JavaScript">

   tree.loadState()

   tree.display()

</SCRIPT> </td>
        </tr>
      </table>

<p align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><? print("<b>$copyright1</b>"); ?></p>
</td>
    <td colspan="3" align="left" valign="top" width="624"> <div align="center">
        <br>
      </div>
      <table width="614" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#006699">
        <tr>
          <td bgcolor="#006699" width="359" height="19"> <div align="left"><b><font color="#FFFFFF">Add
              On-Call Schedule</font></b></div></td>
          <td bgcolor="#006699" width="249" height="19" valign="top"> </td>
        </tr>
        <tr>
          <td colspan="2"> <table width="592" border="0" cellspacing="0" cellpadding="0">

              <tr>
                <td width="15"> </td>
                <td rowspan="3" align="left" valign="top"> <form name="oncall" method="post" action="checkoncall.php" onSubmit="return validate()" >
                    <table width="450" border="0" cellspacing="0" cellpadding="0" align="center">
                      <tr>
                        <td width="196" height="22"> <div align="right"><font class="inputLbl">Date:  </font></div></td>
                        <td width="130"> <input type='text' name='datebox' readonly value="<?
                        								//if coming to the screen first time, print $today - which is the current date. else, print the date in the post variable - $date1
                        								//print ("$today"); print ("$date1");print ("asdfas");
                        								if($date1 == "")
                        									{
                        										print ("$today");
                        									}
                        									else
                        									{
                        										print ("$date1");
                        									}
                        									 ?>" size=15 >
                        </td>
                        <td width="124"><div align="left"><a href="javascript:show_calendar('oncall.datebox');" onmouseover="window.status='Date Picker';return true;" onmouseout="window.status='';return true;"><img src="show-calendar.gif" width=24 height=22 border=0 align="absmiddle"></a></div></td>
                      </tr><script language="JavaScript">

                      </script>
                      <tr>
                        <td width="196"> <div align="right"><font class="inputLbl">Schedule:  </font></div></td>
                        <td colspan="2"> <? //print($time); ?><select name="shift" >
                            <!--if coming to the screen for the first time, print show Shift1 as default, else show last selected value as default-->
                            <option value="Shift 1" <? if ($time == "Shift 1")  print("selected"); ?>>Shift 1</option>
                            <option value="Shift 2" <? if ($time == "Shift 2")  print("selected"); ?>>Shift 2</option>
                            <option value="Shift 3" <? if ($time == "Shift 3")  print("selected"); ?>>Shift 3</option>
                            <option value="Day" <? if ($time == "Day")  print("selected"); ?>>Day</option>
                            <option value="Night" <? if ($time == "Night")  print("selected"); ?>>Night</option>
                            <option value="24 Hours" <? if ($time == "24 Hours")  print("selected"); ?>>24 Hours</option>
                            <option value="Weekend" <? if ($time == "Weekend")  print("selected"); ?>>Weekend</option>

                          </select> </td>
                      </tr>
                      <tr>
                        <td width="196"> <div align="right"><font class="inputLbl">Provider:  </font></div></td>
                        <td colspan="2">
                          <?PHP
						$queryphy="select phy_id, phy_fname, phy_lname from phy_det where phy_disabled = 'Enable' order by phy_lname, phy_fname";
						$resultphy = mysql_query ($queryphy);
						 if ($resultphy)
						 {
							print ("<select name='physician'>\n");
							print ("<option value=\"\"></option>\n");
							while($rowphy = mysql_fetch_array($resultphy))
							{
								if($pat_phy_id == $rowphy["phy_id"])
								{
									print ('<option selected value="'.$rowphy["phy_id"].'">'.$rowphy["phy_lname"].', '.$rowphy["phy_fname"].'</option>');
								}
								else
								{
								   print ('<option value="'.$rowphy["phy_id"].'">'.$rowphy["phy_lname"].', '.$rowphy["phy_fname"].'</option>');
								}
							}
							print ("</select>");
						}

					  ?>
					  <font class="redTxt">*</font>
                        </td>
                      </tr>
                      <tr>
                        <td width="196"> <div align="right"><font class="inputLbl">Location:  </font></div></td>
                        <td colspan="2">
                          <?PHP

							$querys="SELECT org_ID, org_name FROM orgs where org_type !='Office' order by org_name ASC";
							$results= mysql_query ($querys);

							if ($results)
							{

								print ("<select name='location'>\n");
								print ("<option value=\"\"></option>\n");

								//print ("<option value='0' selected>ANY</option>");

								if ($row= mysql_fetch_array($results))
								{
									do
									{

										  print ("<option value=\"");

										  print $row["org_ID"];

										  print ("\">");

										  print $row["org_name"];

										  print ("</option>");

									}
									while ($row = mysql_fetch_array($results));
								}

							}

							print ("</select>");

					 ?>
					 <font class="redTxt">*</font>
                        </td>
                      </tr>
                      <tr>
                        <td width="196" align="left" valign="top"> </td>
                        <td colspan="2" align="left" valign="top"> </td>
                      </tr>
                      <tr>
                        <td width="196" align="left" valign="top"> <div align="right"><font class="inputLbl"> </font></div></td>
                        <td colspan="2" align="left" valign="top">  </td>
                      </tr>
                      <tr>
                        <td width="196" align="left" valign="top"> </td>
                        <td colspan="2" align="left" valign="top"> <input class="sbttn" type="submit" name="action" value="Add">
                        </td>
                      </tr>
                    </table>
                  </form></td>
                <td width="15"> </td>
              </tr>
              <tr>
                <td width="15" height="86"><img src="../images/clear.gif" width="15" height="8"></td>
                <td width="1" height="86"> </td>
                <!--<td width="104" height="146"><img src="../images/clear.gif" width="15" height="8"></td>-->
              </tr>
            </table><div align="center">
            <img src="../images/clear.gif" width="15" height="1"> <table width="536" border="0" cellspacing="0" cellpadding="0">
		  <tr>
                <td colspan="5" height="7"> <div align="center"><? print ("$messages"); ?>
                  </div></td>
              </tr>
              <tr>
                <td width="15"> </td>
                <td width="15"> </td>
              </tr>

              <tr bgcolor="006699">

                <td width="110"> <div align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Date</font></b></div></td>
                <td width="36"> <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">   Time</font></b></div></td>
                <td width="170"> <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">         Provider
                    Name</font></b></div></td>
			<td width="175"> <div align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">               Location</font></b></div></td>
		  </tr>

			<tr  bgcolor=\"#cccccc\">
			<tr>

			<!--<td width="100"> <div align="center"><?PHP print ($list_date); ?></div></td>
			 <td width="117"> <div align="center"><?PHP print ($list_time); ?></div></td>

			<td width="177"> <div align="center"><?PHP print ($list_phyfname); print (","); print ($list_phylname); ?>

			  </div></td>
			<td width="176"> <div align="center"><?PHP print ($list_org); ?></div></td>-->
			  <?
					$resultlistdt=mysql_db_query("$database[dbname]", $querylistdt);
					$num_rows=mysql_num_rows($resultlistdt);
					$num_results=mysql_num_rows($resultlistdt);

					$i=1;

					if(!isset($rowNum))
					{
						$rowNum = 0;
					}

					$rowNumHold = $rowNum;

					if ($num_rows > 0)
					{
						for($q=0;$q<$num_rows;$q++)
						{
							if(mysql_data_seek($resultlistdt, $rowNum++))
							{
								if ($i++%2)
								{
									print ("<tr  bgcolor=\"#cccccc\">");
								}
								else
								{
									print ("<tr>");
								}

								$row = mysql_fetch_object($resultlistdt);
								print("<td height=\"14\"> <div align=\"center\">");
								print($row->oncall_date);
								print("</div></td>");
								print("<td height=\"14\"> <div align=\"center\">");
								print($row->oncall_time);
								print("</div></td>");
								print("<td height=\"14\"> <div align=\"center\">");
								print($row->phy_fname);
								print(" ");
								print($row->phy_lname);
								print("</div></td>");

								print("<td height=\"14\"> <div align=\"center\">");
								print($row->org_name);
								print("</div></td>");


								print("</div></td>");
								print("</tr>");
							}
						}


					}
				?>
	<tr>
              <tr>
                <td width="15"><img src="../../images/clear.gif" width="15" height="8"></td>
                <td width="15"><img src="../../images/clear.gif" width="15" height="1"></td>
              </tr>


              <tr>



			  <tr>
				<td colspan="3"><img src="../../images/clear.gif" width="1" height="15"></td>
			  </tr>
            </table></td>

        </tr>
      </table>
      <p> </p></td>
  </tr>
  <tr>
    <td align="left" valign="top" width="276"> </td>
    <td colspan="3" width="624"> </td>
  </tr>
</table>


</body>

</html>

<?PHP

mysql_close();

?>

 

how do i make sure that these fields are chosen and not blanks before going over to the next screen - checkoncall.php where the user can click on Submit button to insert info into the database?

 

help is badly needed on this one. i know its a small issue, but i am not able to get around it.

 

thanx

If u want to simple validate the fields than try this:

 

 $required_fields = array( 'tchno','nmname','userid','pass','cpass');
    foreach ($required_fields as $field) {
    if (!isset($_POST[$field]) || empty($_POST[$field])) {
       error("One or more required fields were left blank. \\n Please fill them in and try again.".mysql_error());
      } else {
         $cleaned_for_sql[$field] = mysql_real_escape_string($_POST[$field]);
     }
    }

 

Change the attributes according to ur script in the array.

 

Other if u want to use regex than look at this:

 

if ( !preg_match('/^[a-zA-Z\" "]*$/', $name) )
       {
        error('The Name that you have given is not valid.\\n'.
                'Please try again.');
          }

 

Hope this will help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.