Jump to content

how save price with product name in database mysql..


tazeha
 Share

Recommended Posts

I using PHP Simple HTML DOM Parser .

Now I write the mini script .

This script find the products online shopping with price.

<?phpinclude_once('simple_html_dom.php');// Create DOM from URLheader("Refresh: 300;");$html = file_get_html('http://wpu.ir/v3128');$articles = array();// Find all article blocksforeach($html->find('div#content') as $article) {    $item['title']     = $article->find('h1', 0)->plaintext;    $item['intro']    = $article->find('h3', 0)->plaintext;    $item['details'] = $article->find('span.finalprice', 0)->plaintext;    $articles[] = $item;}echo $title="<b>نام محصول:</b>". $item['title'] . "</br>  ";echo  $dec="<b>توضیحات:</b> ". $item['intro'] . "</br> "; echo $pr="<b>قیمت:</b> ". $item['details'] . " </br> ";  //to fetch all images from a webpage$images = array();foreach($html->find('img') as $img) { $images[] = $img->src;}echo " $images[29]";?> 

I have save price in table database mysql.. how can?

Link to comment
Share on other sites

what have you tried? Have you looked in the SQL tutorials?

http://www.w3schools.com/php/php_mysql_intro.asp

 

You'll need to create a database. Then create a table that you can INSERT data into.

  • Like 1
Link to comment
Share on other sites

I can help you work on code you've written. If you're not going to try, after providing a link to the tutorials and some recommended steps to get you going, then there's not much I can do for you.

Link to comment
Share on other sites

sorry, but I dont have only code.. I saw the tutorial but , don't know how save the varible title ,.. save to table.

 

first , I do connect the mysql with this code ..

$con=mysqli_connect("example.com","peter","abc123","my_db");// Check connectionif (mysqli_connect_errno()) {  echo "Failed to connect to MySQL: " . mysqli_connect_error();}

but, after this I don't know how do save in table..

 

founded one code than save in table but so I don't know.

 

http://stackoverflow.com/questions/13868799/storing-php-simple-html-dom-results-to-mysql-db

Link to comment
Share on other sites

I already told you what to do

 

You'll need to create a database. Then create a table that you can INSERT data into.

 

hint:

http://www.w3schools.com/php/php_forms.asp

http://www.w3schools.com/php/php_mysql_insert.asp

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Thank's for your help.

 

Now I create

<?phpinclude_once('simple_html_dom.php');// Create DOM from URLheader("Refresh: 300;");$html = file_get_html('http://www.digikala.com/Product/DKP-33708/Kenwood-KMM023-Food-Processor/%D8%BA%D8%B0%D8%A7%D8%B3%D8%A7%D8%B2-%DA%A9%D9%86%D9%88%D9%88%D8%AF-KMM023');$con = mysql_connect ("localhost","root", "");                mysql_select_db("price", $con);   if (!$con)                {  die(mysql_error());   }else {// Find all article blocksforeach($html->find('div#content') as $article) {                $item['title']   = $article->find('h1', 0)->plaintext;                $item['intro']  = $article->find('h3', 0)->plaintext;                $item['details'] = $article->find('span.finalprice', 0)->plaintext;                $articles[] = $item;}$articles = array("$item"=>"title","$item"=>"intro","$item"=>"details");mysql_select_db ( "price", $con );mysql_qeury("CREATE TABLE Persons(id INT NOT NULL AUTO INCREMENT,PRIMARY KEY(id),title CHAR(30),intro TNT,details CHAR 30) ENGINE=MyISAM") or die(mysql_error());$debugquery = mysql_query("INSERT INTO Persons (title, intro, details) VALUES ('$articles')");                if (!$debugquery)   {   die(mysql_error());  }}echo$title="<b>نام محصول:</b>". $item['title'] . "</br>  ";echo$dec="<b>توضیحات:</b> ". $item['intro'] . "</br> ";echo$pr="<b>قیمت:</b> ". $item['details'] . " </br> ";//to fetch all images from a webpage$images = array();foreach($html->find('img') as $img) {$images[] = $img->src;}echo " $images[29]";?> 

but I have 2 problem.

 

When run top code Receives Error line 23

Fatal error: Call to undefined function mysql_qeury() in C:wampwwwNew foldersimplehtmldom_1_5test.php on line 23
mysql_qeury("CREATE TABLE Persons(id INT NOT NULL AUTO INCREMENT,PRIMARY KEY(id),title CHAR(30),intro TNT,details CHAR 30) ENGINE=MyISAM") or die(mysql_error()); 

and what is database field table photo Specifications for save in database.

 

type is :blob but what are other's setting?

 

Thank's

Edited by tazeha
Link to comment
Share on other sites

There's no reason for me to write my own PDO tutorial, there are plenty already out there:https://www.google.com/search?client=opera&q=introduction+to+pdo&sourceid=opera&ie=UTF-8&oe=UTF-8Make sure you read about error handling and prepared statements with PDO, you need to use those. It's not enough to replace a few functions, using prepared statements is a completely different way of using the database. It's also the correct way. The old mysql extension should never have gotten as popular as it did, because it does not promote security at all.

Link to comment
Share on other sites

can you fix top code and Explain the fix code/

 

thanks

the error message is clearly telling you what the problem is (as well as JSG)

 

Fatal error: Call to undefined function mysql_qeury() in C:wampwwwNew foldersimplehtmldom_1_5test.php on line 23

 

 

You didn't spell the function correctly, pay attention to the error message. And you should really stop using the mysql extension and switch to either mysqli or PDO, with prepared statements.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...