Verán, tengo este código.
Quiero hacer que al buscar películas en IMDB me regresé los datos de la película. HECHO. Ahora quiero que esos datos, al dar clic en un botón, los envíe a una base de datos. ¿Cómo lo podría hacer?
Código PHP:
<?php
//Busqueda
$imdb = new Imdb();
$movieArray = $imdb->getMovieInfoById($_POST["num"]);
echo '<table id="tabla" cellpadding="3" cellspacing="2" border="1" width="80%" align="center">';
foreach ($movieArray as $key=>$value){
$value = is_array($value)?implode("<br />", $value):$value;
echo '<tr>';
echo '<th align="left" valign="top">' . strtoupper($key) . '</th><td>' . $value . '</td>';
echo '</tr>';
echo '</table>';
}
//Obtener datos
class Imdb
{
function getMovieInfoById($imdbId)
{
$arr = array();
$imdbUrl = "http://www.imdb.com/title/" . trim($imdbId) . "/";
$html = $this->geturl($imdbUrl);
if(stripos($html, "<meta name=\"application-name\" content=\"IMDb\" />") !== false){
$arr = $this->scrapMovieInfo($html);
$arr['imdb_url'] = $imdbUrl;
} else {
$arr['error'] = "¡No se econtro en IMDb!";
}
return $arr;
}
function scrapMovieInfo($html)
{
$arr = array();
$arr['titulo'] = trim($this->match('/<title>(IMDb \- )*(.*?) \(.*?<\/title>/ms', $html, 2));
$arr['year'] = trim($this->match('/<title>.*?\(.*?(\d{4}).*?\).*?<\/title>/ms', $html, 1));
$arr['rating'] = $this->match('/ratingValue">(\d.\d)</ms', $html, 1);
$arr['generos'] = array();
foreach($this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Genre.?:(.*?)(<\/div>|See more)/ms', $html, 1), 1) as $m)
array_push($arr['generos'], $m);
$arr['director'] = array();
foreach($this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Director.?:(.*?)(<\/div>|>.?and )/ms', $html, 1), 1) as $m)
array_push($arr['director'], $m);
$arr['cast'] = array();
foreach($this->match_all('/<td class="name">(.*?)<\/td>/ms', $html, 1) as $m)
array_push($arr['cast'], trim(strip_tags($m)));
$arr['sinopsis'] = trim(strip_tags($this->match('/<p itemprop="description">(.*?)(<\/p>|<a)/ms', $html, 1)));
$arr['duracion'] = trim($this->match('/Runtime:<\/h4>.*?(\d+) min.*?<\/div>/ms', $html, 1));
if($arr['duracion'] == '') $arr['duracion'] = trim($this->match('/infobar.*?(\d+) min.*?<\/div>/ms', $html, 1));
$arr['idioma'] = array();
foreach($this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Language.?:(.*?)(<\/div>|>.?and )/ms', $html, 1), 1) as $m)
array_push($arr['idioma'], trim($m));
$arr['pais'] = array();
foreach($this->match_all('/<a.*?>(.*?)<\/a>/ms', $this->match('/Country:(.*?)(<\/div>|>.?and )/ms', $html, 1), 1) as $c)
array_push($arr['pais'], $c);
return $arr;
}
}
}
echo '<body>';
echo '<form method="post" action=".php" />';
echo '<input type="submit" values="TEST" name="boton">';
echo '</body>';
?>
El botón al final es para que al darle clic me agregue los difrerentes $arr a la base de datos.
Una prueba...
Código:
Es esta la forma correcta?$insert ="INSERT INTO personas(Titulo,Año,Rating) VALUES ("$arr['titulo']","$arr['year']","$arr['rating']")"; mysql_query($insert) OR die(mysql_error());
Hay alguna otra manera de que mis datos en los array vayan a mi base de datos?