Hi,
I am having a bit of trouble inserting new records into a MySQL Db. My plan is to check if a records exists, if not then insert one.
this was my original code......
$query = "SELECT FROM searchpost WHERE code2 = '$search_post'";
$result3 = mysql_query ("SELECT FROM searchpost WHERE code = '$search_post'");
if (!$row = mysql_fetch_array($result3)) {
$sql3 = "INSERT INTO searchpost (code,gone) VALUES ('$search_post','$gone')";
}
This does not write any records even though the query is empty.
So I thought I'd probably done something wrong so I then searched these forums and found this alternative code :
$query = "SELECT * FROM searchpost WHERE code2 = '$search_post'";
$res=mysql_query($query);
$numrows=mysql_num_rows($res);
if (!numrows) {
$sql3 = "INSERT INTO searchpost (code,gone) VALUES ('$search_post','$gone')";
}
But this returns error :Supplied argument is not a valid MySQL result resource .....(relates to line 2)
Any help would be appreciated.
Thanks