View difference between Paste ID: uAxCvCsX and v6SUDiX9
SHOW: | | - or go back to the newest paste.
1
<?php
2
	// Get the html returned from the following url and scrape from it
3
	$html = file_get_contents('http://www.phoenixpark.ie/newsevents/2013/title,24194,en.html'); 
4
5
	$park_doc = new DOMDocument();  // Declare a new DOM object
6
7
	libxml_use_internal_errors(TRUE); // Disable libxml errors
8
9
	if(!empty($html))    // If any html is actually returned
10
	{
11
	  $park_doc->loadHTML($html);
12
	  libxml_clear_errors(); //remove html errors
13
	  
14
	  $xpath = new DOMXPath($park_doc);  //DOMXPath allows queries with the DOM document. 
15
	  
16
	  // Perform xpath query to find information
17
	  $event_title = $xpath->query('//h1[not(@class)]');  //gets the event title, ignores any other h1 headings on the page
18
	}
19
	
20
	//-------------------------CONNECTION AND INSERTION INTO DATABASE---------------------------
21
	$username = 'root';
22
	$password = '';
23
	$database = 'park';
24
	$host = 'localhost';
25
26
	$con = mysqli_connect($host, $username, $password, $database);
27
28
	// Check connection
29
	if (mysqli_connect_errno())
30
			echo "Failed to connect to MySQL: " . mysqli_connect_error();
31
		else
32
			echo "</br></br>Connected...</br>";
33
34
	//Check if database is found
35
	$db_found = mysqli_select_db($con, $database)or die("cannot select DB");
36
	if ($db_found)
37
	{
38-
		print "Database Found </br>";
38+
39
		mysqli_select_db($con, $database)or die("cannot select DB");
40
		
41
		$sql = "INSERT INTO events (title)
42
			VALUES
43
			('$event_title')";
44
45
		mysqli_query($con, $sql);
46
47
		print "Inserted";
48
	}
49
	else 
50
		print "Database NOT Found ";
51
?>