Jump to content

kat35601

Members
  • Content count

    137
  • Joined

  • Last visited

Community Reputation

0 Neutral

About kat35601

  • Rank
    Advanced Member
  1. kat35601

    if (empty()) not working for me

    Thanks I looked and looked bet did not see methd="post". Instead of method="post" but that fixed my problem. Thanks Again
  2. kat35601

    if (empty()) not working for me

    I still do not get the echo "Missing Information required"; <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <style> </style> </head> <body> <?php if(isset($_POST['submit'])){ if(empty($_POST["custid"]) || empty($_POST["item"]) || empty($_POST["qty"])){ echo "Missing Information required"; } } ?> <form action="backorder.php" methd="post"> CustId:<input type="text" name="custid"><br /> Item #:<input type="text" name="item"><br /> Qty :<input type="text" name="qty"><br /> <input type="submit" name="submit" value ="OK"> </form> </body> </html
  3. My if(empty())Statement is not working what did I do wrong??? <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <style> </style> </head> <body> <?php if(isset($_POST['submit'])){ if(empty($_POST["custid"] || $_POST["item"] || $_POST["qty"])){ echo "Missing Information required"; } } ?> <form action="backorder.php" methd="post"> CustId:<input type="text" name="custid"><br /> Item #:<input type="text" name="item"><br /> Qty :<input type="text" name="qty"><br /> <input type="submit" name="submit" value ="OK"> </form> </body> </html>
  4. I would like help bullet proofing my code. So if you could suggest ways to handle exceptions or on better ways to write the code I have I would be grateful. <?php $db= include('/var/app/app_env.php'); $port = 22; $user = $db['cit_user']; $pass = $db['cit_pass']; $host = $db['cit_host']; $connection = NULL; $remote_file_path = "/Outbox/CCDATA.TXT"; $local_file = './cit_order_download'. date('mdY_hia') .'.co'; /////////////////////////////////////////////////////////////// //echo "<td>$host</td>"; /////////////////////////////////////////////////////////////// try { $connection = ssh2_connect($host, $port); if(!$connection){ throw new \Exception("Could not connect to $host on port $port"); } $auth = ssh2_auth_password($connection, $user, $pass); if(!$auth){ throw new \Exception("Could not authenticate with username $user and password "); } $sftp = ssh2_sftp($connection); if(!$sftp){ throw new \Exception("Could not initialize SFTP subsystem."); } $stream = fopen("ssh2.sftp://" .(int)$sftp.'//Outbox//'.'CCDATA.TXT', 'r'); $contents = stream_get_contents($stream); file_put_contents ($local_file, $contents); @fclose($stream); $connection = NULL; } catch (Exception $e) { echo "Error due to :".$e->getMessage(); } //////////////////////////////////////////////////////////////////////////////////////////////// $result_clear=''; $result_hold=''; $connect = odbc_connect($db['name'], $db['user'], $db['password']); $approve_status=array("AA","AC","AD","AX"); $decline_status=array("DA","DR","HC","CI","CR","CZ"); sleep(2); $fp = fopen($local_file, 'r'); while (!feof($fp)) { $line = fgets($fp); $order = substr($line, 69, 5); $status=substr($line, 117, 2); $assignment=substr($line, 91, 10); $order=ltrim(rtrim($order)); if (in_array($status,$approve_status)){ $file_array= array($order=> array($assignment,$status)); $clear="update m1_kf.dbo.salesorders set uompcreditstatus='CLEAR', uompschedulecolor='$status$assignment' where ompsalesorderid ='$order' and ompOrderDate > '12-9-2017'"; echo $order,$assignment,$status; echo "<br>"; $result_clear = odbc_exec($connect, $clear); } elseif (in_array($status,$decline_status)){ $hold="update m1_kf.dbo.salesorders set uompcreditstatus='HOLD', uompschedulecolor='$status$assignment' where ompsalesorderid ='$order' and ompOrderDate > '12-9-2017'"; echo $order,$assignment,$status; echo"<br>"; $result_hold = odbc_exec($connect, $hold); } } fclose($fp); odbc_close($connect); ?>
  5. kat35601

    Message -- Warning: file_get_contents --

    I do now thanks
  6. I am getting the Warning and not sure what my problem is. As you can see I am getting address data from a SQL Server and then trying to get the "lat" and "lng" information using a Google API and put that in an array that I can use later to create a google road map. I will have about 200 locations in the array but it errors out on the first one. I have tried a different address but get the same error.Below is my data from the echo $url ."<br>"; Thank You. and this is what I get from the warning. <?php ini_set('display_errors', 1); error_reporting(E_ALL); $connect =odbc_connect("removed"); if(!$connect) { exit("Connection Failed: " . $connect); } $gr_total = 0; $sql=" select distinct ltrim(rtrim(cmoAddressLine2)) as Street ,ltrim(rtrim(cmoCity)) as City ,ltrim(rtrim(cmoState)) as State ,RIGHT( '00000' + LTRIM( RTRIM( [cmoPostCode] ) ), 5 ) as ZipCode from m1_kf.dbo.SalesOrders left join m1_kf.dbo.Organizations on cmoOrganizationID=ompCustomerOrganizationID where ompRequestedShipDate >'11-01-17' and ompClosed !=-1 " ; $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } $json =array(); //**************************************************************** while ($row = odbc_fetch_array($result)) { $text = $row; $address = implode(", ", $text); //echo $address ."<br>"; $url = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&key=removed'); echo $url ."<br>"; $resp = file_get_contents($url); $lati = $resp['results'][0]['geometry']['location']['lat']; $longi = $resp['results'][0]['geometry']['location']['lng']; $formatted_address = $resp['results'][0]['formatted_address']; if($lati && $longi && $formatted_address){ $data_arr = array(); array_push( $data_arr, $lati, $longi, $formatted_address ); return $data_arr; echo $data_arr ."<br>"; }else{ return false; } } odbc_close($connect); ?>
  7. I do like the " if " before the array but a line may have AA in a name so it would mess me up. while (!feof($fp)) { $line = fgets($fp); if(substr($line, 117, 2)=='AA' | substr($line, 117, 2)=='AC'){ $lines[substr($line, 69, 5)] =substr($line, 91, 10); print_r($lines); } } fclose($fp); my output looks like Array ( [45925] => 171665579 ) Array ( [45925] => 171665579 [46409] => 171662760 ) I get 45925 twice but it's only in the file once.
  8. That went over my head quickly. so let me restart to make sure I do it right. I download a file from an ftp site then I look through that file and pull out 3 items (order number, assignment number, status) I want to filter by status and I may need to filter more than one time. Different status causes different updates. For now, I am just worried about AA and AC my output so far looks like this when I do a print_r Array ( [48578] => Array ( [item1] => 172686046 [item2] => AA ) ) Array ( [48578] => Array ( [item1] => 172686046 [item2] => AA ) [48577] => Array ( [item1] => 172686047 [item2] => AA ) ) Array ( [48578] => Array ( [item1] => 172686046 [item2] => AA ) [48577] => Array ( [item1] => 172686047 [item2] => AA ) [ ] => Array ( [item1] => [item2] => ) ) Array ( [48578] => Array ( [item1] => 172686046 [item2] => AA ) [48577] => Array ( [item1] => 172686047 [item2] => AA ) [ ] => Array ( [item1] => [item2] => ) [0] => Array ( [item1] => [item2] => ) ) now I need to filter this for only AAs because in real time there will be a lot of different statuses. then update my MSSQL update statement. so how do fix my filter and implode or is there a better way to do this? Then how should I update my sql statement? Thanks $curl = curl_init();$fh = fopen("order_test1.txt", 'w'); curl_setopt($curl, CURLOPT_URL, 'ftp://server.com/Outbox/' . $server_file); curl_setopt($curl, CURLOPT_USERPWD, "removed"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); fwrite($fh, $result); fclose($fh); curl_close($curl); } $lines = []; $fp = fopen('order_test1.txt', 'r'); while (!feof($fp)) { $line = fgets($fp); $index = substr($line, 69, 5); $lines[$index] = ['item1' => substr($line, 91, 10), 'item2' => substr($line, 117, 2)]; } fclose($fp); $order=array_filter($lines,function($AA){ return $AA=='AA' | $AA=='AC';} ); //print_r($order); $key_string = implode(',', array_keys($order)); $sql_update="update uag.dbo.SalesOrders set order_credit status=-1, assignment_num= "orders[value2]" where ompsalesorderid in ($key_string)"; $connect = odbc_connect("removed"); $result = odbc_exec($connect, $sql_update);
  9. When I use the subarray it kills my filter and implode. So i will need to tell the filter and implode which array value I want to use 0 or 1 correct. What should that look like? $key_string = implode(',', array_keys($order)); print_r($key_string); $sql_update="select ompsalesorderid from m1_kf.dbo.SalesOrders where ompsalesorderid in ($key_string)"; $connect = odbc_connect("kforbe", "sa", "H25rlz95!"); $result = odbc_exec($connect, $sql_update);
  10. as a second value to the existing key? $lines = [];$fp = fopen('order_test1.txt', 'r'); while (!feof($fp)) { $line = fgets($fp); $lines[substr($line, 69, 5)] = substr($line, 117, 2); //I would like to add second array value substr($line, 91, 10) print_r($lines); } fclose($fp); $order=array_filter($lines,function($AA){ return $AA=='AA' | $AA=='AC';} ); $key_string = implode(',', array_keys($order));
  11. I need to add a second value to my associative array. $lines[substr($line, 69, 5)] = substr($line, 117, 2); I need to add substr($line, 91, 10)
  12. I got it if (ftp_get($ftp_conn, $local_file, $ftp_path.$server_file, FTP_ASCII)) I reversed $local_file and $ftp_path.$server_file and it works. thank you for the input
  13. Array ( [0] => Inbox [1] => Outbox ) Array ( [0] => CCDATA.TXT ) bool(true) Connected as giajhojju@tf.sftp.online.com
  14. This is what I have so far. <?php $local_file = "order.txt"; $server_file = 'CCDATA.TXT'; $ftp_username="removed"; $ftp_userpass="removed"; $ftp_path = '/Outbox/'; $ftp_server = "tf.sftp.online.com"; $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server"); $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass); // download server file echo $ftp_server.$ftp_path.$server_file; if (ftp_get($ftp_conn, $ftp_path.$server_file, $local_file, FTP_ASCII)) { echo "Successfully written to $local_file."; } else { echo "Error downloading $server_file."; } // close connection ftp_close($ftp_conn); // test connection /* $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); // try to login if (@ftp_login($conn_id, $ftp_username, $ftp_userpass)) { print_r(ftp_nlist($ftp_conn, ".")); echo "Connected as $ftp_username@$ftp_server\n"; } else { echo "Couldn't connect as $ftp_username\n"; } // close the connection ftp_close($conn_id); */ ?>
  15. Yes line 16 is the line echo $ftp_server.$ftp_path.$server_file; tf.sftp.online.com/Outbox/CCDATA.TXT
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.