nero1009 Posted December 14, 2007 Share Posted December 14, 2007 hi guys im new too using classes and objects to program stuff i made a little bit of code but i keep getting weird errors what exactly am i doing wrong This is for a search page <html> <head></head> <title>Search Comments </title> <body><h1 style="color: #444; margin: 10px 0px;"> Search Comments</h1> <form action="search_comments.php" method="get" name="search"> <input name="q" type="text" value="<?php echo $query; ?>"> <input name= "search_comments.php" type="submit" value="Search "> </form> </div> </div> </body> </html> <?php //connect to the database require '/Library/WebServer/Documents/sitesadmin/comments_dev/functions/sqlF.php'; connect_comments(); require '/Library/WebServer/Documents/sitesadmin/comments_dev/includes/config.php'; config(1); require PATH.'functions/commentF.php'; require PATH.'classes/asset.php'; require PATH.'functions/dateF.php'; // results to display per page $limit = 10; // Get the search variable from URL $var = @$_POST['q'] ; //trim whitespace from the stored variable $trimmed = trim($var); //string and display a message. if ($trimmed == "") { $resultmsg = "<p>Search Error</p> <p>Please enter a search...</p>" ; } echo "<p>Please enter a search...</p>"; if (!isset($var)){ $resultmsg = "<p>Search Error</p> <p>We don't seem to have a search parameter! </p>" ; } // table and field names for the SQL query $query = mysql_query("SELECT * FROM tblcommentsall WHERE comment_text = LIKE '%$trimmed%''") or die("Couldn't execute query"); $numresults = mysql_query($query); // no results if ($numresults == 0){ echo "<h4>Results</h4>"; echo "<p>Sorry, your search: " . $trimmed . " returned zero results</p>"; } // determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query = " LIMIT $s,$limit"; $result = @mysql_fetch_array($query); // display what the person searched for echo "<p>You searched for: " . $var . "</p>"; // begin to show results echo "Results"; $result = 1 + $s ; ?> So when I run this code i can not connect for query is this the wrong way to do this please help Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted December 14, 2007 Share Posted December 14, 2007 not even gonna look plz edit and put your post inbetween tags! Im sorry but its hard to read when its not color coord Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted December 14, 2007 Share Posted December 14, 2007 i moved this as it has no use of classes/objects and isn't OOP. Please get yourself acquainted with the boards and pick a suitable place before posting. also - if you get errors, please post them as you see them and we'll probably be able to help better. Quote Link to comment Share on other sites More sharing options...
CMC Posted December 14, 2007 Share Posted December 14, 2007 $numresults = mysql_query($query); should be $numresults = mysql_num_rows($query); Try that. Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 Still wont allow me to connect to database ? thanks for the help Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2007 Share Posted December 17, 2007 I don't see where you connect to the database. Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 <?php //connect to the database require '/Library/WebServer/Documents/sitesadmin/comments_dev/functions/sqlF.php'; connect_comments(); require '/Library/WebServer/Documents/sitesadmin/comments_dev/includes/config.php'; config(1); require PATH.'functions/commentF.php'; require PATH.'classes/asset.php'; require PATH.'functions/dateF.php';; query for the search Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 // table and field names for the SQL query $query = mysql_query("SELECT * FROM tblcommentsall WHERE comment_text = LIKE '%$trimmed%''") or die("Couldn't execute query"); This is where the error start Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2007 Share Posted December 17, 2007 Can you post the relevent code? Nowhere in what you have posted do you make a connection. You might also change your code to... $query = mysql_query("SELECT * FROM tblcommentsall WHERE comment_text = LIKE '%$trimmed%''") or die(mysql_error()); so we get an actual error message. Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2007 Share Posted December 17, 2007 Actualy, I see your error. You have an extra ' in your query. "SELECT * FROM tblcommentsall WHERE comment_text = LIKE '%$trimmed%'" Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 I appericate the help still didnt work Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 17, 2007 Share Posted December 17, 2007 You need mysql_connect('localhost', 'user', 'password'); mysql_select_db('db_name'); somewhere before the mysql queries, so you then have actually connected to the database; unless the connection details are within '/Library/WebServer/Documents/sitesadmin/comments_dev/functions/sqlF.php'? Also, in $query = mysql_query("SELECT * FROM tblcommentsall WHERE comment_text = LIKE '%$trimmed%''") or die(mysql_error()); why do you have an extra ' in your query - that extra apostraphe would probably cause errors. (As thorpe just said, he beat me to it). Sam Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 <?php //connect to the database require '/Library/WebServer/Documents/sitesadmin/comments_dev/functions/sqlF.php'; connect_comments(); require '/Library/WebServer/Documents/sitesadmin/comments_dev/includes/config.php'; config(1); require PATH.'functions/commentF.php'; require PATH.'classes/asset.php'; require PATH.'functions/dateF.php';; // results to display per page $limit = 10; // Get the search variable from URL $var = @$_POST['q'] ; //trim whitespace from the stored variable $trimmed = trim($var); //string and display a message. if ($trimmed == "") { $resultmsg = "<p>Search Error</p> <p>Please enter a search...</p>" ; } echo "<p>Please enter a search...</p>"; if (!isset($var)){ $resultmsg = "<p>Search Error</p> <p>We don't seem to have a search parameter! </p>" ; } // table and field names for the SQL query $query = mysql_query("SELECT * FROM tblcommentsall WHERE comment_text = LIKE '%$trimmed%'") or die("Couldn't execute query"); $numresults = mysql_num_rows($query); // no results if ($numresults == 0){ echo "<h4>Results</h4>"; echo "<p>Sorry, your search: " . $trimmed . " returned zero results</p>"; } // determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query = " LIMIT $s,$limit"; $result = @mysql_fetch_array($query); // display what the person searched for echo "<p>You searched for: " . $var . "</p>"; // begin to show results echo "$Results"; $result = 1 + $s ; ?> Quote Link to comment Share on other sites More sharing options...
Grego Posted December 17, 2007 Share Posted December 17, 2007 Can you show us what's in '/Library/WebServer/Documents/sitesadmin/comments_dev/functions/sqlF.php'? Obviously, remove any usernames and passwords Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 Can you show us what's in '/Library/WebServer/Documents/sitesadmin/comments_dev/functions/sqlF.php'? Obviously, remove any usernames and passwords remove _dev from comments Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 in the url of the browser you are using Quote Link to comment Share on other sites More sharing options...
Grego Posted December 17, 2007 Share Posted December 17, 2007 in the url of the browser you are using You mean copaste it there? Doesn't work. Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 basically i am allow user to search the comments about the articles in this section of the web Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 17, 2007 Share Posted December 17, 2007 Nero, the URL won't work because /Library.... goes on the end of your site name. Like www.mysite.com/Library/WebServer... etc.. so if we don't have your site URL we can't look at it, and since it's PHP we can't see the code anyway. But surely you knew that. Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2007 Share Posted December 17, 2007 I suggest before you learn php you learn how to form a question. You need to help us help you. Theres a good link in my signiture. Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 sorry Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 17, 2007 Share Posted December 17, 2007 sorry no need to apologise, really. When you try to connect to the database, what does it actually say/what error do you get? Sam Quote Link to comment Share on other sites More sharing options...
nero1009 Posted December 17, 2007 Author Share Posted December 17, 2007 I would like to thank everyone that has help me with this i have finally made it work I need the LIMIT var; in the query for database now I need to make more search options any sugestions for the query 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.