I'm a bit behind when it comes to mysqli, and so just starting to convert over to using it. I've got a script however that just doesn't want to work and either throws up a 500 error or gives the wrong result.
$sql = $mysqli->query("SELECT dateid FROM thedates WHERE bdate = '".$thedate."' AND userid = ".$userid." LIMIT 1");
if ($sql->num_rows()) :
$sql2 = $mysqli->query("UPDATE thedates SET value = '".$status."', cvalue = '' WHERE bdate = '".$thedate."' AND userid = ".$userid." LIMIT 1");
else :
$sql2 = $mysqli->query("INSERT INTO thedates (userid, bdate, daytime, value) VALUES (".$userid.", '".$thedate."', 1, '".$status."')");
endif;
I simply want to say, does a record for this date and userid exist, if so, update it, else insert it. I'm trying to get the insert part to work. Using $sql->num_rows() says it's undefined. I've also tried:
if ($mysqli->query("SELECT dateid FROM thedates WHERE bdate = '".$thedate."' AND userid = ".$userid." LIMIT 1")) :
which always gives true, so only tries to update.
Anyone know what I'm doing wrong?
