Page 1 of 1
If Record Exists, Update It. If Not, Insert It.
Posted: Mon May 11, 2009 4:13 pm
by WithHisStripes
I'm not sure how I would write a PHP statement that says "if a record with this value exists, then update it, if it doesn't, then insert it."
Can someone give me a hand? Thanks!
Re: If Record Exists, Update It. If Not, Insert It.
Posted: Mon May 11, 2009 5:12 pm
by WithHisStripes
Code: Select all
$sql = "SELECT COUNT(*) AS total FROM tableName WHERE recordName` = '$record'";
$query = mysql_query($sql);
$row = mysql_fetch_assoc($query);
$total = $row['total'];
if ($total == 1) {
} else {
}
Re: If Record Exists, Update It. If Not, Insert It.
Posted: Mon May 11, 2009 5:34 pm
by pickle
Look up the REPLACE() statement. This can be done in MySQL without necessarily needing any PHP logic.