Page 1 of 1

update records

Posted: Sat Aug 22, 2009 9:14 am
by jhincen
can any one help me? i have a problem how to update the records..
example. i search the records then the records are display in this row

Code: Select all

 
echo "<tr>";
echo "<form name='form' method='POST' action='1y1supdate.php'>";
echo "<td>".$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_remaks' value=".$row['Remaks']."></td>";
echo "<td><input type='submit' name='update' value='update'></td></form>";
echo "</tr>";
 
then i want to update the rows using this query

Code: Select all

 
$query="UPDATE `1st_ year_1st_sem` SET Grade = '$s_grade' WHERE Subject = '$s_subject ' ";
$result=mysql_query($query) or die ('Cannot connect to database: ' . mysql_error());
 
the WHERE Subject = '' is my problem.. what is the best query for this?

tnx for the person who will help me

Re: update records

Posted: Sat Aug 22, 2009 2:17 pm
by Darhazer
You have to add a hidden field to the form, that will contain the subject:

Code: Select all

 
 
can any one help me? i have a problem how to update the records..
example. i search the records then the records are display in this row
 
echo "<tr>";
echo "<form name='form' method='POST' action='1y1supdate.php'>";
echo "<td><input type='hidden' name='s_subject' value='".$row['Subject']."'>".$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_remaks' value=".$row['Remaks']."></td>";
echo "<td><input type='submit' name='update' value='update'></td></form>";
echo "</tr>";
 

Re: update records

Posted: Sat Aug 22, 2009 10:23 pm
by jhincen
thank you sir for reply but what would be my 1y1supdate.php code?
this is mine but nothings happen when i click the update.

Code: Select all

 
$s_grade=$_POST['s_grade'];
$s_subject=$_POST['Subject'];
 
$connect = mysql_connect("localhost","root","");
if (!$connect)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("student_db", $connect);
 
 
if(isset($_POST['update'])){
$update=$_POST['s_grade'];
}
$query="UPDATE `1st_ year_1st_sem` SET Grade = '$s_grade' WHERE Subject = '$s_subject'";
$result=mysql_query($query) or die ('Cannot connect to database: ' . mysql_error());
 
 

Re: update records

Posted: Sat Aug 22, 2009 10:48 pm
by jhincen
yehey its working now. i add this var and now its working..

Code: Select all

 
if(isset($_POST['update'])){
$update=$_POST['s_grade'];
$s_subject=$_POST['s_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: ' . mysql_error());
 
sorry for my double post...
Darhazer thank you.. without your reply i cannot do it.. and thanks for this forum. i finished my thesis ^_^