Reputation: 3
<?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..
Upvotes: 0
Views: 130
Reputation: 10732
You need to change the WHERE clause from:
WHERE Registration_no=='".$id."'
to
WHERE Registration_no='".$id."'
Upvotes: 2
Reputation: 38147
Do this :
if(!mysql_query($query,$link)) {
die (mysql_error());
} else {
echo "Record updated successfully!";
}
mysql_error()
will give you the exact error message - the issue could just about be anything ... connection problem / query syntax error / missing data etc
Upvotes: 1