By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 769 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

problem getting search script to work

100+
P: 154
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.dtd">
<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_title">Issue Title</option>
<option value="case_number">Case Number</option>
<option value="issue_description">Issue description</option>
<option value="customer_acct">Customer Account</option>
<option value="status">Status</option>
<option value="priority">Priority</option>
<option value="issue_date">Issue Date</option>
<option value="opened_by">Opened By</option>
<option value="assigned_to">Assigned</option>
<option value="issue_type">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">Status</th>
<th scope="col">Issue Title </th>
<th scope="col">Customer Account </th>
<th scope="col">Priortiy</th>
<th scope="col">Issue Type </th>
<th scope="col">Created Date </th>
</tr>
<tr class="aisteam">

<?php
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h3>Results</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($find);
$find = strip_tags($find);
$find = trim ($find);

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

//And we display the results
while($result = mysql_fetch_array( $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=mysql_num_rows($data);
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>Searched For:</b> " .$find;
}
echo "</table>"
?>



<?php include("../template/footer.php");
?>
[/PHP]
Jul 11 '07 #1
Share this Question
Share on Google+
10 Replies


pbmods
Expert 5K+
P: 5,821
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.
Jul 11 '07 #2

100+
P: 154
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.



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.
Jul 11 '07 #3

pbmods
Expert 5K+
P: 5,821
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.
Jul 11 '07 #4

100+
P: 154
its giving no results.

There are no errors.



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.
Jul 11 '07 #5

pbmods
Expert 5K+
P: 5,821
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:
Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT * FROM issue_tracker WHERE $field LIKE'%$find%'";
  2. $data = mysql_query($sql);
  3. if(! $data)
  4.     exit($sql . "\n" . mysql_error());
  5.  
Jul 12 '07 #6

100+
P: 154
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




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:
Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT * FROM issue_tracker WHERE $field LIKE'%$find%'";
  2. $data = mysql_query($sql);
  3. if(! $data)
  4.     exit($sql . "\n" . mysql_error());
  5.  
Jul 12 '07 #7

pbmods
Expert 5K+
P: 5,821
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'.
Jul 12 '07 #8

100+
P: 154
So would I put the statement like this?

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

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'.
Jul 12 '07 #9

pbmods
Expert 5K+
P: 5,821
So would I put the statement like this?

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

Expand|Select|Wrap|Line Numbers
  1. <form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  2.  
Jul 12 '07 #10

100+
P: 154
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.

Close.

Expand|Select|Wrap|Line Numbers
  1. <form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  2.  
Jul 12 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.