Page 1 of 1

Urgent help for Error in php page

Posted: Tue May 01, 2012 8:53 pm
by khin0704
Is it possible to help me for the described problem?
Error encounter for Result Uploading in Portal.
Students can see the result by login with studentID in portal.
There are two Database (Mysql& Microsoft sql) connections for this page.
All results are extracted from Microsoft Sql Database and save as CSV format.
And then import to Sql Database.
The problem encounter is some of the modules result cannot reflect on UI.
Please kindly check the below php code and how can I edit this code.
I am looking forwards to your kind help and reply.

<?php require_once('../Connections/smsportdb.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_smsportdb, $smsportdb);
$query_rsset = "SELECT * FROM results WHERE nfic = '".$studentid."'";
$rsset = mysql_query($query_rsset, $smsportdb) or die(mysql_error());
$row_rsset = mysql_fetch_assoc($rsset);
$totalRows_rsset = mysql_num_rows($rsset);
?>
<?php require('includes/application_top.php');
if($_SESSION['studentid']==''){
tep_redirect('student_register.php');
}
if($_POST['action']=="update" && $_POST['stu_id']!=''){
$stu_id=tep_db_prepare_input($_POST['stu_id']);
$studentid=addslashes(trim($_POST['studentid']));
$sdate=addslashes(trim($_POST['stu_dob']));
$stu_dob=date("Y-m-d",strtotime($sdate));
$fld_stu_login=addslashes(trim($_POST['fld_stu_login']));
$fld_stu_password=addslashes(trim($_POST['password']));
$fld_stu_name=addslashes(trim($_POST['fld_stu_name']));
$fld_stu_fname=addslashes(trim($_POST['fld_stu_fname']));
$fld_stu_email=addslashes(trim($_POST['fld_stu_email']));
$fld_stu_couresename=addslashes(trim($_POST['fld_stu_couresename']));
$fld_class=addslashes(trim($_POST['fld_class']));

$field_value=array('studentid'=>$studentid,
'stu_dob'=>$stu_dob,
'fld_stu_name'=>$fld_stu_name,
'cmsimage'=>$cmsimage,
'fld_stu_login'=>$fld_stu_login,
'fld_stu_password'=>$fld_stu_password,
'fld_stu_fname'=>$fld_stu_fname,
'fld_stu_email'=>$fld_stu_email,
'fld_stu_couresename'=>$fld_stu_couresename,
'fld_class'=>$fld_class,
'fld_address'=>$fld_address,
'student_status'=>'1');

$result=$objmain->editstudentinfo($stu_id,$studentid,$field_value);

if($result){
$message="Record updateded Successfully";
}else{
$message="Student ID is alrady exist, Please use another Student ID";
}
}
if($_SESSION['studentid'] != ""){

// Connect to MSSQL
$db = mssql_connect('servername', 'username', 'password');

if(!$db || !mssql_select_db('databasename ', $db))
{
die('Unable to connect or select database!');
}

$msck1 = "SELECT DISTINCT [MODULE CODE], [MODULE NAME], [MODULE TERM] FROM tablename WHERE STUDENTNO = '".$studentid."'";


$msrs1 = mssql_query($msck1);
$row_msrs1 = mssql_fetch_assoc($msrs1);
$trow_msrs1 = mssql_num_rows($msrs1);

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<link rel="stylesheet" href="css/deafult.css" type="text/css" />
<script src="js/script.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php echo DIR_WS_JAVASCRIPT?>validation.js"></script>


</head>

<body>
<?php require("includes/header.php")?>

<div id="container">

<?php require("includes/left.php")?>
<div class="nav_warper">
<div class="nav_top"></div>
<div class="nav_mid">
<div class="title1">Academic Results</div>
<form name="stuReg" action="" method="post" enctype="multipart/form-data">

<table cellpadding="0" cellspacing="0" class="loging_table" align="center" width="">
<?php if($message!=''){ ?>
<tr>
<td colspan="4" ><?php echo $message?></td>
</tr>
<?php } ?>

<!--<tr>
<td colspan="7">&nbsp;</td>
</tr>-->

<!--<tr>
<td colspan="7"><strong>Your results for previous terms will be updated and reflected here only by 1st of April 2011.</strong></td>
</tr>-->

<tr>
<td colspan="7">&nbsp;</td>
</tr>

<tr>
<td align="center" colspan="7" style="font-size:14px"><strong>Results</strong></td>
</tr>

<tr style="background-color:#09B5E0">
<td align="left" valign="top" rowspan="2" style="color:#FFF"><strong>Module Code</strong></td>
<td align="left" valign="top" rowspan="2" style="color:#FFF"><strong>Module Name</strong></td>
<td align="left" valign="top" rowspan="2" style="color:#FFF"><strong>Term</strong></td>
<td align="center" colspan="4" style="color:#FFF"><strong>Results</strong></td>
</tr>

<tr style="background-color:#09B5E0; color:#FFF;">
<td align="left" style="color:#FFF"><strong>Coursework</strong></td>
<td align="left" style="color:#FFF"><strong>Exam</strong></td>
<td align="left" style="color:#FFF"><strong>Module Marks</strong></td>
<td align="left" style="color:#FFF"><strong>Grade</strong></td>
</tr>

<?php /*if($trow_msrs1 == 0 || $_SESSION['curr'] == 0){ echo "
<tr>
<td align=\"left\" colspan=3><strong style=\"color:#F00\">You have no module in T1/11.</strong></td>
</tr>";
}*/ ?>

<!--OLD TERM RESULTS-->

<?php

if($_SESSION['curr'] == 0){ $xb = "studno"; }
if($_SESSION['curr'] == 1){ $xb = "nric"; }

mysql_select_db($database_smsportdb, $smsportdb);
$query_Recordset2 = "SELECT * FROM smsport.oldrs WHERE ".$xb." = '".$studentid."'";
$Recordset2 = mysql_query($query_Recordset2, $smsportdb) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$count2 = mysql_num_rows($Recordset2);
?>
<?php if($count2 != 0){ do { ?>
<?php if($row_Recordset2['mm'] != "" || $row_Recordset2['grade'] != "") { ?>
<tr>
<td align="left"><?php echo $row_Recordset2['subcode']; ?></td>
<td><?php echo $row_Recordset2['subname']; ?></td>
<td align="left"><?php echo $row_Recordset2['term']; ?></td>
<td align="center"><?php echo $row_Recordset2['cw']; ?></td>
<td align="center"><?php echo $row_Recordset2['ex']; ?></td>
<td align="center"><?php echo $row_Recordset2['mm']; ?></td>
<td><?php echo $row_Recordset2['grade']; ?></td>
</tr>
<?php } ?>
<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); } ?>

<!--OLD TERM RESULTS-->



<!--NEW TERM RESULTS-->

<?php if($trow_msrs1 != 0 && $_SESSION['curr'] == 1){ do { ?>
<?php
mysql_select_db($database_smsportdb, $smsportdb);
$query_Recordset1 = "SELECT * FROM smsport.results WHERE nfic = '".$studentid."' AND subn = '".$row_msrs1['MODULE CODE']."'";
$Recordset1 = mysql_query($query_Recordset1, $smsportdb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$count = mysql_num_rows($Recordset1);
?>

<?php if($row_Recordset1['mm'] != "" && $row_Recordset1['grade'] != "") { ?>
<tr>
<td align="left"><?php echo $row_msrs1['MODULE CODE']; ?></td>
<td><?php echo $row_msrs1['MODULE NAME']; ?></td>
<td align="left"><?php echo $row_Recordset1['term']; ?></td>
<td align="center"><?php echo $row_Recordset1['cw']; ?></td>
<td align="center"><?php echo $row_Recordset1['ex']; ?></td>
<td align="center"><?php echo $row_Recordset1['mm']; ?></td>
<td><?php echo $row_Recordset1['grade']; ?></td>
</tr>
<?php } ?>


<?php } while ($row_msrs1 = mssql_fetch_assoc($msrs1)); } ?>

<!--NEW TERM RESULTS-->

<tr>
<td colspan="7">&nbsp;</td>
</tr>



<tr>
<td colspan="7">&nbsp;</td>
</tr>

<tr>
<td colspan="7">&nbsp;</td>
</tr>
</table>
</form>


</div>
<div class="nav_bot"></div>
</div><!--end of nav_warper-->

<?php require("includes/footer.php")?>


</div><!--end of container-->
</body>
</html>
<?php
mysql_free_result($rsset);
?>

Re: Urgent help for Error in php page

Posted: Wed May 02, 2012 8:54 am
by x_mutatis_mutandis_x
You cannot use "mysql_*" functions for a Microsoft SQL databases. You need to use Mssql, documentation: http://php.net/manual/en/book.mssql.php