I want to capture the value of: <div id="result"></div>
which keep on changing, into a php variable $foo and then insert it into the database. My codes:
<?php
include('config.inc');
$foo = '<div id="result"></div>';
$query= "INSERT INTO register(name) VALUES('$foo')";
echo $foo;
mysql_query($query) or die('An Error occurred' .mysql_error());
?>
The error: Value inserted into the db is:
<div id="result"></div>
, not the value that user has enter... Any help please?
Try this, Use the php DomDocument class. http://www.php.net/manual/en/class.domdocument.php
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$divContent = $xpath->query('//div[id="product_list"]');
this code will return the content of all divs with id result
$value=preg_match_all('/<div id=\"result\">(.*?)<\/div>/s',$foo,$estimates);
print_r($estimates);
Test this :-
$value=preg_match_all('/<div id=\"result\">(.*?)<\/div>/s',$foo,$estimates); $query= "INSERT INTO register(name) VALUES('".$estimates[0]."')";