Modernvox Posted November 2, 2009 Share Posted November 2, 2009 The Variable is adding a blank value into database row sale_items? I am using a regular expression to copy the email address to be stored in DB, But it inputs a blank value instead of the address? <?php function curlURL($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2'); $output = curl_exec($curl); return $output; } $curlResults = curlURL("http://southcoast.craigslist.org/sss/"); $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#'; preg_match_all( $pattern, $curlResults, $matches); echo "<pre>\n"; echo "Links:\n\n"; foreach ($matches[1] as $link): echo "\t" . '<a href="' . $link . '" target="_BLANK">' . $link . '</a>' . "\n"; endforeach; echo '</pre>'; echo file_get_contents("http://southcoast.craigslist.org".$link); $pattern = '#<sale-\K[a-z0-9]+-\d+@craigslist\.org(?=>)#'; //This is the attempted match for the email preg_match_all( $pattern, $link, $matches); foreach ($matches[0] as $address): $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("Craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$address')"); mysql_close($dbx); endforeach; ?> Quote Link to comment Share on other sites More sharing options...
bubbasheeko Posted November 2, 2009 Share Posted November 2, 2009 If you print_r on the array do you see anything in there? Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 2, 2009 Author Share Posted November 2, 2009 If you print_r on the array do you see anything in there? print_r on the array? Not sure I understand you? Where would I add that? Quote Link to comment Share on other sites More sharing options...
bubbasheeko Posted November 2, 2009 Share Posted November 2, 2009 Well, not really an array. My eyes are boggled from looking at this screen for too long. Replace this: foreach ($matches[0] as $address): $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("Craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$address')"); mysql_close($dbx); endforeach; with this for testing: foreach ($matches[0] as $address): echo $address . "<br>"; //$dbx= mysql_connect("localhost", "root", ""); //include before any database implematation //if (!$dbx) //{ //die('Could not connect: ' . mysql_error()); //} //mysql_SELECT_db("Craigslist", $dbx); //mysql_Query("INSERT INTO addresses (sale_items) //VALUES ('$address')"); //mysql_close($dbx); endforeach; What I have provide will place the output to your screen. Let me know if you see anything. Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 2, 2009 Author Share Posted November 2, 2009 Well, not really an array. My eyes are boggled from looking at this screen for too long. Replace this: foreach ($matches[0] as $address): $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("Craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$address')"); mysql_close($dbx); endforeach; with this for testing: foreach ($matches[0] as $address): echo $address . "<br>"; //$dbx= mysql_connect("localhost", "root", ""); //include before any database implematation //if (!$dbx) //{ //die('Could not connect: ' . mysql_error()); //} //mysql_SELECT_db("Craigslist", $dbx); //mysql_Query("INSERT INTO addresses (sale_items) //VALUES ('$address')"); //mysql_close($dbx); endforeach; What I have provide will place the output to your screen. Let me know if you see anything. It displays the same exact results as before. It shows the links at the top and it shows the open page with the email address I want to copy into DB, But when I go to DB it just shows a blank row instead of the email address Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 2, 2009 Author Share Posted November 2, 2009 Here's my screen http://i266.photobucket.com/albums/ii246/Pencilman_2008/test.jpg Quote Link to comment Share on other sites More sharing options...
bubbasheeko Posted November 2, 2009 Share Posted November 2, 2009 Ya I got that too, I ran it locally. Maybe it is just PHP being picky. Try this: foreach ($matches[0] as $address): $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Craigslist", $dbx); mysql_query("INSERT INTO `addresses` (`sale_items`) VALUES ('$address')"); mysql_close($dbx); endforeach; I added some quotations to your query. Also, speaking of something simple...double check your table name is correct as well as the column name. Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 2, 2009 Author Share Posted November 2, 2009 Nope she won't take the address Quote Link to comment Share on other sites More sharing options...
bubbasheeko Posted November 2, 2009 Share Posted November 2, 2009 Let's see if there is any errors. Change this: mysql_query("INSERT INTO `addresses` (`sale_items`) VALUES ('$address')"); to: mysql_query("INSERT INTO `addresses` (`sale_items`) VALUES ('$address')") or mysql_error(); Let me know if there is an error. Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 2, 2009 Author Share Posted November 2, 2009 Let's see if there is any errors. Change this: mysql_query("INSERT INTO `addresses` (`sale_items`) VALUES ('$address')"); to: mysql_query("INSERT INTO `addresses` (`sale_items`) VALUES ('$address')") or mysql_error(); Let me know if there is an error. Yeah Parse error: syntax error, unexpected T_ENDFOREACH in C:\xampp\htdocs\test5.php on line 38 Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 2, 2009 Author Share Posted November 2, 2009 My Bad, I removed code and now put it back, but still nothing..No errors, but no DB input either.. Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 2, 2009 Author Share Posted November 2, 2009 Seems my code is still grabbing the first regex instead of the second? Anyone know why? Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 2, 2009 Author Share Posted November 2, 2009 I'm onna wait up for this one to get answered since it's bugging the shit out of me Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.