Update table not successful in MySQL


Update table not successful in MySQL



I already create an update sql statement, however if I echo the update sql, it shows that the values is updated, but when I check at the table, nothing have been change.
Here is the update statement


$updatesql="UPDATE patient_surgery
set rn_no ='$rn_no',
ic_no = '$ic_no',
ot_location = '$ot_location',
ot_date = '$otdate',
ward = '$ward',
paying_status = '$paying_status',
class = '$class',
arrived_fr = '$arrived_fr',
discharge_to = '$discharge_to'
WHERE rn_no = '$rn_no'
and ot_date = '$otdate'";

if (mysql_query($updatesql))
{
echo "<p>successful</p>";
echo ($updatesql);

} else {
echo mysql_error();
}



and this is the print_r statement


UPDATE patient_surgery set rn_no ='RN001-13', ic_no = '771102016050', ot_location = '3', ot_date = '2014-02-12', ward = '01', paying_status = '2', class = '1', arrived_fr = '2', discharge_to = '3' WHERE rn_no = 'RN001-13' and ot_date = '2014-02-12'



and this is the value in the table after updating



"
+ Options
Full texts Surg_Id rn_no ic_no ot_location ot_date ward paying_status class arrived_fr discharge_to
Edit Edit Copy Copy Delete Delete rand52fad20d168f69.42722209 RN001-13 771102016050 2 2014-02-10 015 1 2 1 1"





this is the value in the table after updating - What does that imply? Does that mean the values in the table remained as it is, or got updated? It's unclear from your question.
– Amal Murali
Feb 16 '14 at 4:50


this is the value in the table after updating





yes..value in the table has not changed..but when i echo updatesql statmt, it says updated
– user3315170
Feb 16 '14 at 4:55





where is your query call? ie. mysql_query($updatesql). You are only showing the query you created.
– Sean
Feb 16 '14 at 5:00


mysql_query($updatesql)





this is it if (mysql_query($updatesql)) { echo "<p>Kemaskini Patient Data Berjaya</p>"; echo ($updatesql); echo "No rows updated: <br />n" . htmlspecialchars($updatesql); } else { echo mysql_error(); }
– user3315170
Feb 16 '14 at 5:12





edit your post with the added code
– wribit
Feb 16 '14 at 5:14




1 Answer
1



Your update query is based upon room no. and date. Date gets changed at the time of query submission and when WHERE clause looks for this current date, it doesn't find it and hence nothing happens. (Compare the ot_date in your query and in your database)


ot_date



First of all, you don't have any primary key such as id. Your query should be based upon that id which remains unchanged and should not be displayed to update. Think if someone changes room no and date then how your WHERE clause is gonna find the matching record?


primary key





tq...i'll try again
– user3315170
Feb 16 '14 at 5:55






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages