A M Ishtiaque Sarwar 5 days ago

PHP MySQL record update error

I am wondering what mistakes has been made in this pretty simple update statement using old version of php. If i echo the statement it says update statement is getting form submitted properly.

Here is the code

<?php
echo $q = "UPDATE notice SET FromDate = $notice_fromdate, ToDate = $notice_todate, VacType ='$notice_vactype',NoticeDetail ='$notice_detail',Status ='$notice_status' WHERE ID=$id";

if (mysql_query($link, $q)) {
    echo "Record updated successfully";
} else {
    echo "<h3>Error updating record</h3>". mysql_error($link)."-". mysql_errno($link). "\n";
}

?>

and the output returns this 

UPDATE notice SET FromDate = 2017-01-08, ToDate = 2017-01-09, VacType ='May Day',NoticeDetail ='Testing',Status ='Enabled' WHERE ID=3
Error updating record
-0

I know its a pretty simple thing, i guess i have not made any mistake in the update statement but instead it is showing Error update record. I copied the output sql statement and run at phpmyadmin, it has worked properly. It would be nice if you can help me. Thank in advance

Note: Clients website built on old version of php, i know that few functions got deprecated so it would be better if you do not discuss or criticize about the version.

Answers


NITIN PATEL 5 days ago

Apply quotes to dates it will work

<?php
echo $q = "UPDATE notice SET FromDate = '$notice_fromdate', ToDate = '$notice_todate', VacType ='$notice_vactype',NoticeDetail ='$notice_detail',Status ='$notice_status' WHERE ID=$id";

if (mysql_query($link, $q)) {
    echo "Record updated successfully";
} else {
    echo "<h3>Error updating record</h3>". mysql_error($link)."-". mysql_errno($link). "\n";
}

?>

Post Status

Asked in 5 days ago
Viewed 3,060 times
Voted 9
Answered 1 times

Search




Leave an answer