Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /** Copyright (C) 2016 Duncan Lee **/
- // Duncan Lee
- // March 25th, 2016
- /*
- `payments` Table structure:
- 1 shopname varchar(70)
- 2 expire_date date
- 3 user_level varchar(12)
- 4 payer_email varchar(100)
- */
- // Read the configuration file
- $access = fopen("test.ini", "r");
- $server = trim(fgets($access));
- $user = trim(fgets($access));
- $password = trim(fgets($access));
- $database = trim(fgets($access));
- $rowreset = trim(fgets($access));
- $curlreset = trim(fgets($access));
- $imagedirectory = trim(fgets($access));
- $extraLine = trim(fgets($access));
- fclose($access);
- // Extra variables
- $store = '';
- $mostRecent = '';
- $zeroResults = false;
- // Create connection
- $_SESSION['database'] = $database;
- $conn = mysqli_connect($server, $user, $password, $database);
- // Check for connection errors
- if($conn->connect_errno > 0) {
- echo "<font color='red'><strong>Error: Failed to make a MySQL connection, here is why:<br>";
- echo "Error: " . $mysqli->connect_errno . "</strong></font><br>";
- exit;
- }
- /**
- ** having the shop name passed through $_GET means this script can be used by anyone if they had a list of shop names.
- ** TODO: i'm going to redo this after I get the script working.
- **/
- // Check for and store the shop parameter
- if (isset($_GET['shop'])) {
- // Save the store name
- $store = isset($_GET['shop']) ? is_array($_GET['shop']) ? $_GET['shop'][0] : $_GET['shop'] : '';
- /** Delete the active record from `payments` **/
- $result = $conn->query("DELETE FROM `payments` WHERE `shopname`='" . $store . "'");
- // Before we process any data, lets make sure the query returned something.
- if (!$result) {
- // This is triggered when 0 rows are returned from the SQL query
- $zeroResults = true;
- echo "Deleting record failed: (" . $conn->errno . ") " . $conn->error;
- } elseif (empty($result)) {
- 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>";
- } else {
- if (mysqli_num_rows($result) > 0) {
- echo "not sure how to get the result/affected rows back.<br>";
- } else {
- // TODO: http://u18450875.onlinehome-server.com/cancel.php?shop=ellu.myshopify.com
- // TODO: IT ALWAYS GOES HERE
- echo mysqli_num_rows($result) . "<br>";
- echo "not found?";
- }
- }
- // Return an error if no results were found for the shopname.
- if ($zeroResults) {
- 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>";
- $zeroResults = false;
- }
- /** Turn daily_email off in `settings` **/
- //$result = $conn->query("UPDATE `settings` SET `daily_email`=0 WHERE `shopname`='" . $store . "'");
- // Return an error if no results were found.
- if ($zeroResults) {
- 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>";
- $zeroResults = false;
- }
- /** Turn auto_run off in `settings` **/
- //$result = $conn->query("UPDATE `settings` SET `auto_run`=0 WHERE `shopname`='" . $store . "'");
- // Return an error if no results were found.
- if ($zeroResults) {
- 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>";
- $zeroResults = false;
- }
- } else {
- /** Since no shop parameter was passed, we will output the whole table. **/
- // Throwing an error as no shop parameter was passed.
- // echo "<strong><font color=red>Error: No shop parameter given. The entire table will be displayed.</font></strong><br>";
- // Instead of giving an obvious error when no parameter is passed, we will fake a 404 error.
- header ("HTTP/1.1 404 Not Found");
- echo file_get_contents('../error_docs/404.html');
- exit();
- }
- // Close the connection.
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement