Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL update row where id = 1

Tags:

sql

php

insert

I'm having problems with my php script.

Im settings these variables:

$v1 = mysql_real_escape_string($_POST["v1"]);
$v2 = mysql_real_escape_string($_POST["v2"]);
$v3 = mysql_real_escape_string($_POST["v3"]);
$v4 = mysql_real_escape_string($_POST["v4"]);

I want these values to be updated to the row of my db where id = 1 every time (the row already exists and just need to be updated).

should I then insert or update the row? I've tried this without success:

$sql = "INSERT INTO table1 (v1, v2, v3, v4) WHERE id = 1";
$sql .= "VALUES ('$v1', '$v2', '$v3', '$v4')";
like image 757
Mac Luc Avatar asked Dec 20 '22 04:12

Mac Luc


1 Answers

Use an UPDATE rather than an INSERT.
Try this:

UPDATE table1 set v1 = '$v1', v2 = '$v2', v3 = '$v3', v4 = '$v4' WHERE id = 1
like image 176
Filippos Karapetis Avatar answered Dec 29 '22 17:12

Filippos Karapetis