steelmanronald06 Posted March 14, 2007 Share Posted March 14, 2007 Right, so I'm new to O.O.P but I've been doing a fair job of it. So, what I have is the following: lib/classes.php <?php class ErrorReporting { // Define some variables var $page; var $error_msg; function databaseInsert() { $page = $this->page; $error_msg = $this->error_msg; if (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } else { $ip = $_SERVER['REMOTE_ADDR']; } $errorMsgQuery = mysql_query("INSERT INTO errors (date, page, ip, error_msg) VALUES (now(), '$page', '$ip', '$error_msg')"); } } ?> lib/functions.php <?php function queryErrorCheck($query) { // // Error checks queries // global $db; global $path; $report = new ErrorReporting; $errorMsg = $db->ErrorMsg(); $report->page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}"; $report->error_msg = "The following error: ' $errorMsg ' was recieved on the query: $query "; $report->databaseInsert(); echo ' <img src="' , $path , 'includes/img/error.jpg" alt="Error" /> <p>We are sorry, but an unexpected error has occured. Please try your request again. If the problem continues, the administrators will be notified and the problem will be addressed. If you have had a loss of money, items, or your stats are no longer correct because of this error, please contact an administrator and we will investigate our logs and refresh your stats to the last correct settings.</p> '; } ?> access/market.php <?php $itemStockQuery = $db->GetAll("SELECT * FROM items WHERE item_id=$item' AND stock > '0' LIMIT 1"); // Error check if (!$itemStockQuery) { queryErrorCheck($itemStockQuery); daFooter(); exit(); }; ?> Right, so all the files are included properly, everything is going good. The function echos out the error to the page and everything. The only problem is the class isn't inserting the error into the database. If I run the class by itself, outside the function, then it works, so there is nothing wrong with the query. It has to be the function. I just don't see what. Any ideas??? Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted March 14, 2007 Share Posted March 14, 2007 just because i'm picky, and seem to remember a similar issue, try replacing: $report = new ErrorReporting; with $report = new ErrorReporting(); Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted March 14, 2007 Author Share Posted March 14, 2007 Sorry, no dice. :-( Quote Link to comment Share on other sites More sharing options...
effigy Posted March 14, 2007 Share Posted March 14, 2007 Are you connected to the database? mysql_query is not being checked for success. Quote Link to comment Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 <?php class ErrorReporting { // Define some variables var $page; var $error_msg; function databaseInsert() { $page = $this->page; $error_msg = $this->error_msg; if (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } else { $ip = $_SERVER['REMOTE_ADDR']; } return mysql_query("INSERT INTO errors (date, page, ip, error_msg) VALUES (now(), '$page', '$ip', '$error_msg')"); } } ?> <?php function queryErrorCheck($query) { // // Error checks queries // global $db; global $path; $report = new ErrorReporting; $errorMsg = $db->ErrorMsg(); $report->page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}"; $report->error_msg = "The following error: ' $errorMsg ' was recieved on the query: $query "; if (!$report->databaseInsert()) { die("MySQL Encountered a fatal error:" . mysql_error()); } echo ' <img src="' , $path , 'includes/img/error.jpg" alt="Error" /> <p>We are sorry, but an unexpected error has occured. Please try your request again. If the problem continues, the administrators will be notified and the problem will be addressed. If you have had a loss of money, items, or your stats are no longer correct because of this error, please contact an administrator and we will investigate our logs and refresh your stats to the last correct settings.</p> '; } ?> Try that see where it gets you. If I was a betting man I would say it is in the "date" column, maybe try to surround that in ` ` or rename it. --FrosT Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted March 14, 2007 Author Share Posted March 14, 2007 updated code throws this: MySQL Encountered a fatal error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'You have an error in your SQL syntax; check the manual that corresponds to your ' at line 1 Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted March 14, 2007 Share Posted March 14, 2007 As the previous poster suggested, I would try: INSERT INTO `errors` (`date`, `page`, `ip`, `error_msg`) VALUES (now(), '$page', '$ip', '$error_msg') Best, Patrick Quote Link to comment Share on other sites More sharing options...
trq Posted March 14, 2007 Share Posted March 14, 2007 date is a reserved word in SQL, you need to surround it with backticks if you want to use it as a field name. Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted March 14, 2007 Author Share Posted March 14, 2007 Put the backticks and i still get this: MySQL Encountered a fatal error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'You have an error in your SQL syntax; check the manual that corresponds to your ' at line 1 Quote Link to comment Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 Try renaming the date column to dates or something like that and see if it still craps out. Whoa, that error you are getting, it looks like you are trying to run a the query "You have an error in your SQL syntax;" That is weird dude, I have never in my life seen that before....lol Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted March 15, 2007 Share Posted March 15, 2007 Could you echo your SQL like: <?php //... $sql = "INSERT INTO `errors` (`date`, `page`, `ip`, `error_msg`) VALUES (now(), '$page', '$ip', '$error_msg')"; echo $sql; return mysql_query($sql); //... ?> I'm guessing that there might be an apostrophe in the $error_msg variable such that you're trying to run something like this: INSERT INTO errors (date, page, ip, error_msg) VALUES (2007-03-14 00:00:00, 'foo.php', '127.0.0.1', 'you've entered something invalid')") Quote Link to comment Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 Ah utexas_pjm is right, try this $sql = "INSERT INTO `errors` (`date`, `page`, `ip`, `error_msg`) VALUES (now(), '$page', '$ip', '".mysql_real_escape_string($error_msg)."')"; Use that mysql_real_escape_string(); see if that helps. Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted March 15, 2007 Author Share Posted March 15, 2007 Jolly Good! That solved that. Now then, this here: "The following error: ' $errorMsg ' was recieved on the query: $query "; It inserts everything correctly, except the $query. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted March 15, 2007 Share Posted March 15, 2007 looking at it closely, $query is not the actual query once it reaches that point. look here: $itemStockQuery = $db->GetAll("SELECT * FROM items WHERE item_id=$item' AND stock > '0' LIMIT 1"); // Error check if (!$itemStockQuery) { queryErrorCheck($itemStockQuery); unless you're doing things differently, $itemStockQuery looks like it contains the RESULTS of a query, not the query itself. try replacing above with: $query = "SELECT * FROM items WHERE item_id=$item' AND stock > '0' LIMIT 1"; $itemStockQuery = $db->GetAll($query); // Error check if (!$itemStockQuery) { queryErrorCheck($query); hope that helps! cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.