problem getting search script to work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonathan184
    New Member
    • Nov 2006
    • 154

    problem getting search script to work

    Hi I tried getting this to work through dreamweaver but it did not.
    So i found a n example on the internet , i followed everything exactly the search script does not work. Could somebody help me this please.
    Thanks for your help in advance. The form and script are on the same page.

    [PHP]<?php require_once('. ./Connections/rs_ais.php'); ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>search </title>

    <link href="../css/ais.css" rel="stylesheet " type="text/css" />

    </head>

    <body>
    <table width="100%" border="0">
    <?php include("../template/header.php"); ?>
    <?php include("../template/leftnav.php"); ?>

    <td colspan="2" valign="top"><p ><strong><br />
    </strong>Search Cases</p>
    <form name="search" method="post" action="<?=$PHP _SELF?>">
    Search for:
    <input name="find" type="text" class="aisteam" />
    in
    <select name="field" class="aisteam" >
    <option value="issue_ti tle">Issue Title</option>
    <option value="case_num ber">Case Number</option>
    <option value="issue_de scription">Issu e description</option>
    <option value="customer _acct">Customer Account</option>
    <option value="status"> Status</option>
    <option value="priority ">Priority</option>
    <option value="issue_da te">Issue Date</option>
    <option value="opened_b y">Opened By</option>
    <option value="assigned _to">Assigned</option>
    <option value="issue_ty pe">Issue Type</option>
    </select>

    <input type="hidden" name="searching " value="yes" />
    <input name="search" type="submit" class="aisteam" value="Search" />
    </form>


    <p>&nbsp;</p>


    <table width="95%" border="0" cellspacing="1" cellpadding="1" >


    <tr>
    <th scope="col">Sta tus</th>
    <th scope="col">Iss ue Title </th>
    <th scope="col">Cus tomer Account </th>
    <th scope="col">Pri ortiy</th>
    <th scope="col">Iss ue Type </th>
    <th scope="col">Cre ated Date </th>
    </tr>
    <tr class="aisteam" >

    <?php
    //This is only displayed if they have submitted the form
    if ($searching =="yes")
    {
    echo "<h3>Result s</h3><p>";

    //If they did not enter a search term we give them an error
    if ($find == "")
    {
    echo "<p>Please enter a search term";
    exit;
    }

    // Otherwise we connect to our Database
    #mysql_connect( "mysql.yourhost .com", "user_name" , "password") or die(mysql_error ());
    mysql_select_db ("aisteam") or die(mysql_error ());

    // We preform a bit of filtering
    $find = strtoupper($fin d);
    $find = strip_tags($fin d);
    $find = trim ($find);

    //Now we search for our search term, in the field the user specified
    $data = mysql_query("SE LECT * FROM issue_tracker WHERE $field LIKE'%$find%'") ;

    //And we display the results
    while($result = mysql_fetch_arr ay( $data ))
    {
    /* <td><?php echo $result['status']; ?></td>
    <td><?php echo $result['issue_title']; ?></td>
    <td><?php echo $result['customer_acct']; ?></td>
    <td><?php echo $result['priority']; ?></td>
    <td><?php echo $result['issue_type']; ?></td>
    <td><?php echo $result['created_date']; ?></td>
    </tr>*/
    echo "<td>";
    echo $result['status'];
    echo "</td>";
    echo "<td>";
    echo $result['issue_title'];
    echo "</td>";
    echo "<td>";
    echo $result['customer_acct'];
    echo "</td>";
    echo "<td>";
    echo $result['priority'];
    echo "</td>";
    echo "<td>";
    echo $result['issue_type'];
    echo "</td>";
    echo "<td>";
    echo $result['created_date'];
    echo "</td>";
    echo "</tr>";

    }

    //This counts the number or results - and if there wasn't any it gives them a little message explaining that
    $anymatches=mys ql_num_rows($da ta);
    if ($anymatches == 0)
    {
    echo "Sorry, but we can not find an entry to match your query<br><br>";
    }

    //And we remind them what they searched for
    echo "<b>Searche d For:</b> " .$find;
    }
    echo "</table>"
    ?>



    <?php include("../template/footer.php");
    ?>
    [/PHP]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Jonathan.

    What do you want your code to do? Give an example.
    What is your code doing that you don't want it to do? Give an example.
    What is your code *not* doing that it is supposed to? Give an example.

    Comment

    • jonathan184
      New Member
      • Nov 2006
      • 154

      #3
      Ok I want to give back results from a search.

      Search wil be like this
      textfield dropdownmenu

      now the text filed will be where i type something to search and the

      dropdown menu will be the column of the database i want to search in.

      So i want to type customer name and choose from the dropdownmenu customer account and click submit and basically it should return results with all records with custmername in that column.



      Originally posted by pbmods
      Heya, Jonathan.

      What do you want your code to do? Give an example.
      What is your code doing that you don't want it to do? Give an example.
      What is your code *not* doing that it is supposed to? Give an example.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Jonathan.

        What is your code doing that you don't want it to do? Give an example.
        What is your code *not* doing that it is supposed to? Give an example.

        Comment

        • jonathan184
          New Member
          • Nov 2006
          • 154

          #5
          its giving no results.

          There are no errors.



          Originally posted by pbmods
          Heya, Jonathan.

          What is your code doing that you don't want it to do? Give an example.
          What is your code *not* doing that it is supposed to? Give an example.

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Jonathan.

            Alrightey. If it gives no results, then there are two possibilities:
            1. There are no rows in `issue_tracker` where `$field` like '%$find%'.
            2. (more likely) The query is generating an error.


            Try changing line 81 to:
            [code=php]
            $sql = "SELECT * FROM issue_tracker WHERE $field LIKE'%$find%'";
            $data = mysql_query($sq l);
            if(! $data)
            exit($sql . "\n" . mysql_error());
            [/code]

            Comment

            • jonathan184
              New Member
              • Nov 2006
              • 154

              #7
              I tried that still no luck

              So I got the php page in a sub folder called content.
              I am thinking could it be the self php is wrong???
              so I get tot he search page http://192.168.1.2/content/search.php
              now after i click the search button this is what i get in the address bar

              http://192.168.1.2//content/<?=$PHP_SELF? >
              and the error message is

              You are not authorized to view this page
              You might not have permission to view this directory or page using the credentials you supplied.

              --------------------------------------------------------------------------------

              If you believe you should be able to view this directory or page, please try to contact the Web site by using any e-mail address or phone number that may be listed on the 192.168.1.2 home page.

              You can click Search to look for information on the Internet.




              HTTP Error 403 - Forbidden
              Internet Explorer




              Originally posted by pbmods
              Heya, Jonathan.

              Alrightey. If it gives no results, then there are two possibilities:
              1. There are no rows in `issue_tracker` where `$field` like '%$find%'.
              2. (more likely) The query is generating an error.


              Try changing line 81 to:
              [code=php]
              $sql = "SELECT * FROM issue_tracker WHERE $field LIKE'%$find%'";
              $data = mysql_query($sq l);
              if(! $data)
              exit($sql . "\n" . mysql_error());
              [/code]

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, Jonathan.

                You're getting this error because you're trying to use short tags on a system that does not have short tags enabled. This is the recommended configuration for modern PHP installations.

                Try changing '<?=' to '<?php echo'.

                Comment

                • jonathan184
                  New Member
                  • Nov 2006
                  • 154

                  #9
                  So would I put the statement like this?

                  [PHP]<form name="search" method="post" action="<?php echo'=$PHP_SELF ' ?>">[/PHP]

                  Originally posted by pbmods
                  Heya, Jonathan.

                  You're getting this error because you're trying to use short tags on a system that does not have short tags enabled. This is the recommended configuration for modern PHP installations.

                  Try changing '<?=' to '<?php echo'.

                  Comment

                  • pbmods
                    Recognized Expert Expert
                    • Apr 2007
                    • 5821

                    #10
                    Originally posted by jonathan184
                    So would I put the statement like this?

                    [PHP]<form name="search" method="post" action="<?php echo'=$PHP_SELF ' ?>">[/PHP]
                    Close.

                    [code=php]
                    <form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                    [/code]

                    Comment

                    • jonathan184
                      New Member
                      • Nov 2006
                      • 154

                      #11
                      Ok Idd that

                      i am not getting that error ont he page anymore. Right now when i clcik search the screen refreshes and it is back to the search page, no errors came up.

                      I cleared the ie cache and tried again and got the same problem.

                      Originally posted by pbmods
                      Close.

                      [code=php]
                      <form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                      [/code]

                      Comment

                      Working...