/    Sign up×
Community /Pin to ProfileBookmark

Can someone check my coding for errors?

Ok, i am making a search engine for a site, the site is [URL=”http://gmldesigngroup.com”]http://gmldesigngroup.com[/URL]

The code is this:

[CODE]<?php

$S_sq_ft = $_POST[‘sq_ft’];
$S_style = $_POST[‘style’];
$S_rooms = $_POST[‘rooms’];
$S_baths = $_POST[‘baths’];

$db_name = “house_search”;

$table_name = “house_detail”;

$connection = @mysql_connect(“”, “, “”) or die (mysql_error());

$db = mysql_select_db($db_name, $connection) or die(mysql_error());

$sql = “SELECT * FROM $table_name ORDER BY sq_ft”;

$result = @mysql_query($sql, $connection) or die(mysql_error());

$search_result = “”;

while ($row = mysql_fetch_array($result)){

$sq_ft = $row[‘sq_ft’];
$style = $row[‘style’];
$rooms = $row[‘num_rooms’];
$baths = $row[‘num_baths’];
$desc = $row[‘desc’];
$fpic = $row[‘fpic’];

if (($S_sq_ft == $sq_ft || $S_sq_ft == “0”) && ($S_style == $style || $S_style == “0”) && ($S_rooms == $style || $S_style == “0”) && ($S_rooms == $rooms || $S_rooms == “0”) && ($S_baths == $style || $S_baths == “0”)
{

$search_result .= “<p><a href=”search_reslut.htm”><img src=”fpic” align=”left” border=”0″></a></p>
<p><strong>Square Feet: </strong> $sq_ft</p>
<p><strong>Style: </strong>$style</p>
<p><strong>Number of rooms: </strong>$rooms</p>
<p><strong>Number of baths: </strong>$baths</p>
<p><strong>Description:</strong> $desc</p>
<hr align=”center” color=”#000000″>”;

}

}

if ($search_result == “”)
{
$search_result .= “Sorry, no results with those specific requirements”;
}

?>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>GML – Home</title>
<style type=”text/css”>
<!–
.style1 {color: #CBCBB3}
body {
background-color: #cbcbb3;
}
–>
</style>

<script type=”text/JavaScript”>
<!–
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf(“#”)!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(“?”))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//–>
</script>

</head>

<body>
<table bgcolor=”#cfc789″ width=”950″ border=”0″ align=”center” cellpadding=”1″ cellspacing=”2″>
<!–DWLayoutTable–>
<tr bgcolor=”#000000″>
<td height=”85″ colspan=”3″ valign=”top”><a href=”index.htm”><img src=”images/logo2.jpg” alt=”GML Logo” width=”494″ height=”100″ border=”0″ /></a><span class=”style6 style1″>Residential Custom Homes and Condominium Design and Land Planning</span></td>
</tr>
<tr bgcolor=”#cfc789″ height=”1″>
<td colspan=”3″></td></tr>
<tr bgcolor=”#000000″ height=”1″>
<td colspan=”3″></td></tr>
<tr bgcolor=”#cfc789″ height=”1″>
<td colspan=”3″></td></tr>
<tr bgcolor=”#000000″ height=”4″>
<td colspan=”3″></td></tr>
<tr bgcolor=”#cfc789″ height=”1″>
<td colspan=”3″></td></tr>
<tr bgcolor=”#cfc789″ height=”20″>
<td align=”center” colspan=”3″>
<a href=”index.htm” onmouseout=”MM_swapImgRestore()” onmouseover=”MM_swapImage(‘Home_Button’,”,’images/Home_button_RO.jpg’,1)”><img src=”images/Home_button.jpg” alt=”Home” width=”100″ height=”20″ border=”0″ id=”Home_Button”/></a>
<a href=”about_us.htm” onmouseout=”MM_swapImgRestore()” onmouseover=”MM_swapImage(‘About_us_Button’,”,’images/About_us_button_RO.jpg’,1)”><img src=”images/About_us_button.jpg” alt=”Home” width=”100″ height=”20″ border=”0″ id=”About_us_Button”/></a>
<a href=”contact.htm” onmouseout=”MM_swapImgRestore()” onmouseover=”MM_swapImage(‘Contact_Button’,”,’images/Contact_button_RO.jpg’,1)”><img src=”images/Contact_button.jpg” alt=”Home” width=”100″ height=”20″ border=”0″ id=”Contact_Button”/></a> </td>
</tr>
<tr bgcolor=”#000000″ height=”1″>
<td colspan=”3″></td></tr>
<tr>
<td valign=”top” width=”250″ height=”600″ bgcolor=”#cfc789″>

<h3>Search pre-made houses:</h3>

<form method=”post” action=”search_houses.php”>

<p>Square Feet:</p>
<dir>
<select name=”sq_feet” size=”1″>

<option value=”0″>Any</option>
<option value=”1000″>1000sq.ft and below</option>
<option value=”1500″>1001 – 1500sq.ft</option>
<option value=”2000″>1501 – 2000sq.ft</option>
<option value=”2500″>2001 – 2500sq.ft</option>
<option value=”3000″>2501 – 3000sq.ft</option>
<option value=”3500″>3001 – 3500sq.ft</option>
<option value=”4000″>3501 – 4000sq.ft</option>
<option value=”4500″>4001 – 4500sq.ft</option>
<option value=”5000″>4501 – 5000sq.ft</option>
<option value=”5500″>5001 – 5500sq.ft</option>
<option value=”6000″>5501 – 6000sq.ft</option>
<option value=”6500″>6001 – 6500sq.ft</option>
<option value=”7000″>6501 – 7000sq.ft</option>
<option value=”7500″>7001 – 7500sq.ft</option>
<option value=”8000″>7501 – 8000sq.ft</option>
<option value=”8500″>8001 – 8500sq.ft</option>
<option value=”9000″>8501 – 9000sq.ft</option>
<option value=”9500″>9001 – 9500sq.ft</option>
<option value=”10000″>9501 – 10000sq.ft</option>
<option value=”10500″>10001 – 10500sq.ft</option>
<option value=”11000″>10501 – 11000sq.ft</option>
<option value=”11500″>11001 – 11500sq.ft</option>
<option value=”12000″>11501 – 12000sq.ft</option>
<option value=”12500″>12001 – 12500sq.ft</option>
<option value=”13000″>12501 – 13000sq.ft</option>
<option value=”13500″>13001 – 13500sq.ft</option>
<option value=”14000″>13501 – 14000sq.ft</option>
<option value=”14500″>14001 – 14500sq.ft</option>
<option value=”15000″>14501 – 15000sq.ft</option>
<option value=”15500″>15001 – 15500sq.ft</option>
<option value=”16000″>15501 – 16000sq.ft</option>
<option value=”16500″>16001 – 16500sq.ft</option>
<option value=”17000″>16501 – 17000sq.ft</option>
<option value=”17500″>17001 – 17500sq.ft</option>
<option value=”18000″>17501 – 18000sq.ft</option>
<option value=”18500″>18001 – 18500sq.ft</option>
<option value=”19000″>18501 – 19000sq.ft</option>
<option value=”19500″>19001 – 19500sq.ft</option>
<option value=”20000″>19501sq.ft and above</option>
</select>
</dir>

<p>Style: </p>
<dir>
<select name=”Style” size=”1″>

<option value=”0″>Any</option>
</select> </dir>

<p>Number of Rooms:</p>
<dir>
<select name=”rooms” size=”1″>

<option value=”0″>Any</option>
<option value=”2″>2 rooms</option>
<option value=”3″>3 rooms</option>
<option value=”4″>4 rooms</option>
<option value=”5″>5 rooms</option>
<option value=”6″>6 rooms</option>
<option value=”7″>7 rooms</option>
<option value=”8″>8 rooms</option>
</select> </dir>

<p>Number of Baths: </p>
<dir>
<select name=”baths” size=”1″>

<option value=”0″>Any</option>
<option value=”1.5″>1 1/2 baths</option>
<option value=”2″>2 baths</option>
<option value=”2.5″>2 1/2 baths</option>
<option value=”3″>3 baths</option>
<option value=”3.5″>3 1/2 baths</option>
<option value=”4″>4 baths</option>
<option value=”4.5″>4 1/2 baths</option>
<option value=”5″>5 baths</option>
<option value=”5.5″>5 1/2 baths</option>
</select>
</dir>

<p><input type=”submit” name=”submit” value=”Search houses”></p>
</form> </td>
<td valign=”top” width=”0″ bgcolor=”#000000″></td>
<td valign=”top” width=”700″ bgcolor=”#cfc789″>
<!– InstanceBeginEditable name=”Body” –>
<h1>Search Results</h1>
<dir>

<?php
echo “$search_result”;
?>
</dir>
<!– InstanceEndEditable –> </td>
</tr>
</table>
</body>
</html>[/CODE]

Yes, i used Dreamweaver to create the HTML, i tried to clean up some of the code, but i know i missed some.

The @mysql_connect(“”, “, “”) really does have the stuff that it needs, i just took it out for obvious reasons.

For the site, it should look exactly the same as the previous ones, but the body is changed to display the search results.

All it does is goes to a blank screen. I don’t know if it is the databases being slow, or whatever, but it isn’t displaying anything.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 29.2008 — Line 13: you left out a quote, probably while editing your your login info

Line 35: needs a closing ")" to close the IF condition.
Copy linkTweet thisAlerts:
@WejauthorMar 29.2008 — Line 13: you left out a quote, probably while editing your your login info

Line 35: needs a closing ")" to close the IF condition.[/QUOTE]


Line 13: Yes, i did delete it when i posted it here, sorry.

Line 35: Thank you. I didn't see that :o

That fixed the problem i was having. I am happy now!

Now, I just have to get the actual search to work...
Copy linkTweet thisAlerts:
@WejauthorMar 29.2008 — Ok, i found a few really stupid mistakes i made in the if statement for the search.

It now looks like this:

[CODE]if (($S_sq_ft == $sq_ft || $S_sq_ft == "0") && ($S_style == $style || $S_style == "0") && ($S_rooms == $rooms || $rooms == "0") && ($S_baths == $baths || $S_baths == "0"))
{

$search_result .= "<p><a href="search_reslut.htm"><img src="fpic" align="left" border="0"></a></p>
<p><strong>Square Feet: </strong> $sq_ft</p>
<p><strong>Style: </strong>$style</p>
<p><strong>Number of rooms: </strong>$rooms</p>
<p><strong>Number of baths: </strong>$baths</p>
<p><strong>Description:</strong> $desc</p>
<hr align="center" color="#000000">";

}


}

if ($search_result == "")
{
$search_result .= "Sorry, no results with those specific requirements";
}[/CODE]


Still didn't fix it though. It should display all 8 of the test rows i chose, but it is showing the "Sorry, no results with those specific requirements".

I narrowed it down. It has to be the if statement. I checked all the variables, and it is getting the data. Please help someone! I am not comparing them right or something?
Copy linkTweet thisAlerts:
@WejauthorMar 29.2008 — Ok, I found the problem, but i don't know the solution.

[CODE]$S_sq_ft = $_POST['sq_ft'];
$S_style = $_POST['style'];
$S_rooms = $_POST['rooms'];
$S_baths = $_POST['baths'];[/CODE]


$S_sq_ft isn't setting itself equal to $_POST['sq_ft'] or $_POST['sq_ft'] isn't getting a value! Why?

EDIT: Even more of a find!

Only $_POST['sq_ft'] and $_POST['style'] are not getting a value. The other 2 are. I can't find why!
Copy linkTweet thisAlerts:
@WejauthorMar 29.2008 — Ok, I fixed it! Finlay. Stupid errors in my HTML coding.
×

Success!

Help @Wej spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...