PHP-MYSQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
palak123
Forum Newbie
Posts: 2
Joined: Mon Oct 10, 2011 8:03 am

PHP-MYSQL

Post by palak123 »

hi everyone. im getting the problem in database, i want to store the price of the product in my database and fetch it from the database, display in my website . but im getting the problem in inserting the price in database, every time it stores 0 as a price.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP-MYSQL

Post by Celauran »

We'll need a little more info than that. Can you show us the code you're using?
palak123
Forum Newbie
Posts: 2
Joined: Mon Oct 10, 2011 8:03 am

Re: PHP-MYSQL

Post by palak123 »

Code: Select all

<html>
<body >
<?php

// Get the ID and number of loops

	if(!$_POST[ "submit" ])
	{ 
		echo " Please go to input.php and fill up! "; } else {
		$offset = $_POST[ "boundry" ];

// Get into loop
	for ($i=0; $i<$offset; $i++)
	{
		//$id = 290603968340;
		$id = $_POST[ "fname" ];
		$key = "http://www.ebay.co.uk/itm/";
		$pID =$id + $i;
		$format = $key.$pID;
		echo $format."<br />";

		// If the listing has ended:

		if($site = @file_get_contents($format))
		{	
			echo "Id is valid <br />";
			
		
			if ( preg_match('@("v4-1-msg")@', $site, $ended) ==false ) 
			{
				echo "match- Yes.". "Product available! <br /> ";

				// Item condition:
				if ( preg_match('@(vi-is1-condText">)(.{1,10})(<)@', $site, $condition) ) 
				{
					echo "match- Yes ";} else {echo "match- No ";
				}
				$con = $condition[2];
				echo "Item condition    : ".$con."<br />";

				// Sold:
				if (preg_match('@(>)(.{1,4})(sold<)@', $site, $qtysold) ) 
				{
					echo "match- Yes "; $sold = $qtysold[2];} else {	echo "match- No ";   $sold = 0;
				}
				echo "Sold so far : ".$sold."<br />";

				// Price:
				if ( preg_match('@("vi-is1-prcp")(.{5,30})(<)@', $site, $pprice) ) 
				{	
					echo "match- Yes "; 
					if(preg_match('@(\$)(.*)@', $pprice[2], $priceUSD))
					{ 
						$Price = $priceUSD[2]; $pcurrency= "$";
						$pr = $priceUSD[2];
						echo "Price : ".$pr."<br />"; 
				     }
					 else 
					 {
						preg_match('@(">)(.*)@', $pprice[2], $priceGBP); 
						$Price = $priceGBP[2]; $pcurrency= "£";		
						$pr = $priceGBP[2];
						echo "Price : ".$pr."<br />";
					} 
					
					} else {echo "match- No <br />";
				}
		
				// Delivery: fshippingCost, 2 option Free or Value also Currency

				if ( preg_match('@(fshippingCost")(.{0,80})(>)(.{3,10})(</span>)@', $site, $delivery) ) 
				{	
					echo "match- Yes ";} else {echo "match- No ";
				}
			
				if ( preg_match('@(Free)@', $delivery[0], $outa) ) 
				{
					$deliverycost = 0; $currency="£";} else {
					preg_match('@(">)(.*)(<)@', $delivery[0], $outF);
					
					if(preg_match('@(£)(.*)@', $outF[2], $delGBP))
					{
						$deliverycost = $delGBP[2];
						$currency= "£";} else	{preg_match('@(\$)(.*)@', $outF[2], $delUSD);
						$deliverycost = $delUSD[2];
						$currency= "$";
					}
				}
				$dc = $currency.$deliverycost;
				echo "Delivery cost : ".$dc."<br />";
				
				// Seller:
				if ( preg_match('@("mbg-nw">)(.{1,50})(</)@', $site, $seller) ) 
				{	
					echo "match- Yes ";} else {echo "match- No ";
				}
				$sp = $seller[2];
				echo "Seller                : ".$sp."<br />";
				
				// Product discription:
				if ( preg_match('@("vi-is1-titleH1">)(.{1,100})(</)@', $site, $discription) ) 
				{	
					echo "match- Yes ";} else {echo "match- No ";
				}
				$dp = $discription[2];
				echo "Product Discription : ".$dp."<br />"; }else {echo "Listing ended <br />";
			
			}
				
					
				}
				
				else 
			{
				echo "This product is no longer available <br/>";
			}
		echo $pID."<br />";
	}
	//*
					// mySQL 
					//connect
				// display
			
					mysql_connect("localhost","root") or
					die('Could not connect to MySQL: ' . mysql_error()); 
					echo "Connection OK"."<br/>"; 
					
					// Select DB, Table and Insert Data
					mysql_select_db("mydb") or
					die('Could not connect to Database: ' . mysql_error());
					echo "Connected to Database"."<br/>"; 
				
					$res = mysql_query("SELECT * 
					FROM etb ");
					
					mysql_query(
					" INSERT INTO `mydb`.`etb` (`ID`,`pID`,`description`,`condition`,`price`,`delivery`,`sold`,`Seller`) 
					VALUES(NULL, '$pID','$dp','$con','$pr','$dc','$sold','$sp' ) "
					) or die('Could not insert to Database: ' . mysql_error());
					echo "Data inserted into Database"."<br/>"; 
		
					
			}		
?>						

<table width="700" border="1" cellspacing="0" cellpadding="0"> 
 <tr> 
 <td>ID</td> 
 <td>Product ID</td> 
 <td>Description</td> 
 <td>Product Condition</td>
 <td>Price</td> 
 <td>Delivery Cost</td>
 <td>Sold so far</td> 
 <td>Seller</td>
 
 <?php
 	
	while($display = mysql_fetch_array($res))
	{
		echo "<tr><td>",$display['ID'],"</td><td>",$display['pID'],"</td><td>",$display['description'],"</td><td>",$display['condition'],"</td><td>",$display['price'],"</td><td>",$display['delivery'],"</td><td>",$display['sold'],"</td><td>",$display['Seller'],"</td></tr>"  ;
	}
?>

</table>

</body>
</html>

above is the code of my work. price is displayed on the page, but it would not be updated in database and because of that can not display in table.
can u suggest me, what should i do?
Last edited by Benjamin on Sat Oct 15, 2011 11:55 am, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
Post Reply