- Joined
- Sep 8, 2011
- Location
- Las Pinas, Philippines
hi guys! i have these codes.. the select from database is working but it wont update.. any chance that im doing wrong?
here are the codes
configdb.php
prelimgrading.php
updateprelimgrade.php
these are the database tables from the "enrollmentdb" database
any help will be greatly appreciated
here are the codes
configdb.php
Code:
<?php
$hostname ="localhost";
$username ="root";
$password ="";
$db ="enrollmentdb";
mysql_connect($hostname,$username,$password) or die("cannot connect to server");
mysql_select_db($db) or die("database not found!");
?>
prelimgrading.php
Code:
<?php
include "configdb.php";
$sql = "SELECT enrollment.student_num, students.lastname, students.firstname, students.middlename, enrollment.subject_num, prelim
FROM enrollment
LEFT OUTER JOIN students ON enrollment.student_num = students.student_num;";
$result = mysql_query($sql) or die ("cannot execute query!");
$count = 0;
$vline = 1;
echo "<form action = 'updateprelimgrade.php' method = 'POST' onsubmit = 'return checkform(this)'; >";
while($row = mysql_fetch_row($result)){
$student_num = $row[0];
$lastname = $row[1];
$firstname = $row[2];
$middlename = $row[3];
$subject_num = $row[4];
$prelim = $row[5];
$count = $count+1;
if($vline%2==1) {
$bg_color = "#3BB9FF";
$vline = 2; }
else
{
$bg_color="#2554C7";
$vline=1;
}
print "<div class='tablecontents' style='float:left';>";
print "<table align = 'left' height = '25' width='750' 'fontko'>";
print "<center>";
print "<tr>";
echo "<td width = '100' bgcolor = '$bg_color'><p align = 'left'><font size = '2' face = 'Century Gothic' color ='white'> <input type='text' id='student_num' name='student_num' value=$student_num></font></td> </font></td>";
print "<td width = '100' bgcolor = '$bg_color'><p align = 'left'><font size = '2' face = 'Century Gothic' color ='white'> $lastname </font></td>";
print "<td width = '100' bgcolor = '$bg_color'><p align = 'left'><font size = '2' face = 'Century Gothic' color ='white'> $firstname </font></td>";
print "<td width = '100' bgcolor = '$bg_color'><p align = 'left'><font size = '2' face = 'Century Gothic' color ='white'> $middlename </font></td>";
echo "<td width = '150' bgcolor = '$bg_color'><p align = 'left'><font size = '2' face = 'Century Gothic' color ='white'><input type='text' id='prelim' name='prelim' value=$prelim></font></td>";
print"</tr>";
print "</center>";
print"</table>";
print"</div>";
}
print "<input type='submit' value='Submit'>";
echo "</form>";
?>
updateprelimgrade.php
Code:
<?php
$con = mysql_connect('localhost','root','') or die('Unable to select database');
mysql_select_db("enrollmentdb", $con);
$student_num=$_POST['student_num'];
$prelim=$_POST['prelim'];
$query="update enrollment SET prelim=$prelim where student_num=$student_num";
$result = mysql_query($query) or die ("Cannot Execute Query!");
if (!mysql_query($result))
{
echo"Failed to Update the Grading";
}
else
header('Location: prelimgrading.php');
?>
these are the database tables from the "enrollmentdb" database
Code:
CREATE TABLE IF NOT EXISTS `enrollment` (
`STUDENT_NUM` varchar(10) NOT NULL DEFAULT '',
`SUBJECT_NUM` varchar(10) NOT NULL DEFAULT '',
`PRELIM` float(10,2) DEFAULT NULL,
`MIDTERM` float(10,2) DEFAULT NULL,
`FINALS` float(10,2) DEFAULT NULL,
`FINAL_GRADE` float(3,2) DEFAULT NULL,
PRIMARY KEY (`STUDENT_NUM`,`SUBJECT_NUM`))
Code:
CREATE TABLE IF NOT EXISTS `students` (
`STUDENT_NUM` varchar(10) NOT NULL,
`LASTNAME` varchar(50) DEFAULT NULL,
`FIRSTNAME` varchar(50) DEFAULT NULL,
`MIDDLENAME` varchar(50) DEFAULT NULL,
PRIMARY KEY (`STUDENT_NUM`)
)
Code:
CREATE TABLE IF NOT EXISTS `subjects` (
`SUBJECT_NUM` varchar(10) NOT NULL,
`SUBJECT_TITLE` varchar(100) DEFAULT NULL,
`DEPARTMENT` varchar(100) DEFAULT NULL,
PRIMARY KEY (`SUBJECT_NUM`)
)
any help will be greatly appreciated