Hello,
I have been trying to develope an online registration system but i can get the right syntax to use in the developement
here are the specifications

We have the following types of visits
• Admission
• Control/Entry/ Visit2/ visit3(routine1)/ visit4(routine2)/ annual
• Acute(unscheduled visit)
On register response page, we should have a drop down with the 3 options, the with one of the second option active. As in option 1 and 3 are static but option 2 is dynamic.
STEP 1
Patient searched prior to regisration and added to demographic table if not exist
STEP 2 opregistration and ipregisration
Aim to search through op and ipregister and select current isit based on the existing record
Control visit:
Search opregiter,ipregister
If patient does not exist in opregister then select control
Add patient details in samps table

Entry visit
Search opregister,ipregister,
if exists in opregister and patient last visit in opregister==Control then visit type==entry OR
if patient exists in ipregister and does not exist in opregister then visit==entry
update samps table set visit1==1 after regstration

Visit2
Search opregister, ipregister.if patient exists in opregister and (samps.visit1==1 and visit2 is null and visit3==null and visit4 is null)
(opregister.lastvisitdate-datetoday)datediff<365
(visittype for lastvisitdate in opregister is not acute and lastvisittype in opregister is not control)
Update visit2==1 after registration
Visit3
Patient exists in opregister
Last visit type is not acute and last visit type is not control
Last visit date is not for an acute visit
Date diff < 365
Samps.visit1==1, samps.visit2==1, samps.visit3==null,samps.visit4==null
Update visit3 in samps to 1

Visit 4
Patient exist in opregister
Last visit type is not acute and last visit type is not control
Last visit date is not for an acute visit
Date diff < 365
Samps.visit1==1, samps.visit2==1, samps.visit3==1,samps.visit4==null
Update visit1 to visit4 in samps to null

Annual
Patient exists in opregister
Last visit date is not for an acute visit
Date diff >365
Update samps.visit1==1 samps.visit2==null,samps.visit3==null, samps.visit4==null after registration

codes for registration pages are
registerresponce.php
/////////////////

<?php 
session_start();
ob_start();
?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<? //include common files?>
<?php include ("ewconfig.php") ?>
<?php include ("db.php") ?>
<?php include ("advsecu.php") ?>
<?php include ("connect.php") ?>
<?php include ("defaults.php") ?>
<?php include ("ewupload.php") ?>
<?php
//check if user is logged in
if (!IsLoggedIn()) {
 ob_end_clean();
 header("Location: login.php");
 exit();
}
$id=$_GET['id'];
//echo $id;
$visittype=$_POST['visittype'];
$demographic_id = @$_POST["demographic_id"];
?>
<?php include ("header.php") ?>

<form name="fregisterresponce" action="opregisteradd.php">

<input type="hidden" name="id" id="id" value="<? echo $id; ?>">
<table class="bordercolor" cellpadding="2" cellspacing="1">
  <tr>
  <?php
$str_query = "Select
opregister.datetod, opregister.scdno,
opregister.visittype,samps.zpp,samps.serum,samps.visit1,samps.visit2,samps.visit3,samps.visit4,DATEDIFF(CURDATE(),opregister.datetod) as datediff,demographic.id as demographic
From opregister
inner join samps on opregister.demographic_id = samps.demographic_id
inner join demographic on demographic.id= opregister.demographic_id
Where opregister.demographic_id = '$id' and opregister.visittype!='AC' order by opregister.datetod asc";

$mysql_access = mysql_connect("localhost", "root","root");

mysql_select_db("scd_study", $mysql_access);

$result = mysql_query($str_query, $mysql_access);

if(mysql_num_rows($result)) {
   while($row = mysql_fetch_row($result))
  {
 $maxdate = $row[0];//prints all dates
 $scdno = $row[1];
 $visittype = $row[2];
 $zpp = $row[3];
 $serum = $row[4];
 $visit1 = $row[5];
 $visit2 = $row[6];
 $visit3 = $row[7];
 $visit4 = $row[8];
 $datediff = $row[9];
 $demographic=$row[10];
  }
} else {
 echo("no rows");

}
//print the maximum date
             

print "Last Visit Date ".$maxdate;
//print "VisitType ".$maxdate;

$today = date("Y-m-d");
print "<br>";
print "today ".$today;
//$days = $today - $maxdate; // is there a date difference function in PHP?

print "<br>";
print "Days diff ".$datediff;
if(($datediff>365) || ($visit1='Null') || (is_null($visit1)))
{
 //if  ((($visit1='') || (is_null($visit1))) && (($visit2='') || (is_null($visit2))) && (($visit3='') || (is_null($visit3))) && (($visit4='') || (is_null($visit4)) ))
 //{
  $opt = "AN";
 // $sql="UPDATE samps SET visit1='1' where demographic_id='$id'";
  //$res = mysql_query($sql) or die(mysql_error());
 //}
}


elseif (($visit2=='Null') || (is_null($visit2)))
{
$opt = "V2";
//$sql="UPDATE samps SET visit2='1' where demographic_id='$id'";
//$res = mysql_query($sql) or die(mysql_error());
}
elseif (($visit3=='Null') || (is_null($visit3)))
{
$opt = "RO";
//$sql="UPDATE samps SET visit3='1' where demographic_id='$id'";
//$res = mysql_query($sql) or die(mysql_error());
}
elseif (($visit4=='Null') || (is_null($visit4)))
{
$opt="RO1";
//$sql="UPDATE samps SET visit1='',visit2='',visit3='',visit4='' where demographic_id='$id'";
//$res = mysql_query($sql) or die(mysql_error());
}
?>



    <td class="g">Select visit type</td>
    <td class="g"><select name="visittype">
 <option>Select</option>
 <option id="visittype">ADM</option>
 <option id="visittype">NE</option>
 <option id="visittype"><?php echo($opt);?></option>

    <option id="visittype">AC</option>
 <option id="visittype">CO</option>
 </select></td>
  </tr>
  <tr><td><input type="submit" name="btnAction" id="btnAction" value="Continue">
</td></tr>
</table>
<?php include ("footer.php") ?>
</form>

/////////////////
opregisteradd.php
/////////////////

<?php 
session_start();
ob_start();
?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?><? //include common files?>
<?php include ("ewconfig.php") ?>
<?php include ("db.php") ?>
<?php include ("opregisterinfo.php") ?>
<?php include ("advsecu.php") ?>
<?php include ("defaults.php") ?>
<?php include ("ewupload.php") ?>
<?php
//check if user is logged in
if (!IsLoggedIn()) {
	ob_end_clean();
	header("Location: login.php");
	exit();
}
?>
<?php
//ShowUserLevelInfo();
SetUpUserLevel();
?>
<?php
if (!CanAdd("opregister")) {
$_SESSION[ewSessionMessage] = "You do not have permissions to view this page";
	ob_end_clean();
	header("Location: login.php");
	exit();
}
?>

<?php //get user and date
$username=@$_SESSION[ewSessionUserName];
$s_today =date("Y-m-j"); 
$today=ConvertDateToMysqlFormat2($GLOBALS["s_today"]);

// Initialize common variables
$x_datetod = NULL;
$ox_datetod = NULL;
$z_datetod = NULL;
$ar_x_datetod = NULL;
$ari_x_datetod = NULL;
$x_datetodList = NULL;
$x_datetodChk = NULL;
$cbo_x_datetod_js = NULL;
$x_scdno = NULL;
$ox_scdno = NULL;
$z_scdno = NULL;
$ar_x_scdno = NULL;
$ari_x_scdno = NULL;
$x_scdnoList = NULL;
$x_scdnoChk = NULL;
$cbo_x_scdno_js = NULL;
$x_hospid = NULL;
$ox_hospid = NULL;
$z_hospid = NULL;
$ar_x_hospid = NULL;
$ari_x_hospid = NULL;
$x_hospidList = NULL;
$x_hospidChk = NULL;
$cbo_x_hospid_js = NULL;
$x_demographic_id = NULL;
$ox_demographic_id = NULL;
$z_demographic_id = NULL;
$ar_x_demographic_id = NULL;
$ari_x_demographic_id = NULL;
$x_demographic_idList = NULL;
$x_demographic_idChk = NULL;
$cbo_x_demographic_id_js = NULL;
$x_visittype = NULL;
$ox_visittype = NULL;
$z_visittype = NULL;
$ar_x_visittype = NULL;
$ari_x_visittype = NULL;
$x_visittypeList = NULL;
$x_visittypeChk = NULL;
$cbo_x_visittype_js = NULL;
$x_consent = NULL;
$ox_consent = NULL;
$z_consent = NULL;
$ar_x_consent = NULL;
$ari_x_consent = NULL;
$x_consentList = NULL;
$x_consentChk = NULL;
$cbo_x_consent_js = NULL;
$x_q = NULL;
$ox_q = NULL;
$z_q = NULL;
$ar_x_q = NULL;
$ari_x_q = NULL;
$x_qList = NULL;
$x_qChk = NULL;
$cbo_x_q_js = NULL;
$x_sample = NULL;
$ox_sample = NULL;
$z_sample = NULL;
$ar_x_sample = NULL;
$ari_x_sample = NULL;
$x_sampleList = NULL;
$x_sampleChk = NULL;
$cbo_x_sample_js = NULL;
$x_comments = NULL;
$ox_comments = NULL;
$z_comments = NULL;
$ar_x_comments = NULL;
$ari_x_comments = NULL;
$x_commentsList = NULL;
$x_commentsChk = NULL;
$cbo_x_comments_js = NULL;
$x_fbp = NULL;
$ox_fbp = NULL;
$z_fbp = NULL;
$ar_x_fbp = NULL;
$ari_x_fbp = NULL;
$x_fbpList = NULL;
$x_fbpChk = NULL;
$cbo_x_fbp_js = NULL;
$x_biochemistry = NULL;
$ox_biochemistry = NULL;
$z_biochemistry = NULL;
$ar_x_biochemistry = NULL;
$ari_x_biochemistry = NULL;
$x_biochemistryList = NULL;
$x_biochemistryChk = NULL;
$cbo_x_biochemistry_js = NULL;
$x_hbelectro = NULL;
$ox_hbelectro = NULL;
$z_hbelectro = NULL;
$ar_x_hbelectro = NULL;
$ari_x_hbelectro = NULL;
$x_hbelectroList = NULL;
$x_hbelectroChk = NULL;
$cbo_x_hbelectro_js = NULL;
$x_urine = NULL;
$ox_urine = NULL;
$z_urine = NULL;
$ar_x_urine = NULL;
$ari_x_urine = NULL;
$x_urineList = NULL;
$x_urineChk = NULL;
$cbo_x_urine_js = NULL;
$x_nextvisit = NULL;
$ox_nextvisit = NULL;
$z_nextvisit = NULL;
$ar_x_nextvisit = NULL;
$ari_x_nextvisit = NULL;
$x_nextvisitList = NULL;
$x_nextvisitChk = NULL;
$cbo_x_nextvisit_js = NULL;
$x_enteredby = NULL;
$ox_enteredby = NULL;
$z_enteredby = NULL;
$ar_x_enteredby = NULL;
$ari_x_enteredby = NULL;
$x_enteredbyList = NULL;
$x_enteredbyChk = NULL;
$cbo_x_enteredby_js = NULL;
$x_entry1 = NULL;
$ox_entry1 = NULL;
$x_datedis = NULL;
$ox_outcome = NULL;
$z_entry1 = NULL;
$ar_x_entry1 = NULL;
$ari_x_entry1 = NULL;
$x_entry1List = NULL;
$x_entry1Chk = NULL;
$cbo_x_entry1_js = NULL;
$x_entry2 = NULL;
$ox_entry2 = NULL;
$z_entry2 = NULL;
$ar_x_entry2 = NULL;
$ari_x_entry2 = NULL;
$x_entry2List = NULL;
$x_entry2Chk = NULL;
$cbo_x_entry2_js = NULL;
$x_labentry = NULL;
$ox_labentry = NULL;
$z_labentry = NULL;
$ar_x_labentry = NULL;
$ari_x_labentry = NULL;
$x_labentryList = NULL;
$x_labentryChk = NULL;
$cbo_x_labentry_js = NULL;
?>
<?php
$demoid=$_GET['id'];
$visittype=$_GET['visittype'];


//echo $visittype;
// Load key from QueryString
$bCopy = true;
$x_datetod = @$_GET["datetod"];

if (($x_datetod == "") || (is_null($x_datetod))) $bCopy = false;
$x_scdno = @$_GET["scdno"];
if (($x_scdno == "") || (is_null($x_scdno))) $bCopy = false;

// Get action
$sAction = @$_POST["a_add"];
if (($sAction == "") || ((is_null($sAction)))) {
	if ($bCopy) {
		$sAction = "C"; // Copy record
	} else {
		$sAction = "I"; // Display blank record
	}
} else {
	// Get fields from form
	$x_datetod = @$_POST["x_datetod"];
	$a_datetod = @$_POST["x_datetod"];
	$visittype = @$_POST["visittype"];
	$x_ward = @$_POST["x_ward"];
	$x_scdno = @$_POST["x_scdno"];
	$x_ascdno = @$_POST["x_ascdno"];
	$x_hospid = @$_POST["x_hospid"];
	$x_demographic_id = @$_POST["x_demographic_id"];
	$x_visittype = @$_POST["x_visittype"];
	$x_consent = @$_POST["x_consent"];
	$x_q = @$_POST["x_q"];
	$x_sample = @$_POST["x_sample"];
	$x_comments = @$_POST["x_comments"];
	$x_fbp = @$_POST["x_fbp"];
	$x_biochemistry = @$_POST["x_biochemistry"];
	$x_hbelectro = @$_POST["x_hbelectro"];
	$x_urine = @$_POST["x_urine"];
	$x_nextvisit = @$_POST["x_nextvisit"];
	$x_enteredby = @$_POST["x_enteredby"];
	$x_entrydate = @$_POST["x_entrydate"];
	$x_entry1 = @$_POST["x_entry1"];
	$x_entry2 = @$_POST["x_entry2"];
	$x_labentry = @$_POST["x_labentry"];
	$x_datedis = @$_POST["x_datedis"];
	$x_outcome = @$_POST["x_outcome"];
}
//start connection to the database
$conn = scd_db_connect(HOST, USER, PASS, DB, PORT);

$sqllab="SELECT * FROM test_table WHERE demographic_id=$demoid";
$reslab=mysql_query($sqllab);
$totallab= mysql_num_rows($reslab);
if($totallab==0)
{
$lab=0;
}
else if($totallab>=1)
{
$lab=1;
}
switch ($sAction) {
	case "C": // Copy record
		if (!LoadData($conn)) { // Load record
			$_SESSION[ewSessionMessage] = "No records found";
			scd_db_close($conn);
			ob_end_clean();
			header("Location: opregisterlist.php");
			exit();
		}
		break;
	case "A": // Add
		if($visittype=="ADM")
				{
				
				$a_datetod  =ConvertDateToMysqlFormat2($x_datetod);
				$x_datedis  =ConvertDateToMysqlFormat2($x_datedis);
				$sqlip="INSERT INTO `ipregister` (`id`,`dateadm`,`ascdno`,`scdno`,`hospid`,`ward`,`demographic_id`,`problem`,
				`outcome`,`datedis`,`diagnosis`,`malaria`,`culture`,`entry1`,`entry2`,`enteredby`,`entrydate`)
				VALUES('','$a_datetod','$x_ascdno','$x_scdno','$x_hospid','$x_ward','$x_demographic_id','$x_problem','$x_outcome','$x_datedis','$x_diagnosis',
				'$x_malaria','$x_culture','$x_entry1','$x_entry2','$x_enteredby','$today')";
				echo $sqlip; 
					$_SESSION[ewSessionMessage] = "Add New Record Successful";
				$res=mysql_query($sqlip) or die(mysql_error());
					header("Location: demographiclist.php");
				}
		else
				{
				if (AddData($conn)) 
				{ // Add new record
					$_SESSION[ewSessionMessage] = "Add New Record Successful";
					scd_db_close($conn);
					ob_end_clean();
					header("Location: opregisterlist.php");
					exit();
				}
				}
				break;
}
?>
<?php include ("header.php") ?>

</style>
<link rel="stylesheet" type="text/css" href="css/epoch_styles.css"/>
<style type="text/css">
<!--
.info   { color: black; background-color: transparent; font-weight: normal; }
  .warn   { color: rgb(120,0,0); background-color: transparent; font-weight: normal; }
  .error  { color: red; background-color: transparent; font-weight: bold }

  .formtab TD      
          { padding: 0.2em; height: 2.5em; vertical-align: top; font-size: 90%; }

-->
</style>
<script type="text/javascript">
<!--
EW_LookupFn = "ewlookup.php"; // ewlookup file name
EW_AddOptFn = "ewaddopt.php"; // ewaddopt.php file name

//-->
</script>
<script type="text/javascript" src="ewp.js"></script>
<script type="text/javascript">
<!--
EW_dateSep = "-"; // set date separator	

//-->
</script>
</script>
<script language="JavaScript" src="js/gen_validatorv2.js" type="text/javascript"></script>
<script type="text/javascript" src="css/epoch_classes.js"></script>
<script type="text/javascript" src="js/formval.js"></script> 
<script type="text/javascript">
/*You can also place this code in a separate file and link to it like epoch_classes.js*/
	var datetod,next,dischargedate;
	var xmlHttp;
var disparea;;      
     window.onload = function () {
	datetod  = new Epoch('epoch_popup','popup',document.getElementById('x_datetod'));
	next  = new Epoch('epoch_popup','popup',document.getElementById('x_nextvisit'));
	dischargedate  = new Epoch('epoch_popup','popup',document.getElementById('x_datedis'));
};
</script>

<script type="text/javascript">
<!--
function EW_checkMyForm(EW_this) {
if (EW_this.x_datetod && !EW_hasValue(EW_this.x_datetod, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.x_datetod, "TEXT", "Please enter required field - datetod"))
		return false;
}
if (EW_this.x_labentry && !EW_hasValue(EW_this.x_labentry, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.x_labentry, "TEXT", "Please enter required field - labentry"))
		return false;
}
if (EW_this.x_scdno && !EW_hasValue(EW_this.x_scdno, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.x_scdno, "TEXT", "Please enter required field - Admno"))
		return false;
}

return true;
}
function checkvalues(form)
{
/*if(document.forms.fopregisteradd.x_ascdno.value=="")
{
 alert('Please enter required field admission number');
 return false;*/
}

}
//-->
</script>
<script type="text/javascript">
<!--
	var EW_DHTMLEditors = [];

//-->
</script>
<p><span class="kemri_scd">Add to TABLE:Register<br>
    <br><a href="opregisterlist.php">Back to List</a></span></p>
	
<form name="fopregisteradd" id="fopregisteradd" action="opregisteradd.php" method="post" onSubmit="return EW_checkMyForm(this);">
<p>

<input type="hidden" name="a_add" value="A">
<input type="hidden" name="visittype" value="<? echo $visittype;?>">
<input type="hidden" name="qsql" id="qsql" value="<? echo $sql; ?>">
<?php
if (@$_SESSION[ewSessionMessage] <> "") {
?>
<p><span class="ewmsg"><?php echo $_SESSION[ewSessionMessage] ?></span></p>
<?php
	$_SESSION[ewSessionMessage] = ""; // Clear message
}
$sql="select * from demographic where id=$demoid";
		$res=mysql_query($sql);
		$row=mysql_fetch_array($res);
		$scdno=$row['scdno'];
switch($visittype)
{
		case "ADM":
				$sql="select * from inpatient where Demographic_id=$demoid";
				$res=mysql_query($sql);
				$row=mysql_fetch_array($res);
				$ascdno=$row['ascdno'];
				break;
		 case "FU":
				$sql="select * from followup where demographic_id=$demoid order by id desc";
				$res=mysql_query($sql);
				$row=mysql_fetch_array($res);
				$datetod=$row['datetod'];
				break;
		case "AN":
				$sql="select * from followup where demographic_id=$demoid order by id desc";
				$res=mysql_query($sql);
				$row=mysql_fetch_array($res);
				$datetod=$row['datetod'];
				break;
		case "AC":
				$sql="select * from followup where demographic_id=$demoid order by id desc";
				$res=mysql_query($sql);
				$row=mysql_fetch_array($res);
				$datetod=$row['datetod'];
				break;
		case "RO":
				$sql="select * from followup where demographic_id=$demoid order by id desc";
				$res=mysql_query($sql);
				$row=mysql_fetch_array($res);
				$datetod=$row['datetod'];
				break;
		case "CO":
				$sql="select * from control where demographic_id='$demoid'";
				$res=mysql_query($sql);
				$row=mysql_fetch_array($res);
				$cscdno=$row['cscdno'];
				$x_datetod=$row['datetod'];
				break;
		case "NE":
				$scdno="";
				break;

}
?>
<table class="bordercolor2" cellpadding="2" cellspacing="1">
	<tr>
	  <td colspan="4" class="oben">Screening</td>
	  </tr>
	<tr>
	  <td class="g">Name</td>
	  <td class="g"><? $sql="SELECT name from demographic where id='$demoid'";
	  $res=mysql_query($sql);
	  $row=mysql_fetch_array($res);
	  $name=$row['name'];
	  echo $name;?></td>
	  <td class="g">Control Number </td>
	  <td class="g"><input type="text" name="x_cscdno" id="x_cscdno" size="10" maxlength="5" value="<?php echo htmlspecialchars(@$cscdno) ?>"></td>
	  </tr>
	<tr>
	  <td class="g"><span>SCD Number <span class='ewmsg'>&nbsp;*</span></span></td>
	  <td class="g"><span id="cb_x_scdno">
        <input type="text" name="x_scdno" id="x_scdno" size="10" maxlength="5" value="<?php echo htmlspecialchars(@$scdno) ?>">
      </span></td>
		<td class="g"><span id="cb_x_demographic_id">
		  <input type="hidden" name="x_demographic_id" id="x_demographic_id" size="30" value="<?php echo htmlspecialchars(@$demoid) ?>">
          <span>Today's Date*</span></td>
		<td class="g"><span id="cb_x_datetod">
		  <input type="text" name="x_datetod" id="x_datetod" value="<?php echo FormatDateTime2(@$datetod,7); ?>">
</span></td>
		</tr>
	<tr>
	  <?php

$str_query = "Select
opregister.datetod, opregister.scdno,
opregister.visittype,samps.zpp,samps.serum,samps.visit1,samps.visit2,samps.visit3,samps.visit4,DATEDIFF(CURDATE(),opregister.datetod) as datediff
From opregister inner join samps on opregister.demographic_id = samps.demographic_id
Where opregister.demographic_id = '$demoid' and opregister.datetod !=CURDATE() and (opregister.visittype='FU' or opregister.visittype='RO' or opregister.visittype='AN' or opregister.visittype='V2') order by opregister.datetod asc";

$mysql_access = mysql_connect("localhost", "root","root");

mysql_select_db("scd_study", $mysql_access);

$result = mysql_query($str_query, $mysql_access);

if(mysql_num_rows($result)) {
   while($row = mysql_fetch_row($result))
  {
 $maxdate = $row[0];//prints all dates
 $scdno = $row[1];
 $visittype = $row[2];
 $zpp = $row[3];
 $serum = $row[4];
 $visit1 = $row[5];
 $visit2 = $row[6];
 $visit3 = $row[7];
 $visit4 = $row[8];
 $datediff = $row[9];
  
  }
} else {
 echo("no rows");

}
//print the maximum date
print "Last Visit Date ".$maxdate;
//print "VisitType ".$maxdate;

$today = date("Y-m-d");
print "<br>";
print "today ".$today;
//$days = $today - $maxdate; // is there a date difference function in PHP?

print "<br>";
print "Days diff ".$datediff;

if(($datediff>365) || ($visit1='Null') || (is_null($visit1)))
{
 //if  ((($visit1='') || (is_null($visit1))) && (($visit2='') || (is_null($visit2))) && (($visit3='') || (is_null($visit3))) && (($visit4='') || (is_null($visit4)) ))
 //{
  $opt = "AN";
  $sql="UPDATE samps SET visit1='1' where demographic_id='$demoid'";
  //$res = mysql_query($sql) or die(mysql_error());
 //}
}


elseif (($visit2=='') || (is_null($visit2)))
{
$opt = "V2";
$sql="UPDATE samps SET visit2='1' where demographic_id='$demoid'";
//$res = mysql_query($sql) or die(mysql_error());
}
elseif (($visit3=='Null') || (is_null($visit3)))
{
$opt = "RO";
$sql="UPDATE samps SET visit3='1' where demographic_id='$demoid'";
//$res = mysql_query($sql) or die(mysql_error());
}

elseif (($visit4=='Null') || (is_null($visit4)))
{
$opt="RO1";
$sql="UPDATE samps SET visit1='Null',visit2='Null',visit3='Null',visit4='Null' where demographic_id='$demoid'";
//$res = mysql_query($sql) or die(mysql_error());
}
?>



    <td class="g"><span>Visittype</span></td>
	  <td class="g"><span id="cb_x_visittype">
        <select name="x_visittype" id="x_visittype">
		<? echo $visittype;?>
		<option>Select</option>
	<option id="x_visittype">ADM</option>
	<option id="x_visittype">NE</option>
	<option id="x_visittype"><?php echo($opt)?></option>

    <option id="x_visittype">AC</option>
	<option id="x_visittype">CO</option>
	</select></td>
		<td class="g"><span><span class='ewmsg'><span id="">
		Admission Number</span></span></span></td>
		<td class="g"><span id="cb_x_ascdno">
</span><input type="text" name="x_ascdno" id="x_ascdno" value="<?php echo htmlspecialchars(@$ascdno) ?>"></td>
		</tr>
	<tr>
	  <td class="g"><span>Informed Consent</span></td>
	  <td  class="g"><span id="cb_x_consent"> <?php echo RenderControl(1, 0, 5, 1); ?>
            <input type="radio" name="x_consent"<?php if (@$x_consent == "1") { ?> checked<?php } ?> value="<?php echo htmlspecialchars("1"); ?>">
            <?php echo "<span class=txt>Yes</span>"; ?> <?php echo RenderControl(1, 0, 5, 2); ?> <?php echo RenderControl(1, 1, 5, 1); ?>
            <input type="radio" name="x_consent"<?php if (@$x_consent == "0") { ?> checked<?php } ?> value="<?php echo htmlspecialchars("0"); ?>">
            <?php echo "<span class=txt>No</span>"; ?> <?php echo RenderControl(1, 1, 5, 2); ?> </span></td>
	  <td class="g"><span>Hospital Id </span></td>
	  <td class="g"><span id="cb_x_hospid">
        <input type="text" name="x_hospid" id="x_hospid" size="30" maxlength="10" value="<?php echo htmlspecialchars(@$x_hospid) ?>">
      </span></td>
	  </tr>
	<tr>
		<td colspan="4" class="oben">Laboratory Investigation </td>
		</tr>
	<tr>
		<td class="g">Questionnaire</td>
		<td class="g"><span id="cb_x_q">
          <span id="cb_x_q"><?php echo RenderControl(1, 0, 5, 1); ?></span>
          <input type="radio" name="x_q" value="Y"<?php if ($x_q == "Y") { ?> checked<?php } ?>>
          <span id="cb_x_q"><?php echo "<span class=txt>Yes</span>"; ?></span><span id="cb_x_q"><?php echo RenderControl(1, 0, 5, 2); ?></span><span id="cb_x_q"><?php echo RenderControl(1, 1, 5, 1); ?></span>
          <input type="radio" name="x_q" value="N"<?php if ($x_q == "N") { ?> checked<?php } ?>>
          <span id="cb_x_q"><?php echo "<span class=txt>No</span>"; ?></span> <span id="cb_x_q"><?php echo RenderControl(1, 1, 5, 2); ?></span> </span></td>
		<td class="g"><span>Sample Taken </span></td>
		<td class="g"><span id="cb_x_sample">
          <span id="cb_x_sample"><span id="cb_x_sample"><?php echo RenderControl(1, 0, 5, 1); ?></span></span>
          <input type="radio" name="x_sample" value="Y"<?php if ($x_sample == "Y") { ?> checked<?php } ?>>
          <span id="cb_x_sample"><span id="cb_x_sample"><?php echo "<span class=txt>Yes</span>"; ?></span></span><span id="cb_x_sample"><span id="cb_x_sample"><?php echo RenderControl(1, 0, 5, 2); ?></span></span>          <span id="cb_x_sample"><span id="cb_x_sample"><?php echo RenderControl(1, 1, 5, 1); ?></span></span>
          <input type="radio" name="x_sample" value="N"<?php if ($x_sample == "N") { ?> checked<?php } ?>>
          <span id="cb_x_sample"><span id="cb_x_sample"><?php echo "<span class=txt>No</span>"; ?></span></span> <span id="cb_x_sample"><span id="cb_x_sample"><?php echo RenderControl(1, 1, 5, 2); ?></span></span> </span></td>
		</tr>
	<tr>
	  <td class="g">FBP</td>
	  <td class="g"><span id="cb_x_fbp"> <span id="cb_x_fbp"><span id="cb_x_fbp"><span id="cb_x_fbp"><?php echo RenderControl(1, 0, 5, 1); ?></span></span></span>
            <input type="radio" name="x_fbp" value="Y"<?php if ($x_fbp == "Y") { ?> checked<?php } ?>>
            <span id="cb_x_fbp"><span id="cb_x_fbp"><?php echo "<span class=txt>Yes</span>"; ?></span></span><span id="cb_x_fbp"><span id="cb_x_fbp"><?php echo RenderControl(1, 0, 5, 2); ?></span></span><span id="cb_x_fbp"><span id="cb_x_fbp"><?php echo RenderControl(1, 1, 5, 1); ?></span></span>
            <input type="radio" name="x_fbp" value="N"<?php if ($x_fbp == "N") { ?> checked<?php } ?>>
            <span id="cb_x_fbp"><span id="cb_x_fbp"><?php echo "<span class=txt>No</span>"; ?></span></span> <span id="cb_x_fbp"><span id="cb_x_fbp"><?php echo RenderControl(1, 1, 5, 2); ?></span></span> </span></td>
	  <td class="g"><span>Biochemistry</span></td>
	  <td class="g"><span id="cb_x_biochemistry"> <span id="cb_x_biochemistry"><span id="cb_x_biochemistry"><span id="cb_x_biochemistry"><?php echo RenderControl(1, 0, 5, 1); ?></span></span></span>
            <input type="radio" name="x_biochemistry" value="Y"<?php if ($x_biochemistry == "Y") { ?> checked<?php } ?>>
            <span id="cb_x_biochemistry"><span id="cb_x_biochemistry"><?php echo "<span class=txt>Yes</span>"; ?></span></span> <span id="cb_x_biochemistry"><span id="cb_x_biochemistry"><?php echo RenderControl(1, 0, 5, 2); ?></span></span><span id="cb_x_biochemistry"><span id="cb_x_biochemistry"><?php echo RenderControl(1, 1, 5, 1); ?></span></span>
            <input type="radio" name="x_biochemistry" value="N"<?php if ($x_biochemistry == "N") { ?> checked<?php } ?>>
            <span id="cb_x_biochemistry"><span id="cb_x_biochemistry"><?php echo "<span class=txt>No</span>"; ?></span></span> <span id="cb_x_biochemistry"><span id="cb_x_biochemistry"><?php echo RenderControl(1, 1, 5, 2); ?></span></span></span></td>
	  </tr>
	<tr>
	  <td class="g"><span>hbelectro</span></td>
	  <td class="g"><span id="cb_x_hbelectro"> <span id="cb_x_sample"><span id="cb_x_hbelectro"><span id="cb_x_hbelectro"><?php echo RenderControl(1, 0, 5, 1); ?></span></span></span>
            <input type="radio" name="x_hbelectro" value="Y"<?php if ($x_hbelectro == "Y") { ?> checked<?php } ?>>
            <span id="cb_x_hbelectro"><span id="cb_x_hbelectro"><?php echo "<span class=txt>Yes</span>"; ?></span></span> <span id="cb_x_hbelectro"><span id="cb_x_hbelectro"><?php echo RenderControl(1, 0, 5, 2); ?></span></span><span id="cb_x_hbelectro"><span id="cb_x_hbelectro"><?php echo RenderControl(1, 1, 5, 1); ?></span></span>
            <input type="radio" name="x_hbelectro" value="N"<?php if ($x_hbelectro == "N") { ?> checked<?php } ?>>
            <span id="cb_x_hbelectro"><span id="cb_x_hbelectro"><?php echo "<span class=txt>No</span>"; ?></span></span> <span id="cb_x_hbelectro"><span id="cb_x_hbelectro"><?php echo RenderControl(1, 1, 5, 2); ?></span></span></span></td>
	  <td class="g"><span>Urine</span></td>
	  <td class="g"><span id="cb_x_urine"> <span id="cb_x_urine"><span id="cb_x_urine"><span id="cb_x_urine"><?php echo RenderControl(1, 0, 5, 1); ?></span></span></span>
            <input type="radio" name="x_urine" value="Y"<?php if ($x_urine == "Y") { ?> checked<?php } ?>>
            <span id="cb_x_urine"><span id="cb_x_urine"><?php echo "<span class=txt>Yes</span>"; ?></span></span> <span id="cb_x_urine"><span id="cb_x_urine"><?php echo RenderControl(1, 0, 5, 2); ?></span></span> <span id="cb_x_urine"><span id="cb_x_urine"><?php echo RenderControl(1, 1, 5, 1); ?></span></span>
            <input type="radio" name="x_urine" value="N"<?php if ($x_urine == "N") { ?> checked<?php } ?>>
            <span id="cb_x_urine"><span id="cb_x_urine"><?php echo "<span class=txt>No</span>"; ?></span></span> <span id="cb_x_urine"><span id="cb_x_urine"><?php echo RenderControl(1, 1, 5, 2); ?></span></span> </span></td>
	  </tr>
	<tr>
		<td class="g"><span>Comments</span></td>
		<td class="g"><textarea name="x_comments" id="x_comments" ><? echo $x_comments; ?></textarea></td>
		<td class="g"><span>Nextvisit</span></td>
		<td class="g"><span id="cb_x_nextvisit">
          <input type="text" name="x_nextvisit" id="x_nextvisit" value="<?php echo FormatDateTime(@$x_nextvisit,5); ?>">
          <input type="hidden" name="x_entry1" id="x_entry1" value="<?php echo htmlspecialchars(@$entry); ?>">
          <input type="hidden" name="x_labentry" id="x_labentry" value="<?php echo htmlspecialchars(@$lab); ?>">
          <input type="hidden" name="x_enteredby" id="x_enteredby" value="<?php echo htmlspecialchars(@$_SESSION[ewSessionUserName]); ?>">
          <input type="hidden" name="x_entrydate" id="x_entrydate" value="<?php echo FormatDateTime2(@$today,7); ?>">
        </span></td>
		</tr>
		<tr>
		  <td colspan="4" class="oben">Overall Assessment </td>
	    </tr>
		<tr>
		  <td class="g">Ward</td>
		  <td class="g"><input type="text" name="x_ward" id="x_ward"></td>
		  <td class="g">Date of Discharge </td>
		  <td class="g"><input type="text" name="x_datedis" id="x_datedis"></td>
	    </tr>
		<tr>
		  <td class="g">Outcome</td>
		    <td class="g"><select name="x_outcome">
			<option id="x_outcome">Select</option>
			<option id="x_outcome">DEA</option>
			<option id="x_outcome">DIS</option>
	        </select></td>
			  <td class="g">&nbsp;</td>
			    <td class="g">&nbsp;</td>
	    </tr>
		<tr>
		<td>
<input type="submit" name="btnAction" id="btnAction" value="ADD" onClick="return checkvalues(this);">
		</td></tr>
</table>
<p>
</form>
<?php include ("footer.php") ?>
<?php
scd_db_close($conn);
?>
<?php

//-------------------------------------------------------------------------------
// Function LoadData
// - Variables setup: field variables

function LoadData($conn)
{
	global $x_datetod;
	global $x_scdno;
	$sFilter = ewSqlKeyWhere;
	$x_datetod =  (get_magic_quotes_gpc()) ? stripslashes($x_datetod) : $x_datetod;
	$sFilter = str_replace("@datetod", AdjustSql($x_datetod), $sFilter); // Replace key value
	$x_scdno =  (get_magic_quotes_gpc()) ? stripslashes($x_scdno) : $x_scdno;
	$sFilter = str_replace("@scdno", AdjustSql($x_scdno), $sFilter); // Replace key value
	$sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
	$rs = scd_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . scd_error($conn) . '<br>SQL: ' . $sSql);
	if (scd_num_rows($rs) == 0) {
		$bLoadData = false;
	} else {
		$bLoadData = true;
		$row = scd_fetch_array($rs);

		// Get the field contents
		$GLOBALS["x_datetod"] = $row["datetod"];
		$GLOBALS["x_scdno"] = $row["scdno"];
		$GLOBALS["x_hospid"] = $row["hospid"];
		$GLOBALS["x_demographic_id"] = $row["demographic_id"];
		$GLOBALS["x_visittype"] = $row["visittype"];
		$GLOBALS["x_consent"] = $row["consent"];
		$GLOBALS["x_q"] = $row["q"];
		$GLOBALS["x_sample"] = $row["sample"];
		$GLOBALS["x_comments"] = $row["comments"];
		$GLOBALS["x_fbp"] = $row["fbp"];
		$GLOBALS["x_biochemistry"] = $row["biochemistry"];
		$GLOBALS["x_hbelectro"] = $row["hbelectro"];
		$GLOBALS["x_urine"] = $row["urine"];
		$GLOBALS["x_nextvisit"] = $row["nextvisit"];
		$GLOBALS["x_enteredby"] = $row["enteredby"];
		$GLOBALS["x_entrydate"] = $row["entrydate"];
		$GLOBALS["x_entry1"] = $row["entry1"];
		$GLOBALS["x_entry2"] = $row["entry2"];
		$GLOBALS["x_labentry"] = $row["labentry"];
	}
	scd_free_result($rs);
	return $bLoadData;
}
?>
<?php

//-------------------------------------------------------------------------------
// Function AddData
// - Add Data
// - Variables used: field variables

function AddData($conn)
{
	global $x_datetod;
	global $x_scdno;
	$sFilter = ewSqlKeyWhere;

	// Check for duplicate key
	$bCheckKey = true;
	if ((@$x_datetod == "") || (is_null(@$x_datetod))) {
		$bCheckKey = false;
	} else {
		$sFilter = str_replace("@datetod", AdjustSql($x_datetod), $sFilter); // Replace key value
	}
	if ((@$x_scdno == "") || (is_null(@$x_scdno))) {
		$bCheckKey = false;
	} else {
		$sFilter = str_replace("@scdno", AdjustSql($x_scdno), $sFilter); // Replace key value
	}
	if ($bCheckKey) {
		$sSqlChk = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
		$rsChk = scd_query($sSqlChk, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . scd_error($conn) . '<br>SQL: ' . $sSqlChk);
		if (scd_num_rows($rsChk) > 0) {
			$_SESSION[ewSessionMessage] = "Duplicate value for primary key";
			scd_free_result($rsChk);
			return false;
		}
		scd_free_result($rsChk);
	}

	// Field datetod
	$theValue = ($GLOBALS["x_datetod"] != "") ? " '" . ConvertDateToMysqlFormat2($GLOBALS["x_datetod"]) . "'" : "Null";
	$fieldList["`datetod`"] = $theValue;
	// Field scdno
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_scdno"]) : $GLOBALS["x_scdno"]; 
	$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
	$fieldList["`scdno`"] = $theValue;

	// Field hospid
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_hospid"]) : $GLOBALS["x_hospid"]; 
	$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
	$fieldList["`hospid`"] = $theValue;

	// Field demographic_id
	$theValue = ($GLOBALS["x_demographic_id"] != "") ? intval($GLOBALS["x_demographic_id"]) : "NULL";
	$fieldList["`demographic_id`"] = $theValue;

	// Field visittype
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_visittype"]) : $GLOBALS["x_visittype"]; 
	$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
	$fieldList["`visittype`"] = $theValue;

	// Field consent
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_consent"]) : $GLOBALS["x_consent"]; 
	$theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
	$fieldList["`consent`"] = $theValue;

	// Field q
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_q"]) : $GLOBALS["x_q"]; 
	$theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
	$fieldList["`q`"] = $theValue;

	// Field sample
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_sample"]) : $GLOBALS["x_sample"]; 
	$theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
	$fieldList["`sample`"] = $theValue;

	// Field comments
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_comments"]) : $GLOBALS["x_comments"]; 
	$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
	$fieldList["`comments`"] = $theValue;

	// Field fbp
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_fbp"]) : $GLOBALS["x_fbp"]; 
	$theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
	$fieldList["`fbp`"] = $theValue;

	// Field biochemistry
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_biochemistry"]) : $GLOBALS["x_biochemistry"]; 
	$theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
	$fieldList["`biochemistry`"] = $theValue;

	// Field hbelectro
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_hbelectro"]) : $GLOBALS["x_hbelectro"]; 
	$theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
	$fieldList["`hbelectro`"] = $theValue;

	// Field urine
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_urine"]) : $GLOBALS["x_urine"]; 
	$theValue = (strtoupper($theValue) != "Y") ? " 'N'" : " 'Y'";
	$fieldList["`urine`"] = $theValue;

	// Field nextvisit
	$theValue = ($GLOBALS["x_nextvisit"] != "") ? " '" . ConvertDateToMysqlFormat2($GLOBALS["x_nextvisit"]) . "'" : "Null";
	$fieldList["`nextvisit`"] = $theValue;

	// Field enteredby
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_enteredby"]) : $GLOBALS["x_enteredby"]; 
	$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
	$fieldList["`enteredby`"] = $theValue;

// Field entrydate
	$theValue = ($GLOBALS["x_entrydate"] != "") ? " '" . ConvertDateToMysqlFormat2($GLOBALS["x_entrydate"]) . "'" : "Null";
	$fieldList["`entrydate`"] = $theValue;

	// Field entry1
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_entry1"]) : $GLOBALS["x_entry1"]; 
	$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
	$fieldList["`entry1`"] = $theValue;

	// Field entry2
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_entry2"]) : $GLOBALS["x_entry2"]; 
	$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
	$fieldList["`entry2`"] = $theValue;

	// Field labentry
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($GLOBALS["x_labentry"]) : $GLOBALS["x_labentry"]; 
	$theValue = ($theValue != "") ? " '" . $theValue . "'" : "NULL";
	$fieldList["`labentry`"] = $theValue;
	
	// Inserting event
	if (Recordset_Inserting($fieldList)) {

		// Insert
		$sSql = "INSERT INTO `opregister` (";
		$sSql .= implode(",", array_keys($fieldList));
		$sSql .= ") VALUES (";
		$sSql .= implode(",", array_values($fieldList));
		$sSql .= ")";	
		scd_query($sSql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . scd_error($conn) . '<br>SQL: ' . $sSql);
		$result = (scd_affected_rows($conn) > 0);
// echo $sSql;
		// Inserted event
		if ($result) Recordset_Inserted($fieldList);
	} else {
		$result = false;
	}
	return $result;
}

// Inserting event
function Recordset_Inserting(&$newrs)
{

	// Enter your customized codes here
	return true;
}

// Inserted event
function Recordset_Inserted($newrs)
{
	$table = "opregister";
}

?>

/////////////////
Kindly assist
Thanks

What Silviuks said.
No one is going to read through the whole code, let alone that entire thing of specs you have.

Your best bet is to tell us which part of the code is failing, even better yet what is happening when you view the site?

I mean, are you getting an error of some sort? is it mysql related or php related?

If you really want to find out where you are getting lost, echo out all of your variables and see what is not getting passed.
Sage

This article has been dead for over six months. Start a new discussion instead.