HowdeeDoodee Posted May 17, 2010 Share Posted May 17, 2010 I am trying to teach myself how to use Full Text. I copied a simple script from a teaching site (lol) and cannot get the script to display any records. Can someone tell me where the error is in the script. Thank you in advance for your replies. <?php /* call this script "this.php" */ if ($c != 1) { ?> echo "input box starts here"; <form action="this.php?c=1"> <input type="text" name="keyword"> <input type="submit" value="Search!"> </form> <?php } else if ($c==1) { $username = "____"; $password = "_____"; $hostname = "localhost"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $dbname = "findthep_DBProj"; mysql_select_db($dbname, $dbh); $sql = "SELECT * FROM `View2_B` WHERE MATCH (Topic, Subtopic, Theswords) AGAINST ('$keyword') ORDER BY score DESC"; $res = MySQL_query($sql); ?> <table> <tr><td>SCORE</td><td>TITLE</td><td>ID#</td></tr> <?php while($row = MySQL_fetch_array($res)) { echo "<tr><td>{$sql['score']}</td>"; echo "<td>{$sql['Topic']}</td>"; echo "<td>{$sql['Subtopic']}</td>"; echo "<td>{$sql['Theswords']}</td>"; echo "<td>{$sql['id']}</td></tr>"; } echo "</table>"; } ?> </body> Quote Link to comment https://forums.phpfreaks.com/topic/202027-cannot-get-simple-script-to-display/ Share on other sites More sharing options...
scvinodkumar Posted May 17, 2010 Share Posted May 17, 2010 I think this code will produce an error while executing the query, so try like this $res = mysql_query($sql) or die(mysql_error()); and try to use php functions in small letters instead of caps, like mysql_query instead of MySQL_query Quote Link to comment https://forums.phpfreaks.com/topic/202027-cannot-get-simple-script-to-display/#findComment-1059419 Share on other sites More sharing options...
HowdeeDoodee Posted May 17, 2010 Author Share Posted May 17, 2010 Thank you for the reply. I tried your suggestions but still get no display of records in the db. Quote Link to comment https://forums.phpfreaks.com/topic/202027-cannot-get-simple-script-to-display/#findComment-1059434 Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2010 Share Posted May 17, 2010 Because there are always multiple things in programming that can prevent code from working on any particular server, to get the quickest help without a lot of guessing, you must communicate exactly what you see in front of you when you submit the form. There are two apparent problems. 1) The code is way out of date and relies on a php.ini setting that was turned off by default over 8 years ago (most of the code you will find posted on the Internet is crap and is just there to get revenue from people clicking on links on the site) and 2) The form never worked because it does not have a method="..." attribute and the default in that case is GET and since the URL in the action="..." attribute also is using GET for the c value, the ?c=1 value will never be submitted. If you change the start of the code up through the <form tag to the following, it should work - <?php $c = isset($_GET['c']) ? (int)$_GET['c'] : 0; $keyword = isset($_POST['keyword']) ? $_POST['keyword'] : ''; /* call this script "this.php" */ if ($c != 1) { ?> echo "input box starts here"; <form action="this.php?c=1" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/202027-cannot-get-simple-script-to-display/#findComment-1059466 Share on other sites More sharing options...
HowdeeDoodee Posted May 17, 2010 Author Share Posted May 17, 2010 Thank you for the reply. I pasted your changes into the script without any changes but I still get no records showing. Is there any way to run a test to see where the problem might be? Quote Link to comment https://forums.phpfreaks.com/topic/202027-cannot-get-simple-script-to-display/#findComment-1059491 Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2010 Share Posted May 17, 2010 Actually, the code worked for me with the modifications (attempted to execute the query against my database.) Are you doing this on a server with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that all the errors php detects will be reported and displayed? Stop and start your web server to get any change made to the master php.ini to take effect and confirm that the setting actually changed by using a phpinfo() statement in case the php.ini that you changed is not the one that php is using. Quote Link to comment https://forums.phpfreaks.com/topic/202027-cannot-get-simple-script-to-display/#findComment-1059508 Share on other sites More sharing options...
BizLab Posted May 17, 2010 Share Posted May 17, 2010 Your echo'ed table looks a little sketchy this while($row = MySQL_fetch_array($res)) { echo "<tr><td>{$sql['score']}</td>"; echo "<td>{$sql['Topic']}</td>"; echo "<td>{$sql['Subtopic']}</td>"; echo "<td>{$sql['Theswords']}</td>"; echo "<td>{$sql['id']}</td></tr>"; } echo "</table>"; should look more like this: while($row=mysqli_fetch_array($res)){ echo '<td>'.$row['score'].'</td>'; } you have to display the $row[''] data you assigned the mysql query results to hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/202027-cannot-get-simple-script-to-display/#findComment-1059514 Share on other sites More sharing options...
HowdeeDoodee Posted May 17, 2010 Author Share Posted May 17, 2010 OK, I have deeply regressed. Error reporting is 135 Display errors is ON I am now getting... Parse error: syntax error, unexpected $end in /home6/findthep/public_html/CP/this.php on line 43 When I run the following script. <html> <head> <title>Sans Titre</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="generator" content="HAPedit 3.1"> </head> <body bgcolor="#FFFFFF"> <?php //phpinfo() ; $c = isset($_GET['c']) ? (int)$_GET['c'] : 0; $keyword = isset($_POST['keyword']) ? $_POST['keyword'] : ''; /* call this script "this.php" */ if ($c != 1) { ?> <form action="this.php?c=1"> <input type="text" name="keyword"> <input type="submit" value="Search!"> </form> <?php } else if ($c==1) { $username = "findthep"; $password = "DiannaK[1952]"; $hostname = "localhost"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $dbname = "findthep_DBProj"; mysql_select_db($dbname, $dbh); $sql = "select * from `View2_BibleFT` where match (Topic, Subtopic, Theswords) against ('$keyword')"; //$res = MySQL_query($sql); $res = mysql_query($sql) or die(mysql_error); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/202027-cannot-get-simple-script-to-display/#findComment-1059545 Share on other sites More sharing options...
scampbell Posted May 17, 2010 Share Posted May 17, 2010 You are missing an end bracket } for this line } else if ($c==1) { Quote Link to comment https://forums.phpfreaks.com/topic/202027-cannot-get-simple-script-to-display/#findComment-1059555 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.