I'm trying to update values in a table that looks like this:
+----+-------------+
| Id | Value |
+----+-------------+
| 1 | title |
+----+-------------+
| 2 | description |
+----+-------------+
| 3 | email |
+----+-------------+
| 4 | keywords |
+----+-------------+
I would like to update the value if the PK already exists, otherwise insert a new row.
submit.php:
include('../../include/config.php');
if($_POST['settings']){
$title=$_POST['title'];
$description=$_POST['description'];
$email=$_POST['email'];
$keywords=$_POST['keywords'];
$test=$db->query("UPDATE `settings` SET `value` = '$title' WHERE `id` =1, SET `value` = '$description' WHERE `id` =2,SET `value` = '$email' WHERE `id` =3, SET `value` = '$keywords' WHERE `id` =4;");
if($test){
echo "good";
}else{
echo "bad";
}
}
UPDATE:
To whoever reading this question now, don't use this structure to store your website settings. and I don't recommend using the query either because it is vulnerable to SQL injection