Update data in database with pdo?

I recently made a CMS with mySQL and PDO following a video tutorial from PHPAcademy on youtube.

I want to add an edit function to it though.

I have the page done, but not the PHP to update the data.

So, I'm wondering, how would I update data in the database with PDO and save the new data?

I have this:

$query = $pdo->prepare("UPDATE articles 'article_content'=? WHERE 'id' = ?");
$query->bindValue(1, $_POST['content']);
$query->bindValue(2, $_POST['id']);
$query->execute()

;

Answers


You have 2 issues:

"UPDATE articles SET  `article_content`=? WHERE `id` = ?"

One you are missing SET.

Two you are using single quotes for column names;use backticks


You are missing the keyword SET in your query

It should be

$pdo->prepare("UPDATE articles SET `article_content`=? WHERE `id` = ?");
                           ----^

Need Your Help

ruby nokogiri HTML table scraping using xpath

html ruby table xpath nokogiri

I am tring to get "cell4" value that is written in a HTML table like the following using ruby xpath and nokogiri

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.