By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,620 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,620 IT Pros & Developers. It's quick & easy.

register and login email process looping indefinitely

P: 11
I'm really new to the whole networking side of things, so I don't know the backend very well. I wrote a series of PHP/AJAX scripts to allow a user to create a login account, but apparently my script is doing much much more than I imagined as I received an email from my admin this morning:

Your script located at .....Scripts/form_check.php has been moved to your account root. This script generated over 7000 emails that bounced back and forth on our server for an hour, which drive the load on this machine to inappropriate levels. Every time this script runs, it also core dumps on the server:

-rw------- 1 squeez7 squeez7 24M Mar 3 21:47 core.14811
-rw------- 1 squeez7 squeez7 24M Mar 3 21:51 core.15255
I think a core dump means my program had a fatal error, and I know my program is supposed to email me when there is an error. Granted, I was debugging the script last night, but I had no idea this was going on! Especially as my mailing code is the same code I have used before without issue.

I'm scared to run this code again even to test it, but I've been over it a million times, and I still have no clue what is causing this.

I would really appreciate any help!!!

List of scripts:
  • ajax.js
  • form_check.php
  • UsrDB.php
  • BasicDB.php

Here are my scripts:

ajax.js
Expand|Select|Wrap|Line Numbers
  1. /**********************************
  2.     Filename:    ajax.js
  3.     Date:            02.25.08
  4. **********************************/
  5.  
  6. /***** CREATE XMLHTTP OBJECT *****/
  7. function request() {
  8.     var browser = navigator.appName;        // get browser
  9.     var req = false;
  10.     if(browser == "Microsoft Internet Explorer") {    // IE
  11.         try {
  12.             req = new ActiveXObject("Msm12.XMLHTTP");        // -- Msm12
  13.         } catch(err1) {
  14.             try {
  15.                 req = new ActiveXObject("Microsoft.XMLHTTP");    // -- Microsoft
  16.             } catch(err2) {
  17.                 req = false;        // FAIL!
  18.             }
  19.         }
  20.     } else {
  21.         try {
  22.             req = new XMLHttpRequest();    // not IE
  23.         } catch(err) {
  24.             req = false;
  25.         }
  26.     }
  27.  
  28.     return req;
  29. }
  30.  
  31. var http = request();        // CREATE XMLHTTP object
  32.  
  33. var obj;                            // other variables
  34. var obj2;
  35. var url;
  36.  
  37. /***** SEND AJAX REQUEST *******/
  38. function send_post(params,use) {
  39.     http.open("POST", url, true);
  40.     http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  41.     http.setRequestHeader("Content-length", params.length);
  42.     http.setRequestHeader("Connection", "close");
  43.     http.onreadystatechange = eval(use);
  44.     http.send(params);
  45. }
  46.  
  47. /********************************************************************************
  48. ***** USE FUNCTIONS *************************************************************
  49. ********************************************************************************/
  50.  
  51. /***** FORM *****/
  52. function form_response() {
  53.     var vobj = "v"+obj;
  54.     if(http.readyState == 4) {
  55.         if(http.status == 200) {
  56.             var data = http.responseText.split(",");
  57.             if(data[0] == 2) {        // no data -- do nothing
  58.             } else if(data[0] == 0) {    // good data -- show check
  59.                 document.getElementById(vobj).innerHTML = "<img class=\"form_img\" src=\"../images/yes.png\"/>";
  60.             } else {        // bad data -- show x and response
  61.                 document.getElementById(vobj).innerHTML = data[1]+" <img class=\"form_img\" src=\"../images/no.png\"/>";
  62.             }
  63.         } else {
  64.             document.getElementById(vobj).innerHTML = "No server response.";
  65.             //document.getElementsByName(obj)[0].className = "maybe";
  66.         }
  67.     } else {
  68.         document.getElementById(vobj).innerHTML = 'Checking...';
  69.         //document.getElementsByName(obj)[0].className = "maybe";
  70.     }
  71. }
  72.  
  73. /***** REGISTER *****/
  74. function register_response() {
  75.     obj = 'message';    // set div id
  76.     var msg = '';
  77.     if(http.readyState == 4) {
  78.         if(http.status == 200) {
  79.             var data = http.responseText;
  80.             document.getElementById(obj).innerHTML = data;
  81.         } else {
  82.             document.getElementById(obj).innerHTML = "Unable to complete request.";
  83.         }
  84.     } else {
  85.         document.getElementById(obj).innerHTML = "Working";
  86.     }
  87. }
  88.  
  89.  
  90. /********************************************************************************
  91. ***** CHECK FUNCTIONS ***********************************************************
  92. ********************************************************************************/
  93.  
  94. /* EMAIL */
  95. function check_email() {
  96.     url = "../Scripts/form_check.php";
  97.     obj = "email";
  98.     if(document.getElementsByName(obj)[0].value != '') {
  99.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  100.         send_post(params,"form_response"); }
  101. }
  102.  
  103. /* USR */ 
  104. function check_usr() {
  105.     url = "../Scripts/form_check.php";
  106.     obj = "usr";
  107.     if(document.getElementsByName(obj)[0].value != '') {
  108.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  109.         send_post(params,"form_response"); }
  110. }
  111.  
  112. /* FIRST */
  113. function check_first() {
  114.     url = "../Scripts/form_check.php";
  115.     obj = "first";
  116.     if(document.getElementsByName(obj)[0].value != '') {
  117.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  118.         send_post(params,"form_response"); }
  119. }
  120.  
  121. /* LAST */
  122. function check_last() {
  123.     url = "../Scripts/form_check.php";
  124.     obj = "last";
  125.     if(document.getElementsByName(obj)[0].value != '') {
  126.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  127.         send_post(params,"form_response"); }
  128. }
  129.  
  130. /* PASSWORD */
  131. function check_password() {
  132.     url = "../Scripts/form_check.php";
  133.     obj = "password";
  134.     if(document.getElementsByName(obj)[0].value != '') {
  135.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  136.         send_post(params,"form_response"); }
  137. }
  138. function check_confirm() {
  139.     url = "../Scripts/form_check.php";
  140.     obj = "confirm";
  141.     obj2 = "password";
  142.     if(document.getElementsByName(obj)[0].value != '') {
  143.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value+
  144.             "&data2="+document.getElementsByName(obj2)[0].value;
  145.         send_post(params,"form_response"); }
  146. }
  147.  
  148. /* REGISTER */
  149. function register() {
  150.     url = "../Scripts/register.php";
  151.  
  152.     if(document.getElementsByName('usr')[0].value != 0 &&
  153.             document.getElementsByName('email')[0].value != 0 &&
  154.             document.getElementsByName('first')[0].value != 0 &&
  155.             document.getElementsByName('last')[0].value != 0) {
  156.         params = "usr="+document.getElementsByName('usr')[0].value+
  157.             "&email="+document.getElementsByName('email')[0].value+
  158.             "&first="+document.getElementsByName('first')[0].value+
  159.             "&last="+document.getElementsByName('last')[0].value;
  160.         send_post(params,"register_response");
  161.     }
  162. }
  163.  
  164. /* LOGIN */
  165. function login() {
  166.     url = "../Scripts/login.php";
  167.  
  168.     if(document.getElementsByName('name')[0].value != 0 &&
  169.         document.getElementsByName('password')[0].value != 0) {
  170.         params = "name="+document.getElementsByName('name')[0].value+
  171.             "&password="+document.getElementsByName('password')[0].value;
  172.  
  173.         send_post(params,"register_response");
  174.     }
  175. }
  176.  

form_check.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. /**********************************
  4.     Filename:    form_check.php
  5.     Date:            02.25.08
  6. **********************************/
  7.  
  8. require_once("../Classes/Sys.php");
  9. require_once("../Classes/Usr.php");
  10. require_once("../Classes/UsrDB.php");
  11.  
  12. session_start();
  13. header("Cache-control: private"); 
  14.  
  15. $db = new UsrDB($_SESSION['sys'],$_SESSION['usr']);
  16.  
  17. $return = "1,Invalid data";
  18.  
  19. if($_POST['data'] == '') {
  20.     echo "2,No data";
  21. }
  22.  
  23. switch($_POST['object']) {
  24.     case "usr":
  25.         if($db->verify_usr($_POST['data'])) {
  26.             $return = "1,Existing user name"; }
  27.         else {
  28.             $return = "0,Available user name"; }
  29.         break;
  30.     case "email":
  31.         $find = "/[\w\d\_\-\.]*\@[\w\d\_\-\.]*\.(com|edu|gov|net|co)/";
  32.         if(!preg_match($find,$_POST['data'])) {
  33.             $return = "1,Invalid email"; }
  34.         else {
  35.             if($db->verify_email($_POST['data'])) {
  36.                 $return = "1,Existing email"; }
  37.             else {
  38.                 $return = "0,Available email"; }
  39.         }
  40.         break;
  41.     case "first":
  42.     case "last":
  43.         $find = "/[^a-zA-Z]/";
  44.         if(preg_match($find,$_POST['data'])) {
  45.             $return = "1,Invalid string"; }
  46.         else {
  47.             $return = "0,Valid string"; }
  48.         break;
  49.     case "password":
  50.         $find = "/\s/";
  51.         if(preg_match($find,$_POST['data'])) {
  52.             $return = "1,Invalid password"; }
  53.         else {
  54.             $return = "0,Valid password"; }
  55.         break;
  56.     case "confirm":
  57.         if($_POST['data'] == $_POST['data2']) {
  58.             $return = "0,Passwords match"; }
  59.         else {
  60.             $return = "1,Passwords don't match"; }
  61.         break;
  62.     default:
  63.         break;
  64. }
  65.  
  66. echo $return;
  67.  
  68. ?>
  69.  
I'll have to put the last two files in the following post.
Mar 4 '08 #1
Share this Question
Share on Google+
5 Replies


P: 11
Here's UsrDB.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. /**********************************
  4.     Filename:    UsrDB.php
  5.     Date:            02.25.08
  6. **********************************/
  7.  
  8. require_once('BasicDB.php');    
  9.  
  10. class UsrDB extends BasicDB {    
  11.  
  12. /* CLASS VARIABLES */
  13.     protected $group;    // denotes project & permissions set
  14.     private $system;    // instance of the system class
  15.     private $user;    // instance of the user class
  16.     private $webmaster;    // email to send error messages to
  17.     private $date;    // date
  18.     private $day;    // day
  19.     private $time;    // time
  20.  
  21. /* PUBLIC FUNCTIONS */
  22.  
  23. /*********************************************************************** 
  24. ***** CONSTRUCTOR & DESTRUCTOR ***************************************** 
  25. ***********************************************************************/
  26.  
  27. /*********************************************************************** 
  28. Constructor
  29.         input: instance of the system and user classes
  30.         output: none */
  31.     public function __construct($sys,$usr) {    
  32.         $this->system    = $sys;    // System class
  33.         $this->user        = $usr;    // Usr class
  34.         $this->group     = $this->system->group();    // GET system group
  35.         $this->day        = date("Y:m:d");    
  36.         $this->time        = date("H:i:s");    
  37.         $this->date        = $day."::".$time;    
  38.         $this->webmaster = "webmaster@------.com";    
  39.     }     // END Constructor
  40.  
  41. public function __destruct() {    }    
  42.  
  43.  
  44. /*********************************************************************** 
  45. ***** ERROR HANDLING FUNCTIONS ***************************************** 
  46. ***********************************************************************/
  47.  
  48. /*********************************************************************** 
  49. Write_log($m)
  50.         input: instruction (Error,LogIN,LogOUT,etc.), and message
  51.         output: TRUE / FALSE
  52.         */
  53.     public function write_log($instruction,&$msg) {    
  54.         /* LOG MESSAGE QUERY */
  55.         $query = sprintf("INSERT INTO log (ses_id, log_date, log_time, log_msg, log_instruction)
  56.             VALUES ( '%s', '%s', '%s', '%s', '%s' )",                    // CREATE mysql query
  57.                 $this->system->id(),
  58.                 $this->day,
  59.                 $this->time,
  60.                 $msg,
  61.                 $instruction);    
  62.         if(!$this->insert($query)) {    // IF our query has errors
  63.             $to    = $this->webmaster;    
  64.             $subj    = "[".$this->group."] Error";    
  65.             $msg = "Function: write_log\n".
  66.                 "Problem: Unable to write to database\n".
  67.                 "Date: ".$this->date."\n".
  68.                 "User: ".$this->user->name();    
  69.             $from    = "From: ".$this->webmaster;    
  70.             mail($to,$subj,$msg,$from);    //    --NOTIFY the webmaster
  71.             return false;    //    --RETURN FALSE
  72.         }    
  73.  
  74.         return true;    // RETURN true
  75.     }     // END log_err
  76.  
  77.  
  78. /*********************************************************************** 
  79. ***** USRDB METHODS **************************************************** 
  80. ***********************************************************************/
  81.  
  82. /***login removed for space */
  83.  
  84. /*********************************************************************** 
  85. logout()
  86.         input: none
  87.         output: none
  88.         result: */
  89.     public function logout() {    
  90.         $this->system->__destruct();    // KILL system instance
  91.         unset($this->system);    // UNSET system instance
  92.         $this->write_log("Log","OUT ".$this->user->name());    // LOG log out
  93.     }     // END logout
  94.  
  95. /*********************************************************************** 
  96. register()
  97.         input: array of user name, first & last name, and email
  98.         output: true if success, false if fail */
  99.     public function register($input_array) {    
  100.         $usr         = $this->mysql_safe($input_array['usr']);    // SECURE user input
  101.         $first    = $this->mysql_safe($input_array['first']);    
  102.         $last        = $this->mysql_safe($input_array['last']);    
  103.         $email    = $this->mysql_safe($input_array['email']);    
  104.         $msg        = '';    
  105.         $row;    
  106.  
  107.         $query = sprintf("INSERT INTO usr (usr_name,usr_fname,usr_lname,usr_email)
  108.             VALUES (%s,%s,%s,%s)",                    // QUERY add user
  109.                 $usr,
  110.                 $first,
  111.                 $last,
  112.                 $email);    
  113.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  114.  
  115.         $query = sprintf("SELECT usr_id FROM usr WHERE usr_name = %s",$usr);    // QUERY get user id
  116.         if(!($row = $this->select($query))) {     return false;     }    // RUN query, FALSE if bad
  117.         $id = $row['usr_id'];    // SAVE user id
  118.  
  119.         $password = $this->random_password();    // CREATE random password
  120.         $query = sprintf("INSERT INTO pswd (p_pswd,usr_id) VALUES ('%s',%d)",    // QUERY add encrypted password
  121.                 sha1($password),
  122.                 $id);    
  123.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  124.  
  125.         $query = sprintf("INSERT INTO usr_grp (usr_id,usrg_grp,usrg_rank) ".    // QUERY insert user into group
  126.                     "VALUES (%d,'%s',%d)",
  127.                 $id,
  128.                 $this->group,
  129.                 1);    
  130.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  131.  
  132.         $query = sprintf("INSERT INTO usr_meta (usr_id) VALUES (%d)",    // QUERY add user row in meta table
  133.             $id);    
  134.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  135.  
  136.         $this->welcome($email,$usr,$password);    // SEND welcome email with password
  137.         $this->write_log("Register",$usr);    // LOG register
  138.  
  139.         return true;    
  140.     }     // END register
  141.  
  142. /*********************************************************************** 
  143. session()
  144.         input: none
  145.         output: TRUE / FALSE */
  146.     public function session() {    
  147.         if(!$this->system->verify_id() || !$this->system->verify_ip()) {    // IF we still have the same creds
  148.             $this->logout();    //    --LOGOUT
  149.             return false;    }    //    --RETURN false
  150.  
  151.         // Add session to database
  152.         $query = sprintf("INSERT INTO session (usr_id,ses_grp,ses_ip,ses_addr,ses_php,ses_date,ses_time)
  153.             VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s' )",    // QUERY add session data
  154.                 $this->user->id(),
  155.                 $this->group,
  156.                 $this->system->ip(),
  157.                 $this->system->addr(),
  158.                 $this->system->id(),
  159.                 $this->day,
  160.                 $this->time);    
  161.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  162.         return true;    // RETURN true
  163.     }     // END session
  164.  
  165. /*********************************************************************** 
  166. welcome
  167.         input: email, user name, password
  168.         output: welcome email and password email  */
  169.     public function welcome($email,$usr,$password) {    
  170.         $to    = $email;    
  171.         $subj = "Welcome to ".$this->group;    
  172.         $from    = "From: ".$this->webmaster;    
  173.         $msg    = "
  174.             Dear $usr,
  175.     ***nice message here ***    
  176.  
  177.             ";    
  178.         mail($to,$subj,$msg,$from);    // SEND welcome email
  179.         mail($to,$subj,$password,$from);    // SEND password email
  180.         return true;    // RETURN true
  181.     }    // END welcome
  182.  
  183.  
  184. /*********************************************************************** 
  185. ***** VERIFY FUNCTIONS ************************************************* 
  186. ***********************************************************************/
  187.  
  188. /*********************************************************************** 
  189. verify_email
  190.         input: email
  191.         output: true | false */
  192.     public function verify_email($email) {    
  193.         $email = $this->mysql_safe($email);    // SECURE user input
  194.         $query = sprintf("SELECT usr_id FROM usr WHERE usr_email = %s",    // QUERY check if email is in database
  195.                     $email);    
  196.         if(!($row = $this->select($query))) {     return false;     }    // RUN query, FALSE if not
  197.         else {     return true;     }    // TRUE if it is
  198.     }    
  199.  
  200. /*********************************************************************** 
  201. verify_usr
  202.         input: user name
  203.         output: true | false   */
  204.     public function verify_usr($usr) {    
  205.         $usr = $this->mysql_safe($usr);    // SECURE user input
  206.         $query = sprintf("SELECT usr_id FROM usr WHERE usr_name = %s",    // QUERY check if user name is in database
  207.                     $usr);    
  208.         if(!($row = $this->select($query))) {     return false;     }    // RUN query, FALSE if not
  209.         else {     return true;     }    // TRUE if it is
  210.     }    
  211.  
  212. /*********************************************************************** 
  213. ***** UPDATE FUNCTIONS ************************************************* 
  214. ***********************************************************************/
  215.  
  216. // removed for space
  217.  
  218. /*********************************************************************** 
  219. ***** GET FUNCTIONS **************************************************** 
  220. ***********************************************************************/
  221.  
  222. /*********************************************************************** 
  223. get_list()
  224.         input: desired attribute, minimum rank (opt)
  225.         output: array of user names */
  226.     public function get_user_list() {     return $this->get_list("usr_name");     }    // ALIAS for get_list USER
  227.     public function get_email_list() {     return $this->get_list("usr_email");     }    // ALIAS for get_list EMAIL
  228.     public function get_list() {    
  229.         $val = func_get_arg(0);    // SAVE desired attribute
  230.         if(func_num_args() == 2) {    // IF more input
  231.             $min_rank = func_get_arg(1);     }    //    --SAVE desired rank
  232.         else {     $min_rank = 1;     }    // ELSE get all ranks
  233.         $query = sprintf("SELECT %s FROM usr WHERE usr_rank >= %d",    // QUERY get all rows
  234.                     $val,
  235.                     $min_rank);    
  236.         if(!($list = $this->select_simple_list($query))) {     return false;     }    // SAVE rows as a array, FALSE on fail
  237.         return $list;    // RETURN array
  238.     }     // END get_list
  239.  
  240. /*********************************************************************** 
  241. random_password()
  242.         input: none
  243.         output: password generated */
  244.     public function random_password() {    
  245.                                     // CREATE character arrays
  246.         $letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');    
  247.         $numbers = array('1','2','3','4','5','6','7','8','9','0');    
  248.         $symbols = array('!','@','#','$','%','^','&','*','(',')','<','>','.','?','/',':','{    ','}    ',',','.',';    ','|','+','=','~');    
  249.         $length     = 10;    
  250.         $password = '';    
  251.  
  252.         for($i = 0;     $i <= $length;     $i++) {    // LOOP for given length
  253.             $set = mt_rand(0,2);    // CHOOSE which array to use
  254.             if($set == 0) {    // IF letters
  255.                 $char = mt_rand(1,count($letters));    //    --GENERATE a random value
  256.                 $char--;    // --DECREMENT (to fit in array index)
  257.                 $password .= $letters[$char];    // --ADD to password
  258.             }     else if($set == 1) {    // IF numbers
  259.                 $char = mt_rand(1,count($numbers));    //    --see above
  260.                 $char--;    
  261.                 $password .= $numbers[$char];    
  262.             }     else if($set == 2) {    // IF symbols
  263.                 $char = mt_rand(1,count($symbols));    // -- see above
  264.                 $char--;    
  265.                 $password .= $symbols[$char];    
  266.             }     else {    }    
  267.         }    
  268.  
  269.         return $password;    // RETURN password
  270.     }     // END random_password
  271.  
  272. }     // END CLASS
  273.  
  274. ?>
  275.  
Mar 4 '08 #2

P: 11
BasicDB.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. /**********************************
  4.     Filename:    BasicDB.php
  5.     Date:            02.25.08
  6. **********************************/
  7.  
  8. class BasicDB {    
  9.  
  10. /* CLASS VARIABLES */
  11.     private $date;    // Date in Y:m:d::H:i:s form
  12.     private $day;    // Day in Y:m:d form
  13.     private $system;    // instance of the system class
  14.     private $time;    // Time in H:i:s form
  15.     private $webmaster;    // Email to send error notifications to
  16.  
  17. /* CLASS FUNCTIONS */
  18.  
  19. /*********************************************************************** 
  20. ***** CONSTRUCTOR & DESTRUCTOR ***************************************** 
  21. ***********************************************************************/
  22.  
  23. /*********************************************************************** 
  24. Constructor
  25.         input: instance of the system class
  26.         output: none */
  27.     public function __construct($sys) {    
  28.         $this->day        = date("Y:m:d");    
  29.         $this->time        = date("H:i:s");    
  30.         $this->date        = $day."::".$time;    
  31.         $this->system    = $sys;    
  32.         $this->webmaster = "webmaster@-------.com";    
  33.     }     // END Constructor
  34.  
  35. /*********************************************************************** 
  36. ***** ERROR HANDLING FUNCTIONS ***************************************** 
  37. ***********************************************************************/
  38.  
  39. /*********************************************************************** 
  40. $this->err($msg)
  41.         input: error message
  42.         output:    email to the webmaster 
  43.                     write to log                     */
  44.     public function err($msg) {    
  45.         $to    = $this->webmaster;    // assign To:
  46.         $subj    = "[".$this->group."] Error";    // assign Subject:
  47.         $msg .= "\n".$this->date;    // assign Message:
  48.         $from    = "From: ".$this->webmaster;    // assign From:
  49.         mail($to,$subj,$msg,$from);    // send mail
  50.         $this->write_log("Error",$msg);    // log error
  51.     }     // END $this->err()
  52.  
  53. /*********************************************************************** 
  54. ***** MYSQL FUNCTIONS ************************************************** 
  55. ***********************************************************************/
  56.  
  57. /*********************************************************************** 
  58. DB_connect()
  59.         input: none
  60.         output: link resource */
  61.     public function db_connect() {    
  62.  
  63.         /* Squeeze of Lime server info*/
  64.         $server = "----------";    
  65.         $usr = '----------';    
  66.         $pswd = '----------';    
  67.         $db = '----------';    
  68.  
  69.         // opening db connection
  70.         $link = mysql_connect($server,$usr,$pswd);    // OPEN mysql connection
  71.         if(!$link) {    // IF no connection 
  72.             $this->err("db_connect(): Unable to connect to db.");    //    --REPORT error
  73.             return false;    //    --RETURN false
  74.         }     else {     }    // ELSE continue
  75.  
  76.         $dbselect = mysql_select_db($db, $link);    // SELECT database
  77.         if(!$dbselect) {    // IF no selection
  78.             $this->err("db_connect(): Unable to select db.");    //    --REPORT error
  79.             return false;    //    --RETURN false
  80.         }     else {     }    // ELSE continue
  81.  
  82.         return $link;    // RETURN link resource
  83.     }     // END db_connect()
  84.  
  85.  
  86. /*********************************************************************** 
  87. insert
  88.         input: mysql query string (insert, delete, or update)
  89.         output: query result (false on fail, true on success)     */
  90.     public function insert($query) {    
  91.         return $this->result($query,1,0);    // CALL result function
  92.     }    
  93.  
  94. /*********************************************************************** 
  95. select
  96.         input: mysql query string (select)
  97.         output: query result (false on fail, single result on success)  */
  98.     public function select($query) {    
  99.         return $this->result($query,0,0);    // CALL result function
  100.     }     // END select
  101.  
  102. /*********************************************************************** 
  103. select_simple_list
  104.         input: mysql query string (select)
  105.         output: query result (false on fail, array of single field on success) */
  106.     public function select_simple_list($query) {    
  107.         return $this->result($query,0,1);    // CALL result function
  108.     }     // END select_simple_list
  109.  
  110. /*********************************************************************** 
  111. result
  112.         input: mysql query string, boolean, boolean
  113.         output: */
  114.     public function result($query,$insert,$list) {    
  115.         $count = 0;    // RESET count
  116.         $link = $this->db_connect();    // GET a database link
  117.         $data;    // INITIALIZE variable
  118.  
  119.         if(!$link) {    // IF we still don't connect
  120.             $msg = "Function: check_result\n".    //    --CREATE error message
  121.                 "Problem: ".mysql_error()."\n".
  122.                 "Date: ".$this->date."\n";    
  123.             $this->err($msg);    //    --REPORT error
  124.             $this->logout();    //    --LOGOUT
  125.             return false;     }    //    --RETURN FALSE
  126.  
  127.         $count = 0;    // RESET count
  128.         $result = mysql_query($query,$link);    // QUERY database
  129.         if(!$result) {    // IF no result,
  130.             $msg = "Function: check_result\n".    //    --CREATE error message
  131.                 "Problem: ".mysql_error()."\n".
  132.                 "Date: ".$this->date."\n".
  133.                 "Query: $query";    
  134.             $this->err($msg);    //    --REPORT error
  135.             $this->logout();    //    --LOGOUT
  136.             return false;     }    //    --RETURN FALSE
  137.  
  138.         if($insert) {    // IF an insert type query
  139.             if(mysql_affected_rows() == 0) {    //    --CHECK for affected rows
  140.                 return false;     }    //    --NONE? return false
  141.             $data = true;    //    --OTHERWISE return true
  142.         }     else {    // ELSE a select type query
  143.             if(mysql_num_rows($result) == 0) {    //    --CHECK for number of rows
  144.                 return false;     }    //    --NONE? return false
  145.             else if($list) {    //    --ELSE IF we want a list
  146.                 while($row = mysql_fetch_row($result)) {    //    --LOOP through the rows returned
  147.                     $data[] = $row[0];     }    //    --SAVE first value in array
  148.             }     else {    //    --ELSE we want a single value
  149.                 $data = mysql_fetch_assoc($result);    //    --SAVE the query result
  150.             }    
  151.             mysql_free_result($result);    // FREE the result
  152.         }    
  153.  
  154.         mysql_close($link);    // CLOSE database link
  155.         return $data;    // RETURN our query data (if good result)
  156.     }    
  157.  
  158.  
  159. /*********************************************************************** 
  160. ***** SAFE FUNCTIONS *************************************************** 
  161. ***********************************************************************/
  162.  
  163. /*********************************************************************** 
  164. Mysql_safe($val)
  165.         input: a string
  166.         output: a safe, mysql 'executable' version of the string, in quotes
  167.         note: (adapted from php.net) */
  168.     public function mysql_safe($value) {    
  169.         $link = $this->db_connect();    // GET a database link
  170.         if (get_magic_quotes_gpc()) {     $value = stripslashes($value);     }    // IF gmqg is turned on, USE it
  171.         if (!is_numeric($value)) {    // IF its not a number
  172.             $value = "\"" . mysql_real_escape_string($value,$link) . "\"";     }    //    --ESCAPE and put in quotes
  173.         return $value;    //    --RETURN our safe string
  174.     }     // END mysql_safe
  175.  
  176. /*********************************************************************** 
  177. Mysql_safe_nq($val)
  178.         input: a string
  179.         output: a safe, mysql 'executable' version of the string, W/O quotes
  180.         note: (adapted from php.net) */
  181.     public function mysql_safe_nq($value) {    
  182.         $link = $this->db_connect();    // GET a database link
  183.         if (get_magic_quotes_gpc()) {     $value = stripslashes($value);     }    // IF gmqg is turned on, USE it
  184.         if (!is_numeric($value)) {    // IF its not a number
  185.             $value = mysql_real_escape_string($value,$link);     }    //    --ESCAPE the string
  186.         return $value;    //    --RETURN our safe string
  187.     }     // END mysql_safe
  188.  
  189. }     // END CLASS
  190.  
  191. ?>
  192.  
Mar 4 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
I don't think you developed this package yourself, otherwise you would have some clue as to where the problem lies or could even be pinpointed.

In my opinion you downloaded this package from one of the many sites like ringsworld who provide free scripts.

Ronald
Mar 4 '08 #4

P: 11
Actually, I wrote the whole thing. This is the second version -- the first being a PHP4 version, but I now added in AJAX and the updated OOP handling in PHP (which is still not very good).

I don't know where the problem is because I don't know what would cause a core dump. And since I'm not getting the emails designed to help me debug the system, I have no idea where I'm going wrong.

What I don't understand is that I haven't really changed the emailing system (the err function in BasicDB), so I should be getting emails -- but neither my emails nor my registration emails are coming through. I did change hosts since the last working version, but I wouldn't expect that to effect why the emails are causing server issues instead of being sent out. Again, I really just don't know what is going on behind the scense. I have been all over this code, debugging it through messages returned in javascript alerts at one point =) (for the errors returned from the ajax-called php).

I am the programmer for this code, though -- I wrote every line and commented it all. The problem is I fear to test it anymore lest my admin suspend my account, I have no idea what causes a core dump, and I can't get to my debugging messages.

I would really appreciate some help if anyone has a chance.


Attached are the four files. For easier use, I deleted most of the tabs that aligned the comments (as is seen in the code pasted above). If anyone wants them, I have the files with the comments aligned on the right with tab=4 in Notepad2.
Attached Files
File Type: txt ajax.txt (5.4 KB, 242 views)
File Type: txt form_check.txt (1.5 KB, 235 views)
File Type: txt BasicDB.txt (7.1 KB, 225 views)
File Type: txt UsrDB.txt (18.5 KB, 254 views)
Mar 4 '08 #5

P: 11
Actually, I wrote the whole thing. This is the second version -- the first being a PHP4 version, but I now added in AJAX and the updated OOP handling in PHP (which is still not very good).

I don't know where the problem is because I don't know what would cause a core dump. And since I'm not getting the emails designed to help me debug the system, I have no idea where I'm going wrong.

What I don't understand is that I haven't really changed the emailing system (the err function in BasicDB), so I should be getting emails -- but neither my emails nor my registration emails are coming through. I did change hosts since the last working version, but I wouldn't expect that to effect why the emails are causing server issues instead of being sent out. Again, I really just don't know what is going on behind the scense. I have been all over this code, debugging it through messages returned in javascript alerts at one point =) (for the errors returned from the ajax-called php).

I am the programmer for this code, though -- I wrote every line and commented it all. The problem is I fear to test it anymore lest my admin suspend my account, I have no idea what causes a core dump, and I can't get to my debugging messages.

I would really appreciate some help if anyone has a chance.


Attached are the four files. For easier use, I deleted most of the tabs that aligned the comments (as is seen in the code pasted above). If anyone wants them, I have the files with the comments aligned on the right with tab=4 in Notepad2.
I didn't see what happens to the obj after it is used - is it or could it be destroyed
or moved?
Mar 5 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.