Jump to content

petersro

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

petersro's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thanks man works, but can i instead of an echo, have just a varable, like $error, then build a html layout and have echo $error to save me writing out the table for each condition
  2. i have an confusing problem here is the code sys_error <?php /** * @author * @copyright 2008 */ if(isset($_GET['error=conn_error'])): echo "Im sorry the system could not connect to the database server"; elseif(isset($_GET['error=conn_error'])): echo "Im sorry there is a problem with the database"; else: echo "An unknown error has occured"; endif; ?> sys_mysql.php <?php /** * @author * @copyright 2008 */ //System loading what we need require ('sys_config.php'); //Starting Connections $conn = mysql_connect($db_host,$db_user,$db_pass); if(!$conn) { header("Location:sys_error.php?error=conn_error"); } $db = mysql_select_db(db_name,$conn); if(!$db) { header("Location:sys_error.php?error=db_error"); } ?> the result is an unknown error occured i know for a fact that the password i have placed for de-bugging purposes is wrong, so it should result in cant connect to db server
  3. thanks man works a treat, however (i have been very suscessfull with customising the php error log) but it doesnt work, is there a simple way to when an arror is triggered, write it to a log file?
  4. thanks mate working on introducing it in my code, i have another question, would make things more cleaner, is there a way i can when $db = mysql_select_db(db_name,$conn) or trigger_error(E_USER_ERROR); trigger_error(E_USER_ERROR) is reached, Is there a way to if there is a problem throw a custom error, secondly is there a way to get it to re-direct on error to say error.php on the root of the site, displaying the echo of whats wrong, in a clean html layout. im guessing the first is possable with a varable, but i dont know how to do the second part.
  5. i tried the \r\n, it works on the logfile, but doesnt work on the php site, it still displays as normal Logfile output ---- PHP Error ---- Number: [2] String: [mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'root'@'localhost' (using password: YES)] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [8] String: [use of undefined constant db_name - assumed 'db_name'] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [2] String: [mysql_select_db(): supplied argument is not a valid MySQL-Link resource] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] Website display ---- PHP Error ---- Number: [2] String: [mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES)] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [12] ---- PHP Error ---- Number: [8] String: [use of undefined constant db_name - assumed 'db_name'] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [2] String: [mysql_select_db(): supplied argument is not a valid MySQL-Link resource] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13] ---- PHP Error ---- Number: [1024] String: [256] File: [C:\wamp\www\onepro\system\sys_mysql.php] Line: [13]
  6. While working on the error handler i have an issue with it working but not putting things on a new line, any hints? // set the error reporting level for this script error_reporting(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE); // Change defaults ini_set('display_errors', 'Off'); ini_set('log_errors', 'On'); // set to the user defined error handler set_error_handler("custom_err_handler"); // The path to the error log file define('ERROR_LOG_PATH', './logs/error_log.txt'); // Our custom error handler function function custom_err_handler($num, $str, $file, $line) { global $error_log_path; $err = ""; $err .= "---- PHP Error ----\n"; $err .= "Number: [" . $num . "]\n"; $err .= "String: [" . $str . "]\n"; $err .= "File: [" . $file . "]\n"; $err .= "Line: [" . $line . "]\n\n"; error_log($err, 3, ERROR_LOG_PATH); echo $err; }
  7. after researching, i have attempted to nock together a mysql class <?php /** * @author Rohan Peters * @copyright 2008 */ //Loading what we need require ('sys_config.php'); require ('sys_error.php'); //Loading master function function database($db_host, $db_user, $db_pass, $db_db){ $this->server=$db_host; $this->user=$db_user; $this->pass=$db_pass; $this->database=$db_db; } //Connecting function function connect() { $this->link_id=@mysql_connect($this->server,$this->user,$this->pass); if (!$this->link_id) {//open failed $this->oops("Could not connect to server: <b>$this->server</b>."); } if(!@mysql_select_db($this->database, $this->link_id)) {//no database $this->oops("Could not open database: <b>$this->database</b>."); } //Unloading for security $this->server=''; $this->user=''; $this->pass=''; $this->database=''; } //Disconnecting function function close() { if(!mysql_close()){ $this->oops("Connection close failed."); } } //Query Function function query($sql) { $this->query_id = @mysql_query($sql, $this->link_id); if (!$this->query_id) { $this->oops("<b>MySQL Query fail:</b> $sql"); } $this->affected_rows = @mysql_affected_rows(); return $this->query_id; } //Fetching Function - Single function fetch_array($query_id=-1) { if ($query_id!=-1) { $this->query_id=$query_id; } if (isset($this->query_id)) { $this->record = @mysql_fetch_assoc($this->query_id); }else{ $this->oops("Invalid query_id: <b>$this->query_id</b>. Records could not be fetched."); } if($this->record){ $this->record=array_map("stripslashes", $this->record); } return $this->record; } //Fetching Function - All function fetch_all_array($sql) { $query_id = $this->query($sql); $out = array(); while ($row = $this->fetch_array($query_id, $sql)){ $out[] = $row; } $this->free_result($query_id); return $out; } //Freeing results up function free_result($query_id=-1) { if ($query_id!=-1) { $this->query_id=$query_id; } if(!@mysql_free_result($this->query_id)) { $this->oops("Result ID: <b>$this->query_id</b> could not be freed."); } } //Single row shot and free function query_first($query_string) { $query_id = $this->query($query_string); $out = $this->fetch_array($query_id); $this->free_result($query_id); return $out; } //Update function function query_update($table, $data, $where='1') { $q="UPDATE `".$this->pre.$table."` SET "; foreach($data as $key=>$val) { if(strtolower($val)=='null') $q.= "`$key` = NULL, "; elseif(strtolower($val)=='now()') $q.= "`$key` = NOW(), "; else $q.= "`$key`='".$this->escape($val)."', "; } $q = rtrim($q, ', ') . ' WHERE '.$where.';'; return $this->query($q); } //Insert Function function query_insert($table, $data) { $q="INSERT INTO `".$this->pre.$table."` "; $v=''; $n=''; foreach($data as $key=>$val) { $n.="`$key`, "; if(strtolower($val)=='null') $v.="NULL, "; elseif(strtolower($val)=='now()') $v.="NOW(), "; else $v.= "'".$this->escape($val)."', "; } $q .= "(". rtrim($n, ', ') .") VALUES (". rtrim($v, ', ') .");"; if($this->query($q)){ //$this->free_result(); return mysql_insert_id(); } else return false; } ?> it just displays the code
  8. After my origional post and finding out that i understand how OOP works, but not how to use it properly, i was wondering if you guys could help me and most likely other users out with a basic MySQL CRUD and an example on how to use it, im not after anything fancy, just the basics, to learn by demonstration, thanks
  9. IMO, the layout and color scheme, is well, interesting (to put it nicely), if this site is as you say your only line of income, try and make it welcoming, it honnestly hurt my eyes when it loaded, my suggestion, go back to the drawing bord with layout and color.
  10. aye sorry my bad, just a quick question why have 2 error statements, just rope it all into one else wrong info so like, if this, else if that, else die wrong info
  11. line 34 and line 38, if im not mistaken, they will error out as they dont flow,
  12. Greetings, I viewed your site on my rig, using firefox 3 @ a screen of 1440*900, and i agree with the others the flash doesnt work for you. however, its not a bad job. A coupple of technical details, the drop down lists need to be configured correctly, i had to guess wich drop down list to select to get the others to work, a Please select country and so on, would not go a miss, i suggest a re-think on the layout, and delivery medium, plus a possable mashup with google maps, to show where said business is. Good Luck!
  13. thanks again, picking over smarty helped a great deal, i have through my quest come up against anew roadblock, i have skimmed through the forum, but havent found a complete answer, i can do basic CRUD with normal php, but with OOP, i have had some interesting issues, This is my current function_mysql.php <?php //Finding web root $dr=($_SERVER['DOCUMENT_ROOT']); //Loading system config require ($dr . 'config.php'); //System connection public function connect() { if(!$this->con) { $sys_connect = @mysql_connect($this->$db_host,$this->$db_user,$this->$db_pass); if($sys_connect) { $select_db = @mysql_select_db($this->db_name,$sys_connect); if($select_db) { $this->con = true; return true; } else { return false; } } else { return false; } } else { return true; } } //System disconnect public function disconnect() { if($this->con) { if(@mysql_close()) { $this->con = false; return true; } else { return false; } } } //System tables load private $result = array(); private function tableExists($table) { $system_tables = @mysql_query('SHOW TABLES FROM '.$this->$db_name.' LIKE "'.$table.'"'); if($system_tables) { if(mysql_num_rows($system_tables)==1) { return true; } else { return false; } } } //System select public function select($table, $rows = '*', $where = null, $order = null) { $q = 'SELECT '.$rows.' FROM '.$table; if($where != null) $q .= ' WHERE '.$where; if($order != null) $q .= ' ORDER BY '.$order; if($this->tableExists($table)) { $query = @mysql_query($q); if($query) { $this->numResults = mysql_num_rows($query); for($i = 0; $i < $this->numResults; $i++) { $r = mysql_fetch_array($query); $key = array_keys($r); for($x = 0; $x < count($key); $x++) { // Sanitizes keys so only alphavalues are allowed if(!is_int($key[$x])) { if(mysql_num_rows($query) > 1) $this->result[$i][$key[$x]] = $r[$key[$x]]; else if(mysql_num_rows($query) < 1) $this->result = null; else $this->result[$key[$x]] = $r[$key[$x]]; } } } return true; } else { return false; } } else return false; } //System insert public function insert($table,$values,$rows = null) { if($this->tableExists($table)) { $insert = 'INSERT INTO '.$table; if($rows != null) { $insert .= ' ('.$rows.')'; } for($i = 0; $i < count($values); $i++) { if(is_string($values[$i])) $values[$i] = '"'.$values[$i].'"'; } $values = implode(',',$values); $insert .= ' VALUES ('.$values.')'; $ins = @mysql_query($insert); if($ins) { return true; } else { return false; } } } //System delete public function delete($table,$where = null) { if($this->tableExists($table)) { if($where == null) { $delete = 'DELETE '.$table; } else { $delete = 'DELETE FROM '.$table.' WHERE '.$where; } $del = @mysql_query($delete); if($del) { return true; } else { return false; } } else { return false; } } //System update logic for($i = 0; $i < count($where); $i++) { if($i%2 != 0) { if(is_string($where[$i])) { if(($i+1) != null) $where[$i] = '"'.$where[$i].'" AND '; else $where[$i] = '"'.$where[$i].'"'; } else { if(($i+1) != null) $where[$i] = $where[$i]. ' AND '; else $where[$i] = $where[$i]; } } } $keys = array_keys($rows); for($i = 0; $i < count($rows); $i++) { if(is_string($rows[$keys[$i]])) { $update .= $keys[$i].'="'.$rows[$keys[$i]].'"'; } else { $update .= $keys[$i].'='.$rows[$keys[$i]]; } // Parse to add commas if($i != count($rows)-1) { $update .= ','; } } //system update public function update($table,$rows,$where) { if($this->tableExists($table)) { // Parse the where values // even values (including 0) contain the where rows // odd values contain the clauses for the row for($i = 0; $i < count($where); $i++) { if($i%2 != 0) { if(is_string($where[$i])) { if(($i+1) != null) $where[$i] = '"'.$where[$i].'" AND '; else $where[$i] = '"'.$where[$i].'"'; } } } $where = implode('=',$where); $update = 'UPDATE '.$table.' SET '; $keys = array_keys($rows); for($i = 0; $i < count($rows); $i++) { if(is_string($rows[$keys[$i]])) { $update .= $keys[$i].'="'.$rows[$keys[$i]].'"'; } else { $update .= $keys[$i].'='.$rows[$keys[$i]]; } // Parse to add commas if($i != count($rows)-1) { $update .= ','; } } $update .= ' WHERE '.$where; $query = @mysql_query($update); if($query) { return true; } else { return false; } } else { return false; } } ?> This is the config.php <?php $db_host = localhost $db_user = root $db_pass = ****** $db_db = test ?> This is a test to see if it works <?php; //Finding web root $dr=($_SERVER['DOCUMENT_ROOT']); //Loading what we need require ($dr . '/system/functions_mysql.php'); $res = $db->getResult(); print($res); ?> this is the output in the web browser getResult(); print($res); ?>
×
×
  • Create New...

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.