Jump to content

iwato

Members
  • Posts

    1,506
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by iwato

  1. Less the discussion about the use of the empty() and isset() functions are you suggesting the following rewrite of the constructor function? public function __construct($mysqli_obj, $field) { $this->mysqli_obj = $mysqli_obj; $this->field = $field; if((isset($get['username']) && !empty($_GET['username'])) AND (isset($_GET['email']) && !empty($_GET['email'])) AND (isset($_GET['hash']) && !empty($_GET['hash']))){ $this->username = $mysqli_obj->real_escape_string($get['username']);; $this->email = $mysqli_obj->real_escape_string($get['email']); $this->hash = $mysqli_obj->real_escape_string($get['hash']); $this->action = $mysqli_obj->real_escape_string($get['action']); } } In any case, I cannot imagine this to be the source of my difficulty, as both ways appear to achieve the same end. Roddy
  2. Yes, I noticed that as well and changed the argument of the constructor function to $get and assigned $_GET to $get before the class is invoked. This is the revised version of the VeriFirm class. <?php class VeriFirm { private $mysqli_obj; private $username; private $email; private $hash; public $action = 0; private $field; private $tbl_name = 'captive_roster'; public $admin = 'admin@grammarcaptive.com'; public $subject = 'Grammar%20Captive%20-%20Verify%20and%20Confirm%20User%20Action'; public $msg_mismatch; public $msg_success; public $msg_failure; public function __construct($mysqli_obj, $get, $field) { $this->mysqli_obj = $mysqli_obj; $this->field = $field; if((isset($get['username']) && !empty($get['username'])) AND (isset($get['email']) && !empty($get['email'])) AND (isset($get['hash']) && !empty($get['hash']))){ $this->username = $mysqli_obj->real_escape_string($get['username']);; $this->email = $mysqli_obj->real_escape_string($get['email']); $this->hash = $mysqli_obj->real_escape_string($get['hash']); $this->action = $mysqli_obj->real_escape_string($get['action']); } } public function create_link() { return $mailto = "mailto:" . $this->admin . "?Subject=" . $this->subject; } public function match_data() { $sql_select = "SELECT user_name, email_address, hash, " . $this->field . " FROM " . $this->tbl_name . " WHERE user_name=? AND email_address=? AND hash=? AND " . $this->field . "=" . $this->action; $mysqli_stmt = $this->mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql_select); $mysqli_stmt->bind_param("sss", $this->username, $this->email, $this->hash); $mysqli_stmt->execute(); $mysqli_result = $mysqli_stmt->get_result(); // $match = mysqli_num_rows($mysqli_result); // if($match > 0){ if($mysqli_stmt->num_rows > 0){ $this->update_record(); } else { return $this->msg_mismatch; } } private function update_record() { if ($this->action == 0) { $sql_update = "UPDATE " . $this->tbl_name . " SET " . $this->field . "='1' WHERE user_name=? AND email_address=? AND hash=? AND ". $this->field . "=0"; $mysqli_stmt->prepare($sql_update); $mysqli_stmt->bind_param("sss", $this->username, $this->email, $this->hash); if ($mysqli_stmt->execute()) { return $this->msg_success; } else { return $this->msg_failure; } } else if ($this->action == 1) { $sql_update = "UPDATE " . $this->tbl_name . " SET " . $this->field . "='0' WHERE user_name=? AND email_address=? AND hash=? AND ". $this->field . "=1"; $mysqli_stmt->prepare($sql_update); $mysqli_stmt->bind_param("sss", $this->username, $this->email, $this->hash); if ($mysqli_stmt->execute()) { return $this->msg_success; } else { return $this->msg_failure; } } } public function get_admin_and_subject() { return $this->admin . " and " . $this->subject; } public function set_admin_and_subject($admin, $subject) { $this->admin = $admin; $this->subject = $subject; } public function get_tablename() { return $this->tbl_name; } public function set_tablename($tbl_name) { $this->tbl_name = $tbl_name; } public function get_msg_mismatch() { return $this->msg_mismatch; } public function set_msg_mismatch($msg_mismatch) { $this->msg_mismatch = $msg_mismatch; } public function get_msg_success() { return $this->msg_success; } public function set_msg_success($msg_success) { $this->msg_success = $msg_success; } public function get_msg_failure() { return $this->msg_failure; } public function set_msg_failure($msg_failure) { $this->msg_failure = $msg_failure; } } ?>
  3. If so, I will post the code that produced it. Roddy
  4. Finally, this is a copy of the script that produces the above observed results. <?php /************************************************************************ Change of Subscription Status - Trial Document ************************************************************************/ $setValue1 = ini_set('display_errors', 1); $setValue2 = ini_set('display_startup_errors', 1); error_reporting(E_ALL); $get = $_GET; $field = 'newsletter'; require_once('./_utilities/php/classes/class.lunarpages.php'); require_once('./_utilities/php/classes/class.verifirm.php'); $lunarpages = new Lunarpages(); $mysqli_obj = $lunarpages->get_mysqli_obj(); $verifirm = new VeriFirm($mysqli_obj, $get, $field); $verifirm->set_msg_mismatch("Sorry, " . $_GET['username'] . ", but no matching entry in the Grammar Captive database was found. Please try again! If the problem persists, contact the Grammar Captive <a class=" . "'link_style'" . "href='" . $verifirm->create_link() . "'" . "title='Grammar Captive Online Administrator' target='_top'>webmaster</a> and expect a prompt reply in response to your additional effort!"); $verifirm->set_msg_success("Congratulations, " . $_GET['username'] . ", your desired action was successfully processed. No further action is required on your part."); $verifirm->set_msg_failure("Sorry, " . $_GET['username'] . ", but Grammar Captive was unable to process your desired action. It appears that your account status has already been reset. If the problem persists, please contact the Grammar Captive <a class='link_style' href='" . $verifirm->create_link() . "' title='Grammar Captive Online Administrator' target='_top'>webmaster</a> and expect a prompt reply in response to your additional effort!"); echo $verifirm->match_data(); ?> Roddy
  5. I have just uploaded the relevant files and trigger page to the Grammar Captive Website in an effort to provide better insight. Click on the submit button under the form field entitled Online Change Subscription Status, and you can reproduce results identical to my own. A match should result when the action field is set to 1. If you like, you can even send yourself a copy of the newsletter. Then scroll down to where it says subscribe and unsubscribe and view the relevant links. This will be my first application of the VeriFirm class, if I can get it to work. Roddy
  6. Thank you for your reply. i tried all of your suggestions, but to no avail. The result was forever the same. No match and no error except in the first instance where your suggested change from $mysqli_stmt = $this->mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql_select); to $mysqli_stmt = $this->mysqli_obj->prepare($sql_select); results in code failure. i should state that I have used similar code in a functional rather than class context, and it worked fine. Truly, i am baffled. Roddy
  7. BACKGROUND: I have learned to keep a log that increases incrementally with the generation of each new newsletter and podcast. 1) Read the Current Log Value $file = './episode_index.txt'; if (file_exists($file)) { $json_str = file_get_contents($file); $episode_no = json_decode($json_str, true); $number = $episode_no['episode_no']; $new_episode = $number + 1; } else { echo 'The desired file either does not exist, or does not exist in the indicated location.'; } 2) Take Some Action and Update the Log Value Incrementally if (!is_blank($_POST['letter_no'])) { $episode_no['episode_no'] = $number + 1; $json_str = json_encode($episode_no); file_put_contents($file, $json_str); } in effect, I perform a simple file_get_contents and file_put_contents on a single document whose only value is that of a single JSON object whose value increases incrementally with the creation of each new newsletter. In order to keep track of my podcasts I need something vastly more complex, for not only must I be able to automatically generate a new counter with each new podcast that I generate, but each counter thus created must keep track of each and every hit of any and all podcasts by each and every known and anonymous podcast user. Further, once this data is recorded it must be easily accessible for the purpose of analysis. In effect, I am loathe to generate a separate document for each new podcast. Although a workable tool for each individual podcast, i cannot imagine it as a very effective way to manage data for all of my podcasts in aggregate or any desired subset thereof. Perhaps I could create a single MySQL table with a set number of fields for all podcasts. Then, 1) With each new podcast insert a new row of data, and 2) with each new user hit of a particular podcast update the field values for the affected row. Might I receive some input in these regards? Roddy
  8. OK. I have managed to remove all of the error messages generated by PHP. I have also checked the various stages of the mysqli_stmt object for errors. There are none. Still, I am unable to generate matches where matches should be clearly present. public function match_data() { $sql_select = "SELECT user_name, email_address, hash, " . $this->field . " FROM " . $this->tbl_name . " WHERE user_name=? AND email_address=? AND hash=? AND " . $this->field . "=" . $this->action; $mysqli_stmt = $this->mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql_select); $mysqli_stmt->bind_param("sss", $this->username, $this->email, $this->hash); $mysqli_stmt->execute(); $mysqli_result = $mysqli_stmt->get_result(); $match = mysqli_num_rows($mysqli_result); if($match > 0){ update_record(); } else { return $this->msg_mismatch; } } What is returned? For what it is worth, these are the mysqli_stmt and mysqli_result objects just prior to the match attempt. mysqli_stmt Object ( [affected_rows] => 0 [insert_id] => 0 [num_rows] => 0 [param_count] => 3 [field_count] => 4 [errno] => 0 [error] => [error_list] => Array ( ) [sqlstate] => 00000 [id] => 1 ) mysqli_result Object ( [current_field] => 0 [field_count] => 4 [lengths] => [num_rows] => 0 [type] => 0 ) Alas, woe is me. Roddy
  9. In particular, I am receiving a parse error in line 16 when the above code is run as $field = 'newsletter'; require_once('./_utilities/php/classes/class.lunarpages.php'); require_once('./_utilities/php/classes/class.verifirm.php'); $lunarpages = new Lunarpages(); $mysqli_obj = $lunarpages->get_mysqli_obj(); $verifirm = new VeriFirm($mysqli_obj, $_GET, $field); echo $verifirm->match_data(); Line 16: public $msg_mismatch = "Sorry, " . $this->username . ", but no matching entry in the Grammar Captive database was found. Please try again! If the problem persists, contact the Grammar Captive <a class='link_style' href='" . create_link() . "' title='Grammar Captive Online Administrator' target='_top'>webmaster</a> and expect a reply in response to your additional effort!";
  10. BACKGROUND: I am in the process of writing a class that will match and update rows in a MySQL data base. The field that contains the values against which a match is to be discovered must be indefinite. The values that it can contain are either 0 or 1 as defined by an ENUM field type. I know both the desired field and value before the matching routine commences. I want the UPDATE routine to set the value of the field to its opposite: 0 => 1 or 1 => 0. CURRENT STATE OF THE CODE: <?php class VeriFirm { private $mysqli_obj; private $username; private $email; private $hash; private $action = 0; private $field; private $tbl_name = 'captive_roster'; public $link = 'admin@grammarcaptive.com'; public $subject = 'Grammar%20Captive%20-%20Verify%20and%20Confirm%20User%20Action'; public $msg_mismatch = "Sorry, " . $this->username . ", but no matching entry in the Grammar Captive database was found. Please try again! If the problem persists, contact the Grammar Captive <a class='link_style' href='" . create_link() . "' title='Grammar Captive Online Administrator' target='_top'>webmaster</a> and expect a reply in response to your additional effort!"; public $msg_success = "Congratulations, " . $this->username . ", your desired action was successfully processed. No further action is required on your part."; public $msg_failure = "Sorry, " . $this->username . ", but Grammar Captive was unable to process your desired action. It appears that your account status has already been reset. If the problem persists, please contact the Grammar Captive <a class='link_style' href='" . create_link() . "' title='Grammar Captive Online Administrator' target='_top'>webmaster</a> and expect a reply in response to your additional effort!"; function __construct($mysqli_obj, $_GET, $field) { $this->mysqli_obj = $mysqli_obj; $this->field = $field; if((isset($_GET['username']) && !empty($_GET['username'])) AND (isset($_GET['email']) && !empty($_GET['email'])) AND (isset($_GET['hash']) && !empty($_GET['hash']))){ $this->$username = $mysqli_obj->real_escape_string($_GET['name']);; $this->$email = $mysqli_obj->real_escape_string($_GET['email']); $this->$hash = $mysqli_obj->real_escape_string($_GET['hash']); $this->$action = $mysqli_obj->real_escape_string($_GET['action']); } } function create_link() { return $mailto = "mailto:" . $this->link . "?Subject=" . $this->subject; } function match_data() { $sql_select = "SELECT user_name, email_address, hash, " . $this->field . " FROM " . $this->tbl_name . " WHERE user_name=? AND email_address=? AND hash=? AND " . $this->field . "=" . $this->action; $mysqli_stmt = $this->mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql_select); $mysqli_stmt->bind_param("ssss", $this->username, $this->email, $this->hash, $this->field); $mysqli_stmt->execute(); $mysqli_result = $mysqli_stmt->get_result(); $match = mysqli_num_rows($mysqli_result); if($match > 0){ update_record(); } else { return $msg_mismatch; } } function update_record() { if ($this->action == 0) { $sql_update = "UPDATE " . $this->tbl_name . " SET " . $this->field . "='1' WHERE user_name=? AND email_address=? AND hash=? AND ". $this->field . "=0"; $mysqli_stmt->prepare($sql_update); $mysqli_stmt->bind_param("sss", $this->username, $this->email, $this->hash); if ($mysqli_stmt->execute()) { return $msg_success; } else { return $msg_failure; } } else if ($this->action == 1) { $sql_update = "UPDATE " . $this->tbl_name . " SET " . $this->field . "='0' WHERE user_name=? AND email_address=? AND hash=? AND ". $this->field . "=1"; $mysqli_stmt->prepare($sql_update); $mysqli_stmt->bind_param("sss", $this->username, $this->email, $this->hash); if ($mysqli_stmt->execute()) { return $msg_success; } else { return $msg_failure; } } function get_link_and_subject() { return $this->link . ' and ' . $this->subject; } function set_link_and_subject($link, $subject) { $this->link = $link; $this->subject = $subject; } function get_tablename() { return $this->tbl_name; } function set_tablename($tbl_name) { $this->tbl_name = $tbl_name; } function get_msg_mismatch() { return $this->msg_mismatch; } function set_msg_mismatch($msg_mismatch) { $this->msg_mismatch = $msg_mismatch; } function get_msg_success() { return $this->msg_success; } function set_msg_success($msg_success) { $this->msg_success = $msg_success; } function get_msg_failure() { return $this->msg_failure; } function set_msg_failure($msg_failure) { $this->msg_failure = $msg_failure; } } ?> I am primarily concerned about the following: if((isset($_GET['username']) && !empty($_GET['username'])) AND (isset($_GET['email']) && !empty($_GET['email'])) AND (isset($_GET['hash']) && !empty($_GET['hash']))){...} Is this a proper use of the $_GET superglobal or would a $_POST or $_REQUEST superglobal be more appropriate. I am concerned about making user's private information public. This said, all communication with the Grammar Captive website is now available to TLS/SSL protocol -- namely, the https:// prefix. $sql_select = "SELECT user_name, email_address, hash, " . $this->field . " FROM " . $this->tbl_name . " WHERE user_name=? AND email_address=? AND hash=? AND " . $this->field . "=" . $this->action; Is this statement properly specified? I am concerned about the placement of the quotation marks and the ability of the mysqli_stmt object to read properly the intended SQL statement. $mysqli_stmt = $this->mysqli_obj->stmt_init(); Is this proper use of the -> operator in the construction of a PHP Class. $sql_update = "UPDATE " . $this->tbl_name . " SET " . $this->field . "='1' WHERE user_name=? AND email_address=? AND hash=? AND ". $this->field . "=0"; Is this statement properly described? Once again, my focus is on the use of quotations marks to define the statement. update_record() Is this the most efficient way to achieve the desire goal -- namely, to toggle the value of action between 0 and 1 depending on an initially assumed value of $this->field. Roddy
  11. Will the following result satisfy you? Array ( [color] => Array ( [name] => color [value] => Array ( [0] => red [1] => blue [2] => green ) ) [age] => Array ( [name] => age [value] => 16 ) ) Roddy
  12. It's OK. I have figured out a solution. I will generate the variable HTML code dynamically outside the template and then insert the result as the value of an HTML template variable that serves as a placeholder for the dynamically generated content within the template.
  13. The following SQL statement is in error $sql = "INSERT INTO users (fname, lname, uname, email, pwd, ) VALUES ('$fname', '$lname', '$uname', '$email' '$pwd')"; You have a comma after the variable name pwd that does not belong, and you left out the necessary comma between the two variable values $email and $pwd. Roddy
  14. BACKGROUND: I have an HTML template that contains a variety of template variables designated by the following pair of delimiters %varname%. In most cases there is a one-to-one correspondence between the values of a set of PHP variables gathered on a PHP processing page and the template variables found on the HTML template. The routine for populating the template variables with values is captured in the following code snippet of a very simple PHP class designed for generating templates. function replace_tags($tags) { if (sizeof($tags) > 0) { foreach ($tags as $tag => $data) { $replace = '%\%' . $tag . '\%%'; $data = (file_exists($data)) ? join("", file($data)) : $data; $this->page = preg_replace($replace, $data, $this->page); } } else { die("No tags designated for replacement."); } } The PROBLEM: My difficulty arises when I seek to populate one of the sets of template variables whose number of sets is not clearly known until the template is generated. Within the template HTML code for a single set of three variables is set aside. Ostensibly, this same set of variables could be repeated five different times, with each time carrying a different set of values. PROBLEM RESOLUTION: As each set of PHP data is numerically encoded there is no confusion about which data goes with each set. And, since the HTML code for each set of data is identical across sets it appears to be a relatively easy task to populate the template variables of the relevant set repeatedly with different data from different PHP variable sets. I imagine myself breaking the HTML code into three parts: the part that comes before the dynamically generated HTML; the part that generates the dynamic HTML code; and the part that that comes after the dynamically generated HTML. Can anyone suggest an alternative strategy? One, for example, that would simply allow me to insert the dynamically generated HTML on the fly? Roddy
  15. Please review the following code and make any suggestions that might improve it. Please understand that all functions and variables can be called and yield the proper results. class Newsletter { public $letter_no; public $mysqli_obj; public $pc_total; public $podcasts; public function __construct($letter_no, $mysqli_obj) { $this->letter_no = $letter_no; $this->mysqli_obj = $mysqli_obj; } public function get_letter() { $mysqli_obj = $this->mysqli_obj; $letter_no = $this->letter_no; $sql = "SELECT letter.*, qa.qa_question, qa.qa_answer FROM sevengates_letter AS letter JOIN sevengates_qa AS qa ON qa.letter_no = letter.letter_no WHERE letter.letter_no =?"; $mysqli_stmt = $mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql); $mysqli_stmt->bind_param('i', $letter_no); $mysqli_stmt->execute(); $meta = $mysqli_stmt->result_metadata(); while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($mysqli_stmt, 'bind_result'), $params); while ($mysqli_stmt->fetch()) { foreach($row as $key => $val) { $c[$key] = $val; } $prelim_result[] = $c; } foreach ($prelim_result as $arr) { foreach ($arr as $name => $value){ $letter_results[$name] = $value; } } return $letter_results; } public function get_nextletter() { $letter_no = $this->letter_no; $mysqli_obj = $this->mysqli_obj; $next_letter_no = $letter_no + 1; $sql = "SELECT letter_no, letter_title, letter_abstract FROM sevengates_letter WHERE letter_no = ?"; $mysqli_stmt = $mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql); $mysqli_stmt->bind_param('i', $next_letter_no); $mysqli_stmt->execute(); $meta = $mysqli_stmt->result_metadata(); while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($mysqli_stmt, 'bind_result'), $params); while ($mysqli_stmt->fetch()) { foreach($row as $key => $val) { $c[$key] = $val; } $prelim_result[] = $c; } $mysqli_stmt->free_result(); foreach ($prelim_result as $arr) { foreach ($arr as $name => $value){ $nextletter_results[$name] = $value; } } return $nextletter_results; } public function get_podcasts() { $letter_no = $this->letter_no; $mysqli_obj = $this->mysqli_obj; $sql = "SELECT podcast_ref FROM sevengates_podref WHERE letter_no = ?"; $mysqli_stmt = $mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql); $mysqli_stmt->bind_param('i', $letter_no); $mysqli_stmt->execute(); $meta = $mysqli_stmt->result_metadata(); while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($mysqli_stmt, 'bind_result'), $params); while ($mysqli_stmt->fetch()) { foreach($row as $key => $val) { $c[$key] = $val; } $prelim_result[] = $c; } $i = 1; foreach ($prelim_result as $arr) { foreach ($arr as $name => $value) { $name = $name . '_' . $i; $podcasts[$name] = $value; } $i++; } $this->pc_total = count($podcasts); return $podcasts; } public function get_podcast_data($podcasts) { $mysqli_obj = $this->mysqli_obj; $this->podcasts = $podcasts; $prelim_result = []; $c = []; $row = []; $podcast_results = []; foreach ($podcasts as $name => $value) { $params = []; $mysqli_stmt = $mysqli_obj->stmt_init(); $sql = "SELECT item_podtype, podcast_no_item, item_title, item_description, item_guid FROM rss2_podcast_item WHERE podcast_no_item = ?"; $mysqli_stmt->prepare($sql); $mysqli_stmt->bind_param('i', $value); $mysqli_stmt->execute(); $meta = $mysqli_stmt->result_metadata(); while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($mysqli_stmt, 'bind_result'), $params); while ($mysqli_stmt->fetch()) { foreach($row as $key => $val) { $c[$key] = $val; } } $prelim_result[] = $c; $mysqli_stmt->free_result(); } foreach ($prelim_result as $arr) { foreach ($arr as $name => $value){ $pc_result[$name] = $value; } $podcast_results[] = $pc_result; } return $podcast_results; } } Roddy
  16. Yes, you have understood correctly. I echo as a means to insure that I am getting what it is that i am after. Already, I have created the functions that I will convert into methods, and each has a return value corresponding to what I have echoed. Eight years have passed since I created my first PHP class, but I took very good notes. Your suggestion about the get and set methods reminded of something I had forgotten. And, your suggestion with regard to the error and connectivity code excites me, as I recently changed my password and discovered that it was a very time-consuming process to call up all the files containing connectivity code. So, once again, thank you kindly for your help. Roddy
  17. Yes, Ingolme and JSG, I have gotten the message and have figured out a way to catalogue the functions. Simply it will take more time. In effect, it is a short-term sacrifice for the long term. Unfortunately, these short-term sacrifices for the long-term are very expensive -- well, at least, for me, anyway.. in the end, I am surprised that you have not recommended that I create classes. Please find below a copy of my code, review it, and then tell me which of the approaches given below the code would be the most appropriate and why. Please understand that this code only assembles the data from the database -- little more. Your answer will likely guide me in assembling the entire package. <?php /************************************************************ Set up PHP error reporting. *************************************************************/ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); /************************************************************ Manual entry of letter number. *************************************************************/ /* $letter_no = 2; echo $letter_no; echo "<br /><span style='color:blue;'>\$param_val</span><span style='color:red;'>: The number of the newsletter that generates the retrieval of the data necessary to fill the template that becomes the newsletter.</span>"; echo '<hr>'; */ /************************************************************ The Test for a Valid $_GET Request (Automated Variable Assignment of the Number of the Current Edition) *************************************************************/ if ($_SERVER["REQUEST_METHOD"] == "GET") { if (empty($_GET['letter_no'])) { $error_msg = "Please submit an edition number for the newsletter that you desire."; } else { $letter_no = filter_var($_GET['letter_no'], FILTER_VALIDATE_INT); amass_data($letter_no); /********************************************************************************************* Close Test for the presence of a proper edition number. *********************************************************************************************/ } /********************************************************************************************* Close Test for Proper a HTTPRequest *********************************************************************************************/ } /********************************************************************************************* Create the amass_data() Funtion with Prepared SQL Statments *********************************************************************************************/ function amass_data($letter_no) { /************************************************************ Establish a connection with the database and set the character set. *************************************************************/ define('_HOST_NAME','baha.lunarbreeze.com'); define('_DATABASE_NAME','...'); define('_DATABASE_USER_NAME','...'); define('_DATABASE_PASSWORD','...'); $mysqli_obj = new MySQLi(_HOST_NAME,_DATABASE_USER_NAME,_DATABASE_PASSWORD,_DATABASE_NAME); if($mysqli_obj->connect_errno) { die("ERROR : -> ".$mysqli_obj->connect_error); } /************************************************************ Set the Character Set of Database Communication to UTF-8 *************************************************************/ if(!$mysqli_obj->set_charset("utf8")) { printf("Error loading character set utf8: %s\n", $mysqli_obj->error); exit(); } /********************************************************************************************* Select (With a Prepared Statement) the data from the Sevengates _letter and _qa data tables that corresponds to the designated letter number. *********************************************************************************************/ $sql = "SELECT letter.*, qa.qa_question, qa.qa_answer FROM sevengates_letter AS letter JOIN sevengates_qa AS qa ON qa.letter_no = letter.letter_no WHERE letter.letter_no =?"; $mysqli_stmt = $mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql); $mysqli_stmt->bind_param('i', $letter_no); $mysqli_stmt->execute(); $meta = $mysqli_stmt->result_metadata(); while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($mysqli_stmt, 'bind_result'), $params); while ($mysqli_stmt->fetch()) { foreach($row as $key => $val) { $c[$key] = $val; } $prelim_result[] = $c; } $mysqli_stmt->free_result(); //$mysqli_obj->close(); foreach ($prelim_result as $arr) { foreach ($arr as $name => $value){ echo $name . ': ' . $value . '<br />'; $letter_results[$name] = $value; } } echo "<span style='color:blue;'>\$letter_results</span><span style='color:red;'>: Selected data from the designated Seven Gates newsletter data</span>"; echo '<hr>'; /********************************************************************************************* Extract the number of the most recently posted newsletter data. *********************************************************************************************/ $letter_no = $letter_results['letter_no']; echo '$letter_results["letter_no"] = '. $letter_no; echo "<br /><span style='color:red;'>The just requested Seven Gates edition number.</span>"; echo '<hr>'; /********************************************************************************************* Next Newsletter Preview from Current Letter Edition *********************************************************************************************/ $next_letter_no = $letter_no + 1; echo '$next_letter_no' . ': ' . $next_letter_no . '<br />'; echo '$letter_results["next_title"] = '. $letter_results['next_title'] . '<br />'; echo '$letter_results["next_letter"] = '. $letter_results['next_letter'] . '<br />'; echo "<span style='color:blue;'>\$next_result</span><span style='color:red;'>: Selected preview data for next Seven Gates newsletter taken from the current letter archive.</span>"; echo '<hr>'; /********************************************************************************************* Next Newsletter Preview from Next Letter Edition *********************************************************************************************/ $result = []; $params = []; $row = []; $c = []; $prelim_result = []; $sql = "SELECT letter_title, letter_abstract FROM sevengates_letter WHERE letter_no = ?"; $mysqli_stmt = $mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql); $mysqli_stmt->bind_param('i', $next_letter_no); $mysqli_stmt->execute(); $meta = $mysqli_stmt->result_metadata(); while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($mysqli_stmt, 'bind_result'), $params); while ($mysqli_stmt->fetch()) { foreach($row as $key => $val) { $c[$key] = $val; } $prelim_result[] = $c; } $mysqli_stmt->free_result(); //Print and store preview data obtained from the next letter archive. foreach ($prelim_result as $arr) { foreach ($arr as $name => $value){ echo $name . ': ' . $value . '<br />'; $nextletter_results[$name] = $value; } } echo '<span style="color:blue;">$nextletter_results</span><span style="color:red;">: Selected preview data for next Seven Gates newsletter obtained from the next letter archive.</span>'; echo '<hr>'; /********************************************************************************************* Discover (With a Prepared Statement) the podcasts associated with the most recently posted newsletter data *********************************************************************************************/ $params = []; $prelim_result = []; $row = []; $c = []; $podcasts = []; $sql = "SELECT podcast_ref FROM sevengates_podref WHERE letter_no = ?"; $mysqli_stmt = $mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql); $mysqli_stmt->bind_param('i', $letter_no); $mysqli_stmt->execute(); $meta = $mysqli_stmt->result_metadata(); while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($mysqli_stmt, 'bind_result'), $params); while ($mysqli_stmt->fetch()) { foreach($row as $key => $val) { $c[$key] = $val; } $prelim_result[] = $c; } $mysqli_stmt->free_result(); // $mysqli_obj->close(); /********************************************************************************************* Extract the value for each referenced podcast, assign to it a unique name, and create from this unique name and associated value an array whose elements are the name-value pairs for each referenced podcast. *********************************************************************************************/ $i = 1; foreach ($prelim_result as $arr) { foreach ($arr as $name => $value) { $name = $name . '_' . $i; $podcasts[$name] = $value; } $i++; } $pc_total = count($podcasts); //Display $pc_total echo '<span style="color:blue;">$pc_total</span>: There are <span style="color:red;">' . $pc_total . '</span> podcasts associated with the Seven Gates Newsletter No. ' . $letter_no; echo '<hr>'; /********************************************************************************************* Retrieve data (With a Prepared Statement) from the named fields of the just discovered podcasts. *********************************************************************************************/ $prelim_result = []; foreach ($podcasts as $name => $value) { $params = []; $c = []; $row = []; $mysqli_stmt = $mysqli_obj->stmt_init(); $sql = "SELECT item_podtype, podcast_no_item, item_title, item_description, item_guid FROM rss2_podcast_item WHERE podcast_no_item = ?"; $mysqli_stmt->prepare($sql); $mysqli_stmt->bind_param('i', $value); $mysqli_stmt->execute(); $meta = $mysqli_stmt->result_metadata(); while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($mysqli_stmt, 'bind_result'), $params); while ($mysqli_stmt->fetch()) { foreach($row as $key => $val) { $c[$key] = $val; } } $prelim_result[] = $c; $mysqli_stmt->free_result(); } // print_r($prelim_result); $mysqli_stmt->free_result(); //$mysqli_obj->close(); foreach ($prelim_result as $arr) { foreach ($arr as $name => $value){ echo $name . ': ' . $value . '<br />'; $pc_results[$name] = $value; } echo '<br />'; } echo '<span style="color:blue;">$pc_results</span><span style="color:red;">: Data retrieved from the above named podcasts.</span>'; echo '<hr>'; /********************************************************************************************* Close the amass_data() function. *********************************************************************************************/ } ?> <?php /* require_once("/Users/kiusau/vendor/autoload.php"); $lipsum = new joshtronic\LoremIpsum(); var_dump(class_exists('joshtronic\LoremIpsum', false)); require_once("../../_utilities/php/page.php"); $start = "<!DOCTYPE html>"; $end = "</html>"; $page = new Page("./newsletter_template.php", $start, $end); $page->parse("./newsletter_template.php"); $tags = array( 'letter_no' => $result['letter_no'], 'letter_title' => $result['letter_title'], 'letter_link' => $result['letter_link'], 'letter_abstract' => $result['letter_abstract'], 'date' => $result['submission_date'], 'revision' => $result['revision_date'], ); $page->replace_tags($tags); $page->output(); */ ?> What are the advantages and disadvantages of each approach and why? Which would you recommend, if any? Leave the code as is and simply include or require it where necessary. Write the whole thing as a single class and convert the functions into methods. Write a new class for each function Roddy
  18. Please allow me to restate my question: Is the function verify_email( ) -- as written in Ingolme's snippet -- properly declared? Or, has she assumed its prior existence and not written its full declaration as a heuristic expedient?
  19. NO! Do not use the .bind( ) function, it has been deprecated. Use the more flexible .on( ) function. Great explanation! Have a great day! Roddy
  20. Can I now access that function anywhere, or is it dependent on the variable whose return value it contains?
  21. JSG: Thank you for the hesitation. I have understood your hesitance well. This is, indeed, what I am attempting to do. Simply, my idea was to do it on its own separate page. Up until this point my preference for compartmentalization has been webpages. The reason for this has been one of order. In short, each page is its own entity that can be accessed at will and neatly listed on an index page for easy reference. Accordingly, most functions that I write are written and entered on two separate pages: one in HTML with a highlighted explanation as to how the function works and what tasks it can perform, and the other written only in the language of the function that can be included anywhere at will. The organizing principle here is the same as above. You appear to be pushing me in the direction of efficiency. Efficiency with an important cost, namely, my organizational strategy that has served me so well up until now. I foresee a painful adjustment.
  22. $verified = verify_email($_POST['email'], $_POST['verification_code']); if($verified) { $vars = [ 'title' => 'Something', 'name' => 'Something' ]; $to = $_POST['email']; $subject = 'Email subject'; $body = generate_template($vars); send_an_email($to, $subject, $body); } If I have understood correctly, you are suggesting the creation of three functions generate_template() send_an_email() and then a routine that executes the generate_template() and send_an_email(), if the value of verify_email is Boolean true. What I am unclear about is the nature of the following expression verify_email($_POST['email'], $_POST['verification_code']); Is verify_email() a function, an array, or an object or some combination of these? If it is a function, is it one that I can call independently of $verified. What would I be creating exactly. Roddy
  23. INGOLME: I will need some time to figure out whether I can pull off what you are suggesting easily. Certainly I know how to write and implement a PHP function, but am known to run into problems of scope on occasion. Also, your suggestion confounds the verification process with the mailing process on the same page -- an idea that, from my most humble technological viewpoint, appears more complicated. The other connection (trigger) between my local form and remote processing page necessitates, of course, an HTTPRequest. There is no getting around this. JSG: Because the information required to send the email is produced on a different page. See above. Please read my BACKGROUND, TRIGGER, and DILEMMA notes carefully. I believe that the answer can be found there.
  24. Excuse me, but what could be simpler than generating the template and email on the same page and not caring from where the instruction comes? Roddy p.s. Just to be clear, I am referring to the email that sends the newsletter, not the verification email that calls the generator to process the template and mail the letter.
×
×
  • Create New...