<?php
$id=$_REQUEST['id'];
$sub=array();
$sub=$_REQUEST['sub'];
$total=0;
for($i=0;$i<count($sub); $i++)
{
$total=$total+$sub[$i];
}
$link=mysql_connect("localhost","root","") or die("Cannot Connect to the database!");
mysql_select_db("nps_exam",$link) or die ("Cannot select the database!");
$query= "UPDATE four SET 'sub[1]'='".$sub[0]."' , 'sub[2]'='".$sub[1]."' , 'sub[3]'='".$sub[2]."' , 'sub[4]'='".$sub[3]."' , 'sub[5]'='".$sub[4]."' , 'sub[6]'='".$sub[5]."' , 'sub[7]'='".$sub[6]."' , 'sub[8]'='".$sub[7]."' , 'sub[9]'='".$sub[8]."' , 'Music'='".$sub[9]."' , 'Arts'='".$sub[10]."' , 'total'='".$total."' WHERE Registration_no=='".$id."'";
if(!mysql_query($query,$link))
{die ("An unexpected error occured while saving the record, Please try again!");}
else
{
echo "Record updated successfully!";}
?>
I am new to php.While updating records from this above php code. I always get error message saying An unexpected error occured while saving record,also I cannot get my data updated..please anyone help..