1

Whenver i try to update my columms in a selected row from PHP, it passed through without error, but it doesn't update in the database.

$query = "UPDATE news SET title = '$title', 
                  cover = '$cover', desc = '$newz', category = '$category' 
        WHERE id = $newz_select_id";
John Woo
  • 249,283
  • 65
  • 481
  • 481
Kevin Jensen Petersen
  • 373
  • 1
  • 21
  • 40
  • Does a simple `SELECT` or `INSERT` query work? Also you should know that your query is vulnerable to [SQL injection attack](https://www.owasp.org/index.php/SQL_Injection) if any of the variables are obtained from the user. – Ranhiru Jude Cooray Sep 23 '12 at 16:56

1 Answers1

4

desc is a reserved keyword in MySQL. Escape it with backtick ( ` ) instead.

$query = "UPDATE news SET title = '$title', 
              cover = '$cover', `desc` = '$newz', category = '$category' 
    WHERE id = $newz_select_id";

by the way, your code is very susceptible to sql injection. in order to avoid it, please study and use PHP PDO or PHP mySQLi Extensions.

See this Link: Best way to prevent SQL Injection

Community
  • 1
  • 1
John Woo
  • 249,283
  • 65
  • 481
  • 481