0

Hi friends I am working on a project where I need to show results based upon user queries.I have created the pages,but results are not showing.as I am new to php I can't figure where the problem is. Here is the code

<html>
<head><title>Showing Results</title></head>
<body bgcolor="#666666">
<?php
include_once "connection.php";
//$clmname=stripslashes(trim($_POST['select']));
//$txtvalue=stripslashes(trim($_POST['value']));
//$txtvalue=$_REQUEST['value'];
$select_query="SELECT * FROM `deed_records` WHERE '".$_REQUEST['select']."'='".$_REQUEST['value']."' ";
$list=mysql_query($select_query);
echo "<table border='1'>
	<tr>
	<th>Index</th>
	<th>Name of Owner</th>
	<th>S/D/H Of Owner</th>
	<th>Address of Owner</th>
	<th>Name of Vendor</th>
	<th>Deed No</th>
	<th>Reg Date</th>
	<th>Rack No</th>
	<th>Due Rs.</th>
	<th>Delivery Date</th>
	</tr>";
while($record=mysql_fetch_array($list))
{
	echo "<tr>
		<td>".$record['index']."</td>
		<td>".$record['name_of_owner']."</td>
		<td>".$record['sdh_of_owner']."</td>
		<td>".$record['address_of_owner']."</td>
		<td>".$record['name_of_vendor']."</td>
		<td>".$record['deed_no']."</td>
		<td>".$record['date']."</td>
		<td>".$record['no']."</td>
		<td>".$record['due_rs']."</td>
		<td>".$record['delivery_date']."</td>
		<td>
		</tr>";
}
mysql_close($connect);
?>
</body>
</html>

the two variable values are passed from another page

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by hielo
0

Line 9 -> You put quotes around the column name, also it is a bit vague what you mean with $_REQUEST , why are you using the same value as column name?

The select query is formatted as following:

SELECT * FROM table WHERE column='value'

Echo your query and check whether it is correct, for example by copying it and then paste it into PHPMyAdmin and then execute it to see what is wrong.

~G

0

The name of a database, table and/or field/column, needs to be enclosed in backticks (`), NOT apostrophes('). You incorrectly used apostrophes. Try:
$select_query="SELECT * FROM `deed_records` WHERE `".$_REQUEST."`='".$_REQUEST."' ";

Also, use [B]... or die( mysql_error() );[/B] whenever you execute a query so you get details about the error (if any).
try:

<html>
<head><title>Showing Results</title></head>
<body bgcolor="#666666">
<?php
include_once "connection.php";
//$clmname=stripslashes(trim($_POST['select']));
//$txtvalue=stripslashes(trim($_POST['value']));
//$txtvalue=$_REQUEST['value'];
$select_query=sprintf("SELECT * FROM `deed_records` WHERE `%s`='%s'"
                        , mysql_real_escape_string($_REQUEST['select'])
                        , mysql_real_escape_string($_REQUEST['value'])
                );

$list=mysql_query($select_query) or die( sprintf('Unable to execute query:<br />%s<br />%s',$select_query, mysql_error() ) );
if( 0==mysql_num_rows($list) )
{
    echo '<p>No records found</p>';
}
else
{
    echo "<table border='1'>
    <tr>
    <th>Index</th>
    <th>Name of Owner</th>
    <th>S/D/H Of Owner</th>
    <th>Address of Owner</th>
    <th>Name of Vendor</th>
    <th>Deed No</th>
    <th>Reg Date</th>
    <th>Rack No</th>
    <th>Due Rs.</th>
    <th>Delivery Date</th>
    </tr>";
    while($record=mysql_fetch_assoc($list))
    {
        echo PHP_EOL."<tr>
        <td>".$record['index']."</td>
        <td>".$record['name_of_owner']."</td>
        <td>".$record['sdh_of_owner']."</td>
        <td>".$record['address_of_owner']."</td>
        <td>".$record['name_of_vendor']."</td>
        <td>".$record['deed_no']."</td>
        <td>".$record['date']."</td>
        <td>".$record['no']."</td>
        <td>".$record['due_rs']."</td>
        <td>".$record['delivery_date']."</td>
        <td>
        </tr>";
    }
}
mysql_close($connect);
?>
</body>
</html>

Edited by hielo: n/a

0

Thanks 'hielo' and 'graphix'. But it didn't work after correcting ``. what I want to do is use the column name and value - variable. Can you please suggest any 'query'

0

on line 13 of my previous post put: echo $select_query; what do you get? What is the HTML code you are using on the page you are posting FROM?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.