esiason14 Posted April 1, 2007 Share Posted April 1, 2007 I'm parsing my pages to find all id's. What I want to do is: if the id already exists in my db then I want to update it...if not I want to insert a record. How can I go about doing that. Any help would be appreciated. Thanks!! foreach ($url as $value) { $base = "http://www.mypage.com/whatever"; $getit = "".$base."$value"; $input = file_get_contents("$getit"); preg_match_all('@<a href="/whatever/([A-Za-z0-9-]+)">(.*?), (.*?)</a>@', $input, $matches); for($i=0;$i<40;$i++) { $sql3 = "SELECT id from mlbplayers where id=".$matches[1][$i].""; while ($row3 = mysql_fetch_assoc($result3)) { $pid = $row3["id"]; } echo "$sql3<br />"; } } Link to comment https://forums.phpfreaks.com/topic/45139-update-record-if-existsinsert-if-not/ Share on other sites More sharing options...
jaku78 Posted April 1, 2007 Share Posted April 1, 2007 $sql3 = "SELECT id from mlbplayers where id=".$matches[1][$i].""; You cannot have code like this. You're confusing the PHP with double quotes IN double quotes. You should have it like this. $sql3 = "SELECT id from mlbplayers where id='.$matches[1][$i].'"; When you cannot use double quotes in html, php, sql, you usually use a alternative like '. Link to comment https://forums.phpfreaks.com/topic/45139-update-record-if-existsinsert-if-not/#findComment-219153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.