I am basically just trying to update multiple values in my table. What would be the best way to go about this? Here is the current code:
$postsPerPage = $_POST['postsPerPage'];
$style = $_POST['style'];
mysql_connect ("localhost", "user", "pass") or die ('Error: ' . mysql_error());
mysql_select_db ("db");
mysql_query("UPDATE settings SET postsPerPage = $postsPerPage WHERE id = '1'") or die(mysql_error());
The other update I want to include is:
mysql_query("UPDATE settings SET style = $style WHERE id = '1'") or die(mysql_error());
Thanks!
This question is related to
php
mysql
sql
sql-update
I guess you can use:
$con = new mysqli("localhost", "my_user", "my_password", "world");
$sql = "UPDATE `some_table` SET `txid`= '$txid', `data` = '$data' WHERE `wallet` = '$wallet'";
if ($mysqli->query($sql, $con)) {
print "wallet $wallet updated";
}else{
printf("Errormessage: %s\n", $con->error);
}
$con->close();
If you are using pdo, it will look like
$sql = "UPDATE users SET firstname = :firstname, lastname = :lastname WHERE id= :id";
$query = $this->pdo->prepare($sql);
$result = $query->execute(array(':firstname' => $firstname, ':lastname' => $lastname, ':id' => $id));
Comma separate the values:
UPDATE settings SET postsPerPage = $postsPerPage, style = $style WHERE id = '1'"
Source: Stackoverflow.com