Can anybody help me understand why this update query isn”t updating the fields in my database? I have this in my php page to retrieve the current values from the database:
Here i my HTML Form:
ID: ” />Username: ” />Title: “/>Date: “/>Message: and here is my “editblogscript”:
I don”t understand why it doesn”t work.
Đang xem: Php mysql: update data
Trending sort Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
You have to have single quotes around any VARCHAR content in your queries. So your update query should be:
mysql_query(“UPDATE blogEntry SET content = “$udcontent”, title = “$udtitle” WHERE id = $id”);Also, it is bad form to update your database directly with the content from a POST. You should sanitize your incoming data with the mysql_real_escape_string function.
Xem thêm: 7 Lợi Ích Tuyệt Vời Của Mía Đối Với Thai Nhi Và Mẹ Bầu, Mang Thai 3 Tháng Đầu Có Nên Uống Nước Mía
Need to add quote for that need to use dot operator:
mysql_query(“UPDATE blogEntry SET content = “”.$udcontent.””, title = “”.$udtitle.”” WHERE id = “”.$id.”””);
Without knowing what the actual error you are getting is I would guess it is missing quotes. try the following:
mysql_query(“UPDATE blogEntry SET content = “$udcontent”, title = “$udtitle” WHERE id = “$id””)
Here i updated two variables and present date and time
$id = “1”;$title = “phpmyadmin”;
$sql= mysql_query(“UPDATE table_name SET id =””.$id.””, title = “”.$title.””,now() WHERE id = “”.$id.”” “);now() function update current date and time.
note: For update query we have define the particular id otherwise it update whole table defaulty
First, you should define “doesn”t work”.Second, I assume that your table field “content” is varchar/text, so you need to enclose it in quotes. content = “{$content}”And last but not least: use echo mysql_error() directly after a query to debug.
Try like this in sql query, It will work fine.
$sql=”UPDATE create_test set url= “$_POST
$sql=”UPDATE create_test set `url`= “$_POST
you must write single quotes then double quotes then dot before name of field and after like that
mysql_query(“UPDATE blogEntry SET content =””.$udcontent.””, title = “”.$udtitle.”” WHERE id = “”.$id.”” “);
Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.
Site design / logo © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev2022.8.26.42925
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.