PHP - Automating Data Exchange
Hello,
I have tried to figure it out on my own for two months, but just don't get it. My goal is to have automated data exchange to my e-shop. It is in Estonian. http://www.elnetsec.ee/pood/ And the place I have to get the data from is a e-shop called Acme. acc.acme.lt All they gave me was a php document and told me to use it. I'll copy it here, so maybe someone can give me advice, which lines do I have to add and which to change. <?php class Filter { public $Name; public $Value; } class ArrayOfFilter { public $Filter; } class GetProductListRequest { public $Filters; } class GetProductList { public $GetProductListRequest; } class GetInvoiceListRequest { public $Filters; } class GetInvoiceList { public $GetInvoiceListRequest; } class GetInvoiceDetailsRequest { public $Filters; } class GetInvoiceProductSerialList { public $GetInvoiceProductSerialListRequest; } class GetInvoiceProductSerialListRequest { public $Filters; } class GetInvoiceDetails { public $GetInvoiceDetailsRequest; } class GetProductSpecification { public $GetProductSpecificationRequest; } class GetProductSpecificationRequest { public $Filters; } class GetProductResourcesRequest { public $Filters; } class GetProductResources { public $GetProductResourcesRequest; } class GetProductBarcodeList { public $GetProductBarcodeListRequest; } class GetProductBarcodeListRequest { public $Filters; } class GetAddressList { public $GetAddressListRequest; } class GetAddressListRequest { public $Filters; } class GetCustomerUserList { public $GetCustomerUserListRequest; } class GetCustomerUserListRequest { public $Filters; } class GetInvoiceShipments { public $GetInvoiceShipmentsRequest; } class GetInvoiceShipmentsRequest { public $Filters; } class GetOrderDetails { public $GetOrderDetailsRequest; } class GetOrderDetailsRequest { public $Filters; } class PurchaseProducts { public $PurchaseProductsRequest; } class PurchaseProductsRequest { public $Filters; public $PurchaseLines; } class ProductPurchaseLine { public $ProductPurchaseLineId; public $SupplierCode; public $Quantity; public $DeliveryTypeId; public $DeliveryAddress; public $Note; } class Address { public $AddressId; public $Street; public $City; public $PostalCode; public $CountryCode; } class AcmeAPI { public $licenseKey = '498ec72c-e8e7-48f2-b300-d95666aeb141'; private $soapClient = null; private $soapHeader = null; private $wsdl = 'https://api.acme.lt/1.0/commerce.asmx?WSDL'; private function init () { $map = array( "Filter"=>"Filter", "ArrayOfFilter" => "ArrayOfFilter", "GetProductListRequest"=>"GetProductListRequest", "GetProductList"=>"GetProductList", "GetInvoiceList"=>"GetInvoiceList", "GetInvoiceListRequest"=>"GetInvoiceListRequest", "GetProductSpecification"=>"GetProductSpecification", "GetProductSpecificationRequest"=>"GetProductSpecificationRequest", "GetProductResources"=>"GetProductResources", "GetInvoiceDetails"=>"GetInvoiceDetails", "GetInvoiceDetailsRequest"=>"GetInvoiceDetailsRequest", "GetInvoiceProductSerialList"=>"GetInvoiceProductSerialList", "GetInvoiceProductSerialListRequest"=>"GetInvoiceProductSerialListRequest", "GetAddressList" => "GetAddressList", "GetAddressListRequest" => "GetAddressListRequest", "GetCustomerUserList" => "GetCustomerUserList", "GetCustomerUserListRequest" => "GetCustomerUserListRequest", "GetInvoiceShipments" => "GetInvoiceShipments", "GetInvoiceShipmentsRequest" => "GetInvoiceShipmentsRequest", "GetOrderDetails" => "GetOrderDetails", "GetOrderDetailsRequest" => "GetOrderDetailsRequest", "PurchaseProducts" => "PurchaseProducts", "PurchaseProductsRequests" => "PurchaseProductsRequest", "ProductPurchaseLine" => "ProductPurchaseLine", "DeliveryAddress" => "Address" ); $this->soapClient = new SoapClient($this->wsdl,array('classmap'=> $map ,'trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS )); $this->soapHeader = new SoapHeader('http://schemas.acme.eu/', 'LicenseHeader', array('LicenseKey'=>$this->licenseKey), false); $this->soapClient->__setSoapHeaders(array($this->soapHeader)); } public function getVendors() { try { $this->init(); $result = $this->soapClient->GetVendorList(); foreach ($result->GetVendorListResult->VendorList->Vendor as $b) { print $b->VendorId." ".$b->VendorName."<br />"; } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getInvoiceList() { try { $this->init(); $request = new GetInvoiceListRequest(); $request->Filters = new ArrayOfFilter(); $datefrom = new Filter(); $datefrom->Name = "InvoiceDateFrom"; $datefrom->Value= "2008.01.01"; $dateTo = new Filter(); $dateTo->Name = "InvoiceDateTo"; $dateTo->Value = "2009.03.16"; $parameters = $request->Filters->Filter = array( $datefrom,$dateTo); $params = new GetInvoiceList(); $params->GetInvoiceListRequest = $request; $result = $this->soapClient->GetInvoiceList($params); if(isset($result->GetInvoiceListResult->InvoiceHeaderList->InvoiceHeader)) { foreach ($result->GetInvoiceListResult->InvoiceHeaderList->InvoiceHeader as $inv) { print $inv->InvoiceNumber." ".$inv->InvoiceDate."</br>"; } } else { print "no invoices found"; } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getInvoiceDetails() { try { $this->init(); $request = new GetInvoiceDetailsRequest(); $request->Filters = new ArrayOfFilter(); $invoice = new Filter(); $invoice->Name = "InvoiceNumber"; $invoice->Value= "ACC-01722223"; $parameters = $request->Filters->Filter = array($invoice); $params = new GetInvoiceDetails(); $params->GetInvoiceDetailsRequest = $request; $result = $this->soapClient->GetInvoiceDetails($params); foreach ($result->GetInvoiceDetailsResult->InvoiceList as $inv) { print $inv->InvoiceHeader->InvoiceNumber." ".$inv->InvoiceHeader->InvoiceDate."</br>"; foreach($inv->InvoiceLine as $line) { print $line->SupplierCode." | ".$line->ShortName." | ".$line->LineAmount."<br />"; } } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getInvoiceProductSerials() { try { $this->init(); $request = new GetInvoiceProductSerialListRequest(); $request->Filters = new ArrayOfFilter(); $invoice = new Filter(); $invoice->Name = "InvoiceNumber"; $invoice->Value= "ACC-00761335"; $parameters = $request->Filters->Filter = array($invoice); $params = new GetInvoiceProductSerialList(); $params->GetInvoiceProductSerialListRequest = $request; $result = $this->soapClient->GetInvoiceProductSerialList($params); foreach ($result->GetInvoiceProductSerialListResult->ProductSerialList->ProductSerial as $ps) { print $ps->SupplierCode." ".$ps->SerialNumber."</br>"; } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getProductSpecification() { try { $this->init(); $request = new GetProductSpecificationRequest(); $request->Filters = new ArrayOfFilter(); $language = new Filter(); $language->Name = "Language"; $language->Value= "en-us"; $product = new Filter(); $product->Name = "SupplierCode"; $product->Value= "032016"; $parameters = $request->Filters->Filter = array($language, $product); //$parameters = $request->Filters->Filter = array($language); $params = new GetProductSpecification(); $params->GetProductSpecificationRequest = $request; $result = $this->soapClient->GetProductSpecification($params); foreach ($result->GetProductSpecificationResult->ProductSpecification as $spec) { print $spec->SupplierCode." "; foreach($spec->ProductProperty as $property) { print $property->PropertyName.": ".$property->PropertyValue."<br />" ; } } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getProductResources() { try { $this->init(); $request = new GetProductResourcesRequest(); $request->Filters = new ArrayOfFilter(); $language = new Filter(); $language->Name = "Language"; $language->Value= "en-us"; $product = new Filter(); $product->Name = "SupplierCode"; $product->Value= "025348"; $parameters = $request->Filters->Filter = array($language, $product); //$parameters = $request->Filters->Filter = array($language); // all resources will be returned if no product filter supplied $params = new GetProductResources(); $params->GetProductResourcesRequest = $request; $result = $this->soapClient->GetProductResources($params); foreach ($result->GetProductResourcesResult->ProductResources as $res) { print $res->SupplierCode." "; if(isset($res->ProductResource)) { foreach($res->ProductResource as $r) { print $r->ResourceName.": ".$r->ResourceURL."<br />" ; } } } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getProductBarcodes() { try { $this->init(); $request = new GetProductBarcodeListRequest(); $params = new GetProductBarcodeList(); $params->GetProductBarcodeListRequest = $request; $result = $this->soapClient->GetProductBarcodeList($params); if($result->GetProductBarcodeListResult->ProductBarcodeList->ProductBarcode) { foreach ($result->GetProductBarcodeListResult->ProductBarcodeList->ProductBarcode as $b) { print $b->SupplierCode." ".$b->Barcode."<br />"; } } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getProductClassification () { try { $this->init(); $result = $this->soapClient->GetProductClassification(); // segments print "Segments list:<br />"; foreach ($result->GetProductClassificationResult->SegmentList->Segment as $b) { print $b->SegmentId." ".$b->SegmentName."<br />"; } print "-----------------------------------------------<br />"; // Groups print "Group list:<br />"; foreach ($result->GetProductClassificationResult->GroupList->Group as $b) { print $b->GroupId." ".$b->GroupName."<br />"; } print "-----------------------------------------------<br />"; // Classes print "Class list:<br />"; foreach ($result->GetProductClassificationResult->ClassList->Class as $b) { print $b->ClassId." ".$b->ClassName."<br />"; } print "-------------------------------------------------<br />"; // Series print "Series list:<br />"; foreach ($result->GetProductClassificationResult->SeriesList->Series as $b) { print $b->SeriesId." ".$b->SeriesName."<br />"; } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getProductList () { try { $this->init(); $request = new GetProductListRequest(); $request->Filters = new ArrayOfFilter(); $language = new Filter(); $language->Name = "Language"; $language->Value= "lt-lt"; $currency = new Filter(); $currency->Name = "Currency"; $currency->Value = "LTL"; $request->Filters->Filter = array( $language,$currency); $params = new GetProductList(); $params->GetProductListRequest = $request; $result = $this->soapClient->GetProductList($params); foreach ($result->GetProductListResult->ProductList->Product as $p) { print $p->SupplierCode." ".$p->Name."<br />"; } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getInvoiceShipments() { try { $this->init(); $request = new GetInvoiceShipmentsRequest(); $request->Filters = new ArrayOfFilter(); $invoice = new Filter(); $invoice->Name = "InvoiceNumber"; $invoice->Value= "ACC-00761335"; // set invoice number here $parameters = $request->Filters->Filter = array($invoice); $params = new GetInvoiceShipments(); $params->GetInvoiceShipmentsRequest = $request; $result = $this->soapClient->GetInvoiceShipments($params); foreach ($result->GetInvoiceShipmentsResult->ShipmentList->Shipment as $ps) { print $ps->CarrierId." ".$ps->Number."</br>"; } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getOrderDetails() { try { $this->init(); $request = new GetOrderDetailsRequest(); $request->Filters = new ArrayOfFilter(); $parameters = $request->Filters->Filter = array(); $params = new GetOrderDetails(); $params->GetOrderDetailsRequest = $request; $result = $this->soapClient->GetOrderDetails($params); if(isset($result->GetOrderDetailsResult->OrderList->Order)) { foreach ($result->GetOrderDetailsResult->OrderList->Order as $o) { print "OrderId: ".$o->OrderHeader->OrderId." <br />"; foreach($o->OrderLine as $line) { print "OrderLineId: ".$line->OrderLineId." SupplierCode: ".$line->SupplierCode." LineAmount: ".$line->LineAmount." <br />"; } print "----------------------------------------------------<br />"; } } else { print "no orders found"; } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function purchaseProducts() { try { $this->init(); $request = new PurchaseProductsRequest(); $request->Filters = new ArrayOfFilter(); $request->Filters->Filter = array(); $line = new ProductPurchaseLine(); $line->ProductPurchaseLineId = "demo"; $line->SupplierCode = "003315"; $line->Quantity = 1; $line->DeliveryTypeId = 0; $line->Note = "test order"; $address = new Address(); $address->AddressId = "ecommtest-001"; $line->DeliveryAddress = $address; $request->PurchaseLines = array($line); $params = new PurchaseProducts(); $params->PurchaseProductsRequest = $request; $result = $this->soapClient->PurchaseProducts($params); foreach ($result->PurchaseProductsResult->StatusList->ProductPurchaseStatus as $st) { print $st->ProductPurchaseLineId." ".$st->Status."<br />"; } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getAddressList() { try { $this->init(); $request = new GetAddressListRequest(); $request->Filters = new ArrayOfFilter(); $request->Filters->Filter = array(); $params = new GetAddressList(); $params->GetAddressListRequest = $request; $result = $this->soapClient->GetAddressList($params); foreach ($result->GetAddressListResult->AddressList->Address as $b) { print $b->AddressId." ".$b->Street." ".$b->City."<br />"; } //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } public function getCustomerUserList() { try { $this->init(); $request = new GetCustomerUserListRequest(); $request->Filters = new ArrayOfFilter(); $request->Filters->Filter = array(); $params = new GetCustomerUserList(); $params->GetCustomerUserListRequest = $request; $result = $this->soapClient->GetCustomerUserList($params); if(isset($result->GetCustomerUserListResult->UserList->User)) { foreach ($result->GetCustomerUserListResult->UserList->User as $b) { print $b->UserId." ".$b->FirstName." ".$b->LastName."<br />"; } } // uncomment this line to see raw result of this method response //echo "<pre>". print_r($result,1) . '</pre>'; } catch(SoapFault $e) { echo '<xmp>' . $this->soapClient->__getLastRequestHeaders() . $this->soapClient->__getLastRequest() . '</xmp>'; echo "<pre>". print_r($e,1) . '</pre>'; } } } $client = new AcmeAPI() ; $client->getVendors(); //$client->getProductClassification(); //$client->getProductList(); //$client->getProductBarcodes(); //$client->getInvoiceList(); //$client->GetInvoiceDetails(); //$client->GetInvoiceProductSerials(); //$client->getProductSpecification(); //$client->getProductResources(); //$client->getAddressList(); //$client->getCustomerUserList(); //$client->getInvoiceShipments(); //$client->getOrderDetails(); //$client->purchaseProducts(); ?> Thanks! Similar TutorialsHi, am trying without much luck, (I am new), to define an exchange rate on the page and then mutiplying it by a value I am extracting from a mysql db. I write the value as below normally but having trouble writing this entry and multiplying it by my defined exchanged rate of say 2.22. <?php if(!empty($row['Band_1_Price'])) {echo "<div class=pricing_box_right2>£".$row['Band_1_Price']."</div></div>"; } ?> Thanks so much. Hi .. i have an array format like (mysql result array) $new_array=Array ( [0] => Array ( [quantity] => 5 ) [1] => Array ( [quantity] => 25 ) [2] => Array ( [quantity] => 20 ) ) I have to convert this array into the following format $new_array['quantity'][0]=5 $new_array['quantity'][1]=25 $new_array['quantity'][2]=20 How to convert this array format using any standard array method. Hi guys, New to PHP but learning every day. This is probably a really newbie error but I've tried multiple different ways and can't get it to work. $tableData = ''; if(mysql_num_rows($result)==0) { $tableData = "<tr><td colspan=\"4\">No results returned.</td></tr>\n"; } else { while($row = mysql_fetch_assoc($result)) { $tableData .= " <tr bgcolor='#FFFFFF' align='center'>\n"; $tableData .= " <td>{$rank}</td>\n"; $tableData .= " </tr>\n"; $rank = ($row['rank']); if ($rank == 0) { print "Cadet"; } if ($rank == 1) { print "Sergeant"; } if ($rank == 2) { print "2nd Lieutenant"; } if ($rank == 3) { print "1st Lieutenant"; } if ($rank == 4) { print "Captain"; } if ($rank == 5) { print "Major"; } if ($rank == 6) { print "Lt. Colonel"; } if ($rank == 7) { print "Colonel"; } } } ?> <table class="tables" cellspacing="0" cellpadding="0"> <tr> <th>Rank</th> </tr> <?php echo $tableData; ?> </table> When this script is run the $rank variable shows the numbers 1,2,3,4,5,6,7 instead of the textual translations for example if 0 is displayed then "cadet" should be shown instead. The current script shows the numbers in the table but prints the accurate translations at the top outside the table tag..... Can anyone show me what I've done wrong here? Thank you in advance. $html = @file_get_contents($urlw) or problem('Can\'t open Your Remote URL!'); $html = strtolower($html); $site_url = strtolower($set['site_url']); if (preg_match_all('/<a\s[^>]*href=([\"\']??)([^" >]*?)\\1([^>]*)>/siU', $html, $matches, PREG_SET_ORDER)) { foreach($matches as $match) { if ($match[2] == $set['site_url'] || $match[2] == $set['site_url'].'/') { $found = 1; if (strstr($match[3],'nofollow')) { $nofollow = 1; } break; } } } if ($found == 0) { echo "<center><h2>Our URL Not FOund on your page please submit or check again</h2></center>"; } else next proceggerr.... in $html we getting the content of that page which that user give where he put our link what is this actually this all code is doing infact i was making a link exchange site where on a page people can submit their link for exchange and give their site link and the that page link where they have put our link this code verify at the sPot did they have put our code or not but m facing some problem.. beacuse it's not working good Hi, I making a banner exchange script. Members will have to place a banner code on their sites to make banners appear. Some members might cheat by using bots to refresh the page to gain impressions and to waste other members impressions so i wanted to know if bots have ip addresses? because i want to only give member impressions if their visitors have ip. What are the other things i can do to check if members are cheating?. Thanks
$ip=$_SERVER['REMOTE_ADDR']; Hi All, Its been a while since i've posted, its good to be back. I am currently trying to pull two exchange rates against the $ using YQL's restful url. Unfortunately I am having a huge problem returning the results correct.... currently my array will only output a single rate (instead of two) and the hash array returns with the base rate name rather than the expected currency code. I hope someone can help me sort this as it's given me quite a headache! Please see the code below: Code: [Select] <?php require_once('uwe_proxy.php'); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ # use the yahoo YQL rest service to return any number of rates in a hash function get_yahoo_rest_rate ($base, $curr_arr) { $params = ''; $rates = array(); # define the YQL rest url head & tail $yql_base_uri = "http://query.yahooapis.com/v1/public/yql"; $yql_tail_uri = '&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'; # build up the $params value foreach($curr_arr as $curr) { $params .= $curr.$base.','; } #strip last comma $params = substr($params, 0, -1); # build the query with the params as comma sep. string eg. USDGBP,USDBOB,.. $yql_query = "select * from yahoo.finance.xchange where pair IN ('{$params}')"; # build the the complete YQL query $yql_query_url = $yql_base_uri . "?q=" . urlencode($yql_query) . $yql_tail_uri; # send the query via proxy and get as string and load as simplexml object $yql_response = @simplexml_load_string(file_get_contents_proxy($yql_query_url)); Print_r($yql_query_url); //- debugging only # process simplexml object and return a sorted hash of rates or FALSE on error if ($yql_response) { foreach($yql_response->results->rate as $rate) { if ((float)$rate->Rate>0) { $rates[substr((string)$rate->attributes()->id, -3)] = (float)$rate->Rate; } } ksort($rates); return $rates; } else { return FALSE; }// print_r($yql_response); - debugging only } /////// - debugging only $curr_arr = array('GBP','GBP'); $rates = get_yahoo_rest_rate ('USD', $curr_arr); //PRINT_R($yql_response); print_r($rates); ?> Sorry about dumping the whole lot - but I really don't know where this is going wrong! Thanks in Advance for any help or pointers in the right direction! Hello php Freaks, before i start , let me tell you ; BY GOD, i googled, i used countless search functions on several websites and forums, i even called some friends that told me once, they are good with php, but guess what : No Results , AT ALL! So here i am, sorta desperate and hungry for a solution. I need to admit, and somehow its obvious, i am not much of a Programmer, or Coder of some kind. I be more the gfx type of Guy ! Well, here we go : I bought a php Script, and ran a first test on a free web host ( like always ) to check if all looks fine, works well and runs like a charm. And it did. So i went over to my paid space account, bought a domain, and installed the Script on my new domain. All was fine, until i registered a test account. The Script suppose to send an activation email , with an activation link in it. As i said before, on the FREE web space , it worked just fine, even though i entered a gmail Admin Email. (not like i planed to do support@newdomain.com) After a lot of research and 3 re-installations i contacted the Support to tell them that my script dont work on their Server. And here it comes : They don`t allow php Mail for Spamming Reasons. And they are not willing to make an exception. But, they gave me the advice to implement an authenticated smpt script in order to get the job done. The Vendor, is not willing to help me, and i am to much of a php noob to actually know or understand what to do now. Basically i need to know how i pull of a switch from php mail() to authenticate smpt. Here the original Code, with the mail function : Code: [Select] <?php include('header.php'); if(isset($_POST['register'])){ foreach($_POST as $key => $value) { $sec[$key] = filter($value); } $verificare1 = mysql_query("SELECT * FROM `users` WHERE `login`='{$sec['user']}' OR `email`='{$sec['email']}'"); $verificare = mysql_num_rows($verificare1); if ($verificare > 0) { $mesaj = "<div class=\"error\">ERROR: Username or email already registered!</div>"; }else if (!isUserID($sec['user'])) { $mesaj = "<div class=\"error\">ERROR: Username is incorrect!</div>"; }else if(!isEmail($sec['email'])) { $mesaj = "<div class=\"error\">ERROR: Enter a valid email address!</div>"; }else if (!checkPwd($sec['password'],$sec['password2'])) { $mesaj = "<div class=\"error\">ERROR: Passwords do not match!</div>"; }else{ if(isset($_COOKIE['PlusREF'])){ $ref = $_COOKIE['PlusREF']; $user1 = mysql_query("SELECT * FROM `users` WHERE `id`='{$ref}'"); $user = mysql_fetch_object($user1); mysql_query("INSERT INTO `referals`(user,referal,date) values('{$user->login}','{$sec['user']}',NOW())"); } $activare = rand(000000000, 999999909); mail($sec['email'],"Activate your account"," Hello, Thank you for your signup on our site. Click on this link to activate your account: {$site->site_url}/activate.php?cod={$activare} Best Regards!","From: Site Admin <{$site->site_email}>"); $final = VisitorIP(); $passa = $sec['password']; $passc = MD5($passa); mysql_query("INSERT INTO `users`(email,login,IP,pass,passdecoded,ref,signup,activate) values('{$sec['email']}','{$sec['user']}','$final','$passc','$passa','{$ref}',NOW(),'{$activare}')")or die(mysql_error()); $mesaj = "<div class=\"success\">Registered! You need to confirm your email address now!</div>"; }} ?> <div class="block medium right"> <div class="top"> <h1>Register</h1> </div> <div class="content"><div class="msg"><?echo $mesaj;?></div> <form action="" method="post"> <fieldset> <p> <label>Username</label><br/> <input class="text big" type="text" value="" name="user"/> </p> <p> <label>Email</label><br/> <input class="text big" type="email" value="" name="email"/> </p> <p> <label>Password</label> <br/> <input class="password" type="password" value="" name="password"/> </p> <p> <label>Repeat Password</label> <br/> <input class="password" type="password" value="" name="password2"/> </p> <p> <input type="submit" class="button gray small" value="Register" name="register" /> </p> </fieldset> </form> </div> </div> <?include('footer.php');?> imap_fetchstructure is not returing information about attachments for certain e-mails after the mailbox is migrated to exchange 2010. Using IMAP protocol and was working fine until the migration from exchange 2007 to 2010. 99% of emails with attachments works fine, but few don't. I can replicate the issue when an attachment is sent from gmail accounts or some xerox devices to exchange 2010. The output of imap_fetchstructure (message has no body, only attachment) looks like below, as you can see, parts is returning null. I have tested it using imap-2006e and imap-4.7b libraries and produces same issues. Any ideas how to resolve the issue or debug this issue? Can also replicate the problem in Thunderbird 2.0.0.24 stdClass Object ( [type] => 1 [encoding] => 5 [ifsubtype] => 1 [subtype] => MIXED [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( => stdClass Object ( [attribute] => boundary [value] => AHNKAKBLDCDIDAGCDHGDAAAKACAK ) ) [parts] => Array ( ) ) Am new here - looks like a great foru! I would sincerely appreciate any help anyone can give me. I have been trying to solve my problem for hours and I am not having any luck, so I thought I would post and see if anyone can help. I am very stuck and am not making much progress on this project, and I am certain the answer is very simple. I am constructing a form to collect data for a specialized purpose. The form and program actually work for its intended function, but I am trying to enhance the user experience by preventing customers from having to reenter all of their data should there be a problem with any of the data submitted. I have been able to do that with the contact form portion, but what I am having trouble with is the portion which has as many as 400 possible entries. So, in a nutshell, if the customers contact data is incomplete or in error, the form will ask them to return to the page and correct things. The previous data entered has been saved in the session and the input value will equal the previous entry. i.e. <tr> <td align="right" class="infoBox"><?php echo ENTRY_EMAIL_ADDRESS; ?></td> <td align=left><?php echo "<input type=text name='cemail' value=\"$cemail\" size=35 maxlength=35>" ?></td> </tr> Works perfectly, all well and good there. On the other 400 more or less entries, I am having a difficult time tweaking the string concatenation to work to achieve similar results. There are 4 columns each with $points entries asking for a dimension in either feet or inches. The <input name=> is one of ptaf,ptai,ptbf,ptbi, appended programatically with the corresponding row number or data point. i.e. "ptaf1", "ptai1", etc... This is produced by the example below and works perfectly also. <?php { $points=100; $i=1; while ($i <= $points) {echo ' <tr><td align="center" width="6"><b> ' .$i . '</b></td> <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" name="ptaf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>A' .$i . ' (in) <input type="text" name="ptai'.$i.'" size=4 maxlength=4> </td> <td align="right" NOWRAP>B' .$i . ' (ft) <input type="text" name="ptbf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>B' .$i . ' (in) <input type="text" name="ptbi'.$i.'" size=4 maxlength=4> </td> '; $i++; } } ?> I am trying to add <input value=$ptai.$i> for each field but as I mentioned I am not having any luck. It seems as if I have tried every combination imagineable, but still no luck. My head is spinning! The closest I seem to have gotten was with this: <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="' . "$ptaf" . $i . '" ></td> But line 17 for example returns this: <input type="text" value="17" name="ptaf17" maxlength="3" size="6"> To recap, I am trying to have the value set to whatever the customer may have entered previously. Again, I would most appreciate any help anyone can give me. If you need clarification on anything please let me know. Thanks AJ Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. I have two tables. Table Name:Users Fields: User_name user_email user_level pwd 2.Reference Fields: refid username origin destination user_name in the users table and the username field in reference fields are common fields. There is user order form.whenever an user places an order, refid field in reference table will be updated.So the user will be provided with an refid Steps: 1.User needs to log in with a valid user id and pwd 2.Once logged in, there will be search, where the user will input the refid which has been provided to him during the time of order placement. 3.Now User is able to view all the details for any refid 3.Up to this we have completed. Query: Now we need to retrieve the details based on the user logged in. For eg: user 'USER A' has been provided with the referenceid '1234' during the time of order placement user 'USER B' has been provided with the referenceid '2468' during the time of order placement When the userA login and enter the refid as '2468' he should not get any details.He should get details only for the reference ids which is assigned to him. <?php session_start(); if (!$_SESSION["user_name"]) { // User not logged in, redirect to login page Header("Location: login.php"); } $con = mysql_connect('localhost','root',''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); $user_name = $_POST['user_name']; $refid = $_POST['refid']; $query = "SELECT * from reference,users WHERE reference.username=users.user_name AND reference.refid='$refid' AND "; $result = mysql_query($query) or trigger_error('MySQL encountered a problem<br />Error: ' . mysql_error() . '<br />Query: ' . $query); while($row = mysql_fetch_array($result)) { echo $row['refid']; echo $row['origin']; echo $row['dest']; echo $row['date']; echo $row['exdate']; echo $row['username']; } echo "<p><a href=\"logout.php\">Click here to logout!</a></p>"; ?> <html> <form method="post" action="final.php"> Ref Id:<input type="text" name="refid"> <input type="submit" value="submit" name="submit"> </html> Here's the code that deals with the client side:
<?php session_start(); if(!isset($_SESSION['Logged_in'])){ header("Location: /page.php?page=login"); } ?> <!DOCTYPE Html> <html> <head> <!--Connections made and head included--> <?php require_once("../INC/head.php"); ?> <?php require_once("../Scripts/DB/connect.php"); ?> <!--Asynchronously Return User Names--> <script> $(document).ready(function(){ function search(){ var textboxvalue = $('input[name=search]').val(); $.ajax( { type: "GET", url: 'search.php', data: {Search: textboxvalue}, success: function(result) { $("#results").html(result); } }); }; </script> </head> <body> <div id="header-wrapper"> <?php include_once("../INC/nav2.php"); ?> </div> <div id="content"> <h1 style="color: red; text-align: center;">Member Directory</h1> <form onsubmit="search()"> <label for="search">Search for User:</label> <input type="text" size="70px" id="search" name="search"> </form> <a href="index.php?do=">Show All Users</a>|<a href="index.php?do=ONLINE">Show All Online Users</a> <div id="results"> <!--Results will be returned HERE!--> </div>search.php <?php //testing if data is sent ok echo "<h1>Hello</h1><br>" . $_GET['search']; ?>This is the link I get after sending foo. http://www.family-li...php?&search=foo Is that mean it was sent, but I'm not processing it correctly? I'm new to the whole AJAX thing. Say there is a complex opt in process where people start to enter their data but certain questions stop them where they close out of the page. They already entered their data and I feel there is a way to grab it and post it to mysql even though they do not click submit.
How would this be done?
A super simple example (proof of concept) or a link to a tutorial would be very useful.
Edited by brentman, 23 September 2014 - 10:42 AM. This could be PHP or MySql so putting it in PHP forum for now... I have code below (last code listed) which processes a dynamically created Form which could have anywhere from 0 to 6 fields. So I clean all fields whether they were posted or not and then I update the mySQL table. The problem with this code below is that if, say, $cextra was not posted (i.e. it wasnt on the dynamically created form), then this code would enter a blank into the table for $cextra (i.e. if there was already a value in the table for $cextra, it gets overwritten, which is bad). What is the best way to handle this? I'm thinking i have to break my SQL query into a bunch of if/else statements like this... Code: [Select] $sql = "UPDATE cluesanswers SET "; if (isset($_POST['ctext'])){ echo "ctext='$ctext',"; } else { //do nothing } and so on 5 more times.... That seems horribly hackish/inefficient. Is there a better way? Code: [Select] if (isset($_POST['hidden']) && $_POST['hidden'] == "edit") { $cimage=trim(mysql_prep($_POST['cimage'])); $ctext=trim(mysql_prep($_POST['ctext'])); $cextra=trim(mysql_prep($_POST['cextra'])); $atext=trim(mysql_prep($_POST['atext'])); $aextra=trim(mysql_prep($_POST['aextra'])); $aimage=trim(mysql_prep($_POST['aimage'])); //update the answer edits $sql = "UPDATE cluesanswers SET ctext='$ctext', cextra='$cextra', cimage='$cimage', atext='$atext', aextra='$aextra', aimage='$aimage'"; $result = mysql_query($sql, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { } Hi, after banging my head against the wall for a while thinking this would be a simple task, I'm discovering that this is more complicated than I thought. Basically what I have is a link table linking together source_id and subject_id. For each subject there are multiple sources associated with each. I had created a basic listing of sources by subject... no problem. I now need a way of having a form to create an ordered list in a user-specified way. In other words, I can currently order by id or alphabetically (subject name lives on a different table), but I need the option of choosing the order in which they display. I added another row to this table called order_by. No problem again, and I can manage all of this in the database, however I want to create a basic form where I can view sources by subject and then enter a number that I can use for sorting. I started off looping through each of the entries and the database (with a where), and creating a foreach like so (with the subject_id being grabbed via GET from the URL on a previous script) Code: [Select] while($row = mysqli_fetch_array($rs)) { //update row order if (isset($_POST['submit'])) { //get variables, and assign order $subject_id = $_GET['subject_id']; $order_by = $_POST['order_by']; $source_id = $row['source_id']; //echo 'Order by entered as ' . $order_by . '<br />'; foreach ($_POST['order_by'] as $order_by) { $qorder = "UPDATE source_subject set order_by = '$order_by' WHERE source_id = '$source_id' AND subject_id = '$subject_id'"; mysqli_query($dbc, $qorder) or die ('could not insert order'); // echo $subject_id . ', ' . $order_by . ', ' . $source_id; // echo '<br />'; } } else { $subject_id = $_GET['subject_id']; $order_by = $row['order_by']; $source_id = $row['source_id']; } And have the line in the form like so: Code: [Select] echo '<input type="text" id="order_by" name="order_by[]" size="1" value="'. $order_by .'"/> (yes I know I didn't escape the input field... it's all stored in an htaccess protected directory; I will clean it up later once I get it to work) This, of course, results in every source_id getting the same "order_by" no matter what I put into each field. I'm thinking that I need to do some sort of foreach where I go through foreach source_id and have it update the "order_by" field for each one, but I must admit I'm not sure how to go about this (the flaws of being self-taught I suppose; I don't have anyone to go to on this). I'm hoping someone here can help? Thanks a ton in advance Hi, I want to pull data from db, where sometimes all rows and sometimes rows matching given "username". Here is my code:
//Grab Username of who's Browsing History needs to be searched. if (isset($_GET['followee_username']) && !empty($_GET['followee_username'])) { $followee_username = $_GET['followee_username']; if($followee_username != "followee_all" OR "Followee_All") { $query = "SELECT * FROM browsing_histories WHERE username = \"$followee_username\""; $query_type = "followee_username"; $followed_word = "$followee_username"; $follower_username = "$user"; echo "$followee_username"; } else { $query = "SELECT * FROM browsing_histories"; $query_type = "followee_all"; $followed_word = "followee_all"; $follower_username = "$user"; echo "all"; } }
When I specify a "username" in the query via the url: browsing_histories_v1.php?followee_username=requinix&page_number=1 I see result as I should. So far so good.
Now, when I specify "all" as username then I see no results. Why ? All records from the tbl should be pulled! browsing_histories_v1.php?followee_username=all&page_number=1 This query shouldv'e worked:
$query = "SELECT * FROM browsing_histories";
Hi I am trying to select and order data/numbers from a colum in a mysql data base however i run the code and it returns no value just a blank page no errors or any thing so i think the code is working right but then it returns no result? Please help thanks Here is the code: <?php $host= "XXXXXX"; $mysql_user = "XXXXXX"; $mysql_password = "XXXXXX"; $mysql_database = "XXXXXXX"; $connection = mysql_connect("$host","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server."); mysql_select_db($mysql_database) or die ("Unable to select requested database."); $row = mysql_fetch_assoc( mysql_query( "SELECT XP FROM Game ORDER BY number DESC LIMIT 1" ) ); $number = mysql_result(mysql_query("SELECT XP FROM Game ORDER BY number DESC LIMIT 1"), 0); echo "The the highest XP is $number"; ?> I can add and delete data from my table. Now I need to be able to change one or more fields in an entry. So I want to retrieve a row from the db, display that data on a form where the user can change any field and then pass the changed data to an update.php program. I know how to go from form to php. But how do I pass the data from retrieve.php to a form so it will display? Do I use a URL and Get? Can I put the retrieve and form in the same program? I'm pulling data from an xml file and I'm getting a lot of duplicates. How can I remove the duplicates from the query? Code: [Select] foreach($xml->category->subcategory as $category){ echo $category[id]; }//end foreach Hi, I've currently started to modify a chat script of mine to output a moderation panel but the moderation page seems empty(blank) every time I load it. What im trying to do is to take the ID part in my URL via the $_GET and look it up in my database table in the column named id, then select that specific row to be able to retrieve the StringyChat_ip and place it into another table to ban the IP and the second thing im trying to do is to be able to delete the specific row from my table.
My Http link look something like
http://imagecrab.fre.../ban.php?id=159
and my ban.php page where I want to lookup the 159 part and do the banning etc looks like
<? include("admin_code_header.php"); if ($_POST["DeletePost"]) { $id = $_POST['id']; $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; mysql_query($query); echo "ID removed from system: ".$id; } if ($_POST["BanIP"]) { $IP_To_Add = $_POST["ip"]; $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")"; $result = mysql_query($sql); } $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'",$db); while ($myrow = mysql_fetch_array($result)) { $msg = $myrow["StringyChat_message"]; $idm = $myrow["id"]; ?> <html> <form name="form<? echo $myrow["id"];?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="DeletePost" type="submit" id="DeletePost" value="Delete"> <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>"> </form> </html> <? } ?> |