Page 1 of 1

search record then update

Posted: Thu Aug 20, 2009 1:45 pm
by jhincen
//is there a kind ppl who help me... i have some problem using php.
heres my query on searching a person records

$query = "SELECT * FROM `1st_ year_1st_sem` WHERE StudentID='$user'";
$result=mysql_query($query) or die ("Cannot connect to database");
$row = mysql_fetch_array($result);
echo "<center>";
echo "<b>";
echo "Name:";
echo $row['Name'] ."". $row['Midle']."". $row['Surname'];
echo "<br>";
echo "Year Level: ";
echo $row['Yearlevel'];
echo "<br>";
echo "Course: ";
echo $row['Course'];
echo "</b>";
echo "<br>";
echo "<br>";
echo "<br>";


echo "<table border='1' width='70%'>";
echo "<tr>";
echo "<td background='img/td.jpg'><b>SUBJECT CODE</b></td>";
echo "<td background='img/td.jpg'><b>DESCRIPTION</b></td>";
echo "<td background='img/td.jpg'><b>UNITS</b></td>";
echo "<td background='img/td.jpg'><b>GRADE</b></td>";
echo "<td background='img/td.jpg'><b>REMARKS</b></td>";
echo "<td background='img/td.jpg'><b>Update</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>1st Year - 1st semester</b></td>";
echo "</tr>";
if($query = "SELECT * FROM `1st_ year_1st_sem` WHERE StudentID='$user'"){
$result=mysql_query($query) or die ("Cannot connect to database");
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<form name='form' method='POST' action='1y1supdate.php'>";
echo "<td><input type='text' style='border: none' name='s_subject' value=".$row['Subject']."></td>";
echo "<td>".$row['Description']."</td>";
echo "<td>".$row['Units']."</td>";
echo "<td><input type='text' style='border: none' name='s_grade' value=".$row['Grade']."></td>";
echo "<td><input type='text' style='border: none' name='s_remarks' value=".$row['Remarks']."></td>";
echo "<td><input type='submit' name='update' value='update'></td></form>";
echo "</tr>";

}

}

//actually it display the records but the problem is i cant update the grade and the remarks.
here my update query

if(isset($_POST['update'])){
$update=$_POST['s_grade'];
$s_subject=$row['Subject'];

$query="UPDATE `1st_ year_1st_sem` SET Grade = '$s_grade' WHERE Subject ='$s_subject'";
$result=mysql_query($query) or die ("Cannot connect to database");
}

//it works when i use this query on update
$query="UPDATE `1st_ year_1st_sem` SET Grade = '$s_grade' WHERE Subject ='Eng 11'";
$result=mysql_query($query) or die ("Cannot connect to database");

but i want to query the subject that display on the $row['Subject']; on the search code.

is that possible?? im newbie on php this is the 1st time i use this language.

Re: search record then update

Posted: Thu Aug 20, 2009 2:00 pm
by aceconcepts
I would use mysql_error() to report on any column name errors etc...

Re: search record then update

Posted: Thu Aug 20, 2009 2:07 pm
by jhincen
thanks for the reply, i use mysql_error(); but no error display. T_T

Re: search record then update

Posted: Thu Aug 20, 2009 2:23 pm
by aceconcepts
In that case I would double check all you post names and variable names.

Re: search record then update

Posted: Thu Aug 20, 2009 2:46 pm
by jhincen
yehey thanks sir. actually this my proposed thesis... my thesis is all about viewing the student grades for student and adding/updating records for admin. so far i finished it except for this last one.

if any one can read my post and have an idea feel free to post here so that i can try it ^_^.