mtlhd Posted November 18, 2008 Share Posted November 18, 2008 Going nutz here! NOt sure what I did wrong in this snippet of code, but it fails to query. I am only a year into being a web dev and OOP still fairly new to me. This code works up until it tries to run 'mysql_query($query)', it echoes "Query failed. Check your SQL statement." Where did I mess it up at? Thanks PHP brains! Class StripHTML { //Select description column and strip it of HTML (calls all functions) function fixDESC(){ $link = mysql_connect(***left out for obvious reasons!***); /* check connection */ if (!$link) { printf("Connect failed: %s\n", mysql_error()); exit(); } $query = "SELECT item FROM table;"; if ($result = mysql_query($query)){ $count = 0; /* fetch associative array */ while ($row = mysql_fetch_assoc($result)) { $desc = $this->strip_html_tags($row); $update = "UPDATE table SET item = '" . $desc . "' WHERE product_desc = '" . $row . "';"; mysql_query($update); $count++; } //* determine number of rows result set */ printf("<br /><br /><b>Result set has fixed %d rows.\n</b>", $count); } else { echo "<span style='color: red;'><b>Query failed. Check your SQL statement.</b></span><br />"; } if (!mysql_close($link)){ printf("Disconnect failed: %s\n", mysql_error()); } } //REMOVE HTML Function /** * Remove HTML tags, including invisible text such as style and * script code, and embedded objects. Add line breaks around * block-level tags to prevent word joining after tag removal. */ function strip_html_tags($var){ preg_replace( array( // Remove invisible content '@<head[^>]*?>.*?</head>@siu', '@<style[^>]*?>.*?</style>@siu', '@<script[^>]*?.*?</script>@siu', '@<object[^>]*?.*?</object>@siu', '@<embed[^>]*?.*?</embed>@siu', '@<applet[^>]*?.*?</applet>@siu', '@<noframes[^>]*?.*?</noframes>@siu', '@<noscript[^>]*?.*?</noscript>@siu', '@<noembed[^>]*?.*?</noembed>@siu', // Add line breaks before and after blocks '@</?((address)|(blockquote)|(center)|(del))@iu', '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu', '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu', '@</?((table)|(th)|(td)|(caption))@iu', '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu', '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu', '@</?((frameset)|(frame)|(iframe))@iu', ), array( ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", ), $var); return strip_tags($var); } //end class } Quote Link to comment https://forums.phpfreaks.com/topic/133215-custom-class-query-within-function-not-workingplease-help/ Share on other sites More sharing options...
premiso Posted November 18, 2008 Share Posted November 18, 2008 I think it would be better to output the actual error. I think the issue is the ; in the SQL but not sure. I seem to remember issues with that. Change this: } else { echo "<span style='color: red;'><b>Query failed. Check your SQL statement.</b></span><br />"; } to } else { echo "<span style='color: red;'><b>Query failed. Check your SQL statement.<br />" . $query . " <br />MySQL Error: " . mysql_error() . "</b></span><br />"; } At least in development that will help you immensely to find the issue. Quote Link to comment https://forums.phpfreaks.com/topic/133215-custom-class-query-within-function-not-workingplease-help/#findComment-692842 Share on other sites More sharing options...
mtlhd Posted November 19, 2008 Author Share Posted November 19, 2008 Hey! Good call! It reported to me that I hadn't selected a Database like a smart guy! Thanks man! Gonna try and fix that issue today and will report fixed code today. Quote Link to comment https://forums.phpfreaks.com/topic/133215-custom-class-query-within-function-not-workingplease-help/#findComment-693442 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.