Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.92 KB | None | 0 0
  1. <?php
  2. /** Copyright (C) 2016 Duncan Lee **/
  3. // Duncan Lee
  4. // March 25th, 2016
  5.  
  6. /*
  7.  `payments` Table structure:
  8.  1  shopname                    varchar(70)
  9.  2  expire_date                 date
  10.  3  user_level                  varchar(12)
  11.  4  payer_email                 varchar(100)
  12. */
  13.  
  14. // Read the configuration file
  15. $access = fopen("test.ini", "r");
  16.     $server = trim(fgets($access));
  17.     $user = trim(fgets($access));
  18.     $password = trim(fgets($access));
  19.     $database = trim(fgets($access));
  20.     $rowreset = trim(fgets($access));
  21.     $curlreset = trim(fgets($access));
  22.     $imagedirectory = trim(fgets($access));
  23.     $extraLine = trim(fgets($access));
  24. fclose($access);
  25.  
  26. // Extra variables
  27. $store = '';
  28. $mostRecent = '';
  29. $zeroResults = false;
  30.  
  31. // Create connection
  32. $_SESSION['database'] = $database;
  33. $conn = mysqli_connect($server, $user, $password, $database);
  34.  
  35. // Check for connection errors
  36. if($conn->connect_errno > 0) {
  37.     echo "<font color='red'><strong>Error: Failed to make a MySQL connection, here is why:<br>";
  38.     echo "Error:  " . $mysqli->connect_errno . "</strong></font><br>";
  39.     exit;
  40. }
  41.  
  42. /**
  43. ** having the shop name passed through $_GET means this script can be used by anyone if they had a list of shop names.  
  44. ** TODO: i'm going to redo this after I get the script working.
  45. **/
  46. // Check for and store the shop parameter
  47. if (isset($_GET['shop'])) {
  48.     // Save the store name
  49.     $store = isset($_GET['shop']) ? is_array($_GET['shop']) ? $_GET['shop'][0] : $_GET['shop'] : '';
  50.    
  51.     /** Delete the active record from `payments` **/
  52.     $result = $conn->query("DELETE FROM `payments` WHERE `shopname`='" . $store . "'");
  53.    
  54.     // Before we process any data, lets make sure the query returned something.
  55.     if (!$result) {
  56.         // This is triggered when 0 rows are returned from the SQL query
  57.         $zeroResults = true;
  58.         echo "Deleting record failed: (" . $conn->errno . ") " . $conn->error;
  59.     } elseif (empty($result)) {
  60.         echo "<font color='red' size='2'><strong>Error:  The requested SQL query returned no results.  No active record was found in `payments`.</strong></font><br>";
  61.     } else {
  62.         if (mysqli_num_rows($result) > 0) {
  63.             echo "not sure how to get the result/affected rows back.<br>";
  64.         } else {
  65.             // TODO: http://u18450875.onlinehome-server.com/cancel.php?shop=ellu.myshopify.com
  66.             // TODO: IT ALWAYS GOES HERE
  67.             echo mysqli_num_rows($result) . "<br>";
  68.             echo "not found?";
  69.         }      
  70.     }
  71.    
  72.     // Return an error if no results were found for the shopname.
  73.     if ($zeroResults) {
  74.         echo "<font color='red' size='2'><strong>Error:  The requested SQL query returned no results.  No active record was found in `payments`.</strong></font><br>";
  75.         $zeroResults = false;
  76.     }
  77.    
  78.    
  79.     /** Turn daily_email off in `settings` **/
  80.     //$result = $conn->query("UPDATE `settings` SET `daily_email`=0 WHERE `shopname`='" . $store . "'");
  81.  
  82.    
  83.     // Return an error if no results  were found.
  84.     if ($zeroResults) {
  85.         echo "<font color='red' size='2'><strong>Error:  The requested SQL query returned no results.  The shop could not be found in `settings`.</strong></font><br>";
  86.         $zeroResults = false;
  87.     }
  88.    
  89.    
  90.     /** Turn auto_run off in `settings` **/
  91.     //$result = $conn->query("UPDATE `settings` SET `auto_run`=0 WHERE `shopname`='" . $store . "'");
  92.    
  93.     // Return an error if no results  were found.
  94.     if ($zeroResults) {
  95.         echo "<font color='red' size='2'><strong>Error:  The requested SQL query returned no results.  The shop could not be found in `settings`.</strong></font><br>";
  96.         $zeroResults = false;
  97.     }
  98. } else {
  99.     /** Since no shop parameter was passed, we will output the whole table. **/
  100.     // Throwing an error as no shop parameter was passed.
  101.     // echo "<strong><font color=red>Error:  No shop parameter given.  The entire table will be displayed.</font></strong><br>";
  102.    
  103.     // Instead of giving an obvious error when no parameter is passed, we will fake a 404 error.
  104.     header ("HTTP/1.1 404 Not Found");
  105.     echo file_get_contents('../error_docs/404.html');
  106.     exit();
  107. }
  108.  
  109. // Close the connection.
  110. $conn->close();
  111. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement