Jump to content

Update record if exists...Insert if not


esiason14

Recommended Posts

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
Share on other sites

 $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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.