Page 1 of 1

My Project: Trying to store text found in a forum.

Posted: Fri Feb 24, 2006 8:32 pm
by tmaiden
First you log into the site.
Once logged in, you can view posts.
In my signature, I have a script that runs. I want my script to save to my database the user's name who is viewing my post.
When you view the source of the post there is a line that has the user's id in it.

I want to store the whole entire page into a varable then seach for the user's id and insert it into my database, along with a time stamp, plus more to come.

This is what I have so far.

Code: Select all

<?php
	$ch = curl_init();
	$timeout = 10;
	curl_setopt ($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	$contents = curl_exec($ch);
	curl_close($ch);

	$data = file($contents); 
	$length = count($data); 
 
	for ($i=0; $i<$length; $i++)
	{ 
		$tempString = $data[$i]; 
		$point1 = strpos($tempString, "up_UserID"); 
		$strpoint2 = "', '";
		if ($point1 > 0)
		{ 
			$point2 = strpos($tempString, $strpoint2);
			$ttest = substr($tempString, $point1+14, ($point2-$point1)-14);
		} 
	} 

	$username="hidden";
	$password="hidden";
	$database="hidden";

	$connection = mysql_connect("hidden",$username,$password);
	mysql_select_db("hidden",$connection);


	$query = "insert into temp set ID=" . $ttest;
	echo $query;
	$result=mysql_query($query);
	echo $contents;


?>
And of course, I am new to PHP and none of this works.

Posted: Fri Feb 24, 2006 8:51 pm
by tmaiden
Is there a reason to why I try to insert $url into my database and noting shows up?

Posted: Fri Feb 24, 2006 8:53 pm
by feyd
It's nonnumeric. You're creating a syntax error for MySQL.

the url should be inside single quotes inside the query.

Posted: Fri Feb 24, 2006 8:57 pm
by tmaiden
This was just a temp table, ID is a string field.

I also just did a strlen($contents) and it returns 0