Jump to content

Cannot Get Simple Script To Display


HowdeeDoodee

Recommended Posts

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>


Link to comment
Share on other sites

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">

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.