Jump to content

Recommended Posts

i get the value from drop down box.. when i display echo it .. i can view all the data i selected.... but when i get these data apply into the query below .. it did not show the data i want..

<?php 

 

if(isset($_POST[submitform])){

 

$location= $_POST[location];

$category= $_POST[category];

$option= $_POST[option];

 

echo"$location";

echo"$category";

echo"$option";

}?>

 

<?php

                $TableName = "prem_propertyad";                 

                $Conn =mysql_connect($server, $user, $pass);               

                mysql_select_db($db);                   

               

                $Query = "SELECT * from $TableName where type1='$option'"; 

               

                if ($location !="All Locations")

                $Query = $Query. " and state= '$Location'";

               

                if ($category !="All Category")

                $Query = $Query. " and type2='$category'";

               

               

               

                $Result=mysql_query($Query);               

           

                print ("<TABLE BORDER=1 WIDTH=\"750\" CELLSPACING=2 CELLPADDING=2 ALIGN=center>\n"); 

                print ("<TR ALIGN=center VALIGN=top>\n"); 

               

                print ("<TD ALIGN=center VALIGN=top>Sale/Rent</TD>\n"); 

                print ("<TD ALIGN=center VALIGN=top>Location</TD>\n"); 

                print ("<TD ALIGN=center VALIGN=top>Price(RM)</TD>\n"); 

                print ("<TD ALIGN=center VALIGN=top>Type</TD>\n"); 

                print ("<TD ALIGN=center VALIGN=top>Build Up Area/Land Area (sq ft)</TD>\n"); 

                print ("<TD ALIGN=center VALIGN=top>Date Posted</TD>\n"); 

                print ("</TR>\n"); 

               

           

                while ($Row = mysql_fetch_array ($Result)) 

                { 

                    print ("<TR ALIGN=center VALIGN=top>\n"); 

                    print ("<TD ALIGN=center VALIGN=top>$Row[type1] </TD>\n"); 

                    print ("<TD ALIGN=center VALIGN=top>$Row[state] </TD>\n"); 

                    print ("<TD ALIGN=center VALIGN=top>$Row[selling_price]</TD>\n"); 

                    print ("<TD ALIGN=center VALIGN=top>$Row[type3]</TD>\n"); 

                    print ("<TD ALIGN=center VALIGN=top>$Row[buildup_area]</TD>\n"); 

                    print ("<TD ALIGN=center VALIGN=top>$Row[datePosted]</TD>\n"); 

                    print ("</TR>\n"); 

                } 

           

                mysql_close($Conn);             

                print ("</TABLE>\n"); 

            ?>

Link to comment
https://forums.phpfreaks.com/topic/67950-syntax-error/
Share on other sites

Take out the Quotes and change the Query

 

<?php  

if(isset($_POST[submitform])){ 

$location= $_POST[location]; 
$category= $_POST[category]; 
$option= $_POST[option]; 

echo ($location); 
echo($category); 
echo ($option); 
}

$Query = ("SELECT * FROM ".$TableName."    WHERE type1='$option'");  

?> 

Link to comment
https://forums.phpfreaks.com/topic/67950-syntax-error/#findComment-341510
Share on other sites

You are getting a syntax error? What is this error?

 

You really should use literal strings when using a key in an array, like $_POST['location'].

 

Try

$Result=mysql_query($Query) or die(mysql_error());                 

To see the error. If there is no error, there probably isn't an entry that has $option for "type1" in table "prem_propertyad". Check that the entry that you want exists.

Link to comment
https://forums.phpfreaks.com/topic/67950-syntax-error/#findComment-341518
Share on other sites

Final Code:

 

<?php 
                $TableName = "prem_propertyad";                  
                $Conn =mysql_connect($server, $user, $pass);                 
                mysql_select_db($db);                     
                 
                $Query = ("SELECT * FROM ".$TableName." WHERE type1=".$option.""
                 
                if ($location !="All Locations") 
                $Query = $Query. " and state= ".$Location.""; 
                 
                if ($category !="All Category") 
                $Query = $Query. " and type2=".$category.""; 
                 
                 
                 
                $Result=mysql_query($Query)or die(mysql_error("Could not select from database!"));                  
             
                print ("<TABLE BORDER=1 WIDTH=\"750\" CELLSPACING=2 CELLPADDING=2 ALIGN=center>\n");  
                print ("<TR ALIGN=center VALIGN=top>\n");  
                 
                print ("<TD ALIGN=center VALIGN=top>Sale/Rent</TD>\n");  
                print ("<TD ALIGN=center VALIGN=top>Location</TD>\n");  
                print ("<TD ALIGN=center VALIGN=top>Price(RM)</TD>\n");  
                print ("<TD ALIGN=center VALIGN=top>Type</TD>\n");  
                print ("<TD ALIGN=center VALIGN=top>Build Up Area/Land Area (sq ft)</TD>\n");  
                print ("<TD ALIGN=center VALIGN=top>Date Posted</TD>\n");  
                print ("</TR>\n");  
                 
             
                while ($Row = mysql_fetch_array ($Result))  
                {  
                    print ("<TR ALIGN=center VALIGN=top>\n");  
                    print ("<TD ALIGN=center VALIGN=top>".$Row['type1']." </TD>\n");  
                    print ("<TD ALIGN=center VALIGN=top>".$Row['state']." </TD>\n");  
                    print ("<TD ALIGN=center VALIGN=top>".$Row['selling_price']."</TD>\n");  
                    print ("<TD ALIGN=center VALIGN=top>".$Row['type3']."</TD>\n");  
                    print ("<TD ALIGN=center VALIGN=top>".$Row['buildup_area']."</TD>\n");  
                    print ("<TD ALIGN=center VALIGN=top>".$Row['datePosted']."</TD>\n");  
                    print ("</TR>\n");  
                }  
             
                mysql_close($Conn);              
                print ("</TABLE>\n");  
            ?>  

Link to comment
https://forums.phpfreaks.com/topic/67950-syntax-error/#findComment-341546
Share on other sites

bro.. i had followed your way.. but now the whole page became blank... it din show any error msg.. just blank whole page... i had unchekced the show friendly messaage ..below is my full code..
i think of no idea why show wrong din data that i wan...

[quote]<?php 
include('./uservar.php');	
?>	
<?php 
error_reporting(E_ALL);
if(isset($_POST[submitform])){

$location= $_POST[location];
$category= $_POST[category];
$option= $_POST[option];

echo"$location";
echo"$category";
echo"$option";
}?>
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Neuproperty</title>
<style fprolloverstyle>A:hover {color: #FFFFCC}
</style>
<script type="text/javascript" language="JavaScript1.2" src="menu/stmenu.js"></script>
</head>

<body link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" bgcolor="#C0C0C0">

<div align="center">
<table border="0" style="border-collapse: collapse" width="950" id="table1">
	<tr>
			<td width="566" rowspan="2" bgcolor="#FFFFFF">
		<img border="0" src="img/logo.gif" width="235" height="67"></td>
		<td height="22" colspan="3" valign="top" bgcolor="#FFFFFF"> </td>
	</tr>
	<tr>
		<td colspan="3" height="47" bgcolor="#FFFFFF">
		<p align="right"><b><font face="Arial" color="#333333" size="2">
		Quick Property Search</font></b>
        <input type="text" name="T1" size="25"><input type="submit" value="Find" name="B1"></td>
	</tr>

	<tr>
		<td colspan="4" bgcolor="#FFFFFF">
		<div align="center">
			<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table2">

				 <td height="28" colspan="0"><script type="text/javascript" language="JavaScript1.2" src="menu/property.js"></script>                  </td>
				<tr>

					<td bgcolor="#009696" height="8" width="6%"> </td>
				</tr>
		</table>
			<p align="left"><b><font face="Arial">Search</font></b></div>
		</td>
	</tr>

	<tr>
		<td colspan="3" bgcolor="#FFFCF9">
		  <FORM  name="frmPropWanted" action="results.php" method=post>
		   <TABLE  cellSpacing=0 cellPadding=0 align="center" width="101%"  bgColor=#dddddd border=0 id="table4" height="15">
					<TR>
						`<TD height="15" bgcolor="#FFFCF9">
						<select size="1" name="location">
							<option selected>All Locations</option>
							<option>Kedah</option>
							<option>Perlis</option>
							<option>Pulau Pinang</option>
							<option>Perak</option>
							<option>Selangor</option>
							<option>Sabah</option>
							<option>Sabah</option>
							<option>Negeri Sembilan</option>
							<option>Melaka</option>
							<option>Johor</option>
							<option>Terrenganu</option>
							<option>Kelantan</option>
							<option>W.P. Kuala Lumpur</option>
							<option>W.P Labuan</option>
						</select>

						<select size="1" name="category">
							<option selected>All Category</option>
							<option>Residential Property</option>
							<option>Commercial Property</option>
							<option>Industrial Property</option>
							<option>Land</option>
							<option>Room</option>
						</select>

						<select size="1" name="option">
							<option>Rental</option>
							<option>Sales</option>
							<option selected>Rental / Sales</option>
						</select>

						<input type="submit" value="Search" name="submitform">
						<input type="reset" value="Reset" name="B2"><br>
							 
								</FORM>
						</TD>
					</TR>
					 <TR>

             <TD height="15" bgcolor="#FFFFFF" colspan="3">
			<table border="0" style="border-collapse: collapse" width="100%"  cellpadding="0" id="table6">
				<tr>
					<td bgcolor="#FFE2D9">
						<font face="Arial" size="2"> records </font>

					</td>
				</tr>
				<tr></tr>

			</table>
			<div align="left">
       
      			</div>	
	</tr>

			</TABLE>

			<?php
			error_reporting(E_ALL);
			$TableName = "prem_propertyad"; 				
			$Conn =mysql_connect($server, $user, $pass);				
			mysql_select_db($db);					

			$Query = ("SELECT * from ".$TableName." where type1=".$option.""; )

			if ($location !="All Locations")
			$Query = $Query. " and state= ".$Location."";

			if ($category !="All Category")
			$Query = $Query. " and type2=".$category."";



			$Result=mysql_query($Query)or die(mysql_error("Could not select from database!"));                  				

			print ("<TABLE BORDER=1 WIDTH=\"750\" CELLSPACING=2 CELLPADDING=2 ALIGN=center>\n"); 
			print ("<TR ALIGN=center bgcolor=999999 VALIGN=top>\n"); 

			print ("<TD ALIGN=center VALIGN=top>Sale/Rent</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Location</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Price(RM)</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Type</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Build Up Area/Land Area (sq ft)</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Date Posted</TD>\n"); 
			print ("</TR>\n"); 


			while ($Row = mysql_fetch_array ($Result)) 
			{ 
				print ("<TR ALIGN=center bgcolor='pink' VALIGN=top>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['type1']." </TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['state']." </TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['selling_price']."</TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['type3']."</TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['buildup_area']."</TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['datePosted']."</TD>\n"); 
				print ("</TR>\n"); 
			} 

			mysql_close($Conn); 			
			print ("</TABLE>\n"); 
		?> 
			<br>

			<?php
			$TableName2 = "free_propertyad"; 	
			$Conn =mysql_connect($server, $user, $pass);				
			mysql_select_db($db);					

			$Query = ("SELECT * from ".$TableName2." where type1=".$option.""; )

			if ($location !="All Locations")
			$Query = $Query. " and state= ".$Location."";

			if ($category !="All Category")
			$Query = $Query. " and type2=".$category."";



			$Result=mysql_query($Query)or die(mysql_error("Could not select from database!"));                  				

			print ("<TABLE BORDER=1 WIDTH=\"750\" CELLSPACING=2 CELLPADDING=2 ALIGN=center>\n"); 
			print ("<TR ALIGN=center bgcolor=999999 VALIGN=top>\n"); 

			print ("<TD ALIGN=center VALIGN=top>Sale/Rent</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Location</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Price(RM)</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Type</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Build Up Area/Land Area (sq ft)</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Date Posted</TD>\n"); 
			print ("</TR>\n"); 


			while ($Row = mysql_fetch_array ($Result)) 
			{ 
				print ("<TR ALIGN=center VALIGN=top>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['type1']." </TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['state']." </TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['selling_price']."</TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['type3']."</TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['buildup_area']."</TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['datePosted']."</TD>\n"); 
				print ("</TR>\n"); 
			} 

			mysql_close($Conn); 			
			print ("</TABLE>\n"); 
		?> 
		<br>

		<?php
			$TableName3 = "basic_propertyad"; 	

			$Conn =mysql_connect($server, $user, $pass);				
			mysql_select_db($db);					

			$Query = ("SELECT * from ".$TableName3." where type1=".$option.""; )

			if ($location !="All Locations")
			$Query = $Query. " and state= ".$Location."";

			if ($category !="All Category")
			$Query = $Query. " and type2=".$category."";



			$Result=mysql_query($Query)or die(mysql_error("Could not select from database!"));                  				

			print ("<TABLE BORDER=1 WIDTH=\"750\" CELLSPACING=2 CELLPADDING=2 ALIGN=center>\n"); 
			print ("<TR ALIGN=center bgcolor=999999 VALIGN=top>\n"); 

			print ("<TD ALIGN=center VALIGN=top>Sale/Rent</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Location</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Price(RM)</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Type</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Build Up Area/Land Area (sq ft)</TD>\n"); 
			print ("<TD ALIGN=center VALIGN=top>Date Posted</TD>\n"); 
			print ("</TR>\n"); 


			while ($Row = mysql_fetch_array ($Result)) 
			{ 
				print ("<TR ALIGN=center VALIGN=top>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['type1']." </TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['state']." </TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['selling_price']."</TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['type3']."</TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['buildup_area']."</TD>\n"); 
				print ("<TD ALIGN=center VALIGN=top>".$Row['datePosted']."</TD>\n"); 
				print ("</TR>\n"); 
			} 

			mysql_close($Conn); 			
			print ("</TABLE>\n"); 
		?> 


		</td>
	</tr>		



        

	<tr>
		<td colspan="2" bgcolor="#FFFCF9"> </td>


		<td width="379" bgcolor="#FFFCF9"> </td>
	</tr>

	<tr>
		<td colspan="4" bgcolor="#FFFFFF">

			<table border="0" style="border-collapse: collapse" width="950" cellspacing="1" id="table3">
				<tr>
					<td width="100%" height="20"><hr noshade size="1"></td>
				</tr>
				<tr>
					<td width="100%" height="26">
					<p align="center"><b><font size="1" color="#808080">Help | Contact | 
					About this site | Terms and Conditions | </font></b></td>
				</tr>
			</table>
		</td>
	</tr>

</table>


</body>

</html>[/quote]

Link to comment
https://forums.phpfreaks.com/topic/67950-syntax-error/#findComment-342116
Share on other sites

You never check your query succeeds before attempting to use it. The general syntax for a select query should be something like...

 

<?php

 $sql = "SELECT foo FROM bar";
 if ($result = mysql_query($sql)) {
   if (mysql_num_rows($result)) {
     // it is now safe to display your retrieved data.
     while ($row = mysql_fetch_assoc($result)) {
       echo $row['foo']."<br />";
     }
   } else {
    echo "No results found";
   }
 } else {
   echo "Query failed<br />$sql<br />". mysql_error();
 }

?>

 

Apply this example to your code and let use know what the results are.

Link to comment
https://forums.phpfreaks.com/topic/67950-syntax-error/#findComment-342580
Share on other sites

my query able to display the data..

hi.. darkfreaks.. for the code u written..

[code=php:0] $Query = ("SELECT * FROM ".$TableName." WHERE type1=".$option.""
                 
                if ($location !="All Locations") 
                $Query = $Query. " and state= ".$Location.""; 
                 
                if ($category !="All Category") 
                $Query = $Query. " and type2=".$category.""; 
                 

 

my browser wrote an error at the line 

$Query = ("SELECT * FROM ".$TableName." WHERE type1=".$option."";)

error on ";"

 

is it should be like this ??

$Query = ("SELECT * FROM ".$TableName." WHERE type1=".$option."") ;

 

Link to comment
https://forums.phpfreaks.com/topic/67950-syntax-error/#findComment-342626
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.