[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error in php search form

Posted on 2011-05-11
2
Medium Priority
?
196 Views
Last Modified: 2012-05-11
I'm getting an error in my php script. It has to do with the else on line 38. Can anyone see what the problem is.
<?php

$con = mysql_connect("localhost","","");
	if (!$con)
 	{
 	 die('Could not connect: ' . mysql_error());
 	 }

	mysql_select_db("", $con);

$query = mysql_query("SELECT description, cross_streets, title, town, feeornofee, lease, phone, contact, office, email, rent FROM apartments WHERE description LIKE '%$search%' ¦¦ cross_streets LIKE '%$search%' ¦¦ title LIKE '%$search%' ¦¦ town LIKE '%$search%' ¦¦ feeornofee LIKE '%$search%' ¦¦ lease LIKE '%$search%' ¦¦ phone LIKE '%$search%' ¦¦ contact LIKE '%$search%' ¦¦ contact LIKE '%$search%' ¦¦ office LIKE '%$search%' ¦¦ email LIKE '%$search%' ¦¦ rent LIKE '%$search%'", $db);

if ($query) 
{ 
echo "<table width=100% border=0 cellpadding=0 cellspacing=5 class=border_playlist_table><tr>";

while ($myrow = mysql_fetch_array($query)) { // Begin while 
$title = $myrow["title"]; 
$town = $myrow["town"];
$contact = $myrow["contact"]; 
$office = $myrow["office"]; 
$phone = $myrow["phone"]; 
$rent = $myrow["rent"]; 
echo "<tr class=sub_1><td colspan=4>$title : $town</td></tr> 
<tr bgcolor=#55556F><td><p><a href=$url target=_blank>$url</a></p></td> 
<td><p>$title</p></td> 
<td><p>$town</p></td> 
<td><p>$contact</p></td></tr> 
<tr bgcolor=#55556F><td colspan=4>$office</td></tr> 
<tr bgcolor=#55556F><td colspan=4>$phone</td></tr> 
<tr><td colspan=4>&nbsp;</td></tr>"; 
} // end while 
echo "</tr></table>"; 
} 
else {
echo "problems...."; 
}
else{ 
echo "Search string is empty. <br> Go back and type a string to search"; 
} 
?>

Open in new window

0
Comment
Question by:genesisvh
2 Comments
 
LVL 19

Accepted Solution

by:
Greg Alexander earned 2000 total points
ID: 35738892
You have one two many elses

<?php

$con = mysql_connect("localhost","","");
        if (!$con)
        {
         die('Could not connect: ' . mysql_error());
         }

        mysql_select_db("", $con);

$query = mysql_query("SELECT description, cross_streets, title, town, feeornofee, lease, phone, contact, office, email, rent FROM apartments WHERE description LIKE '%$search%' ¦¦ cross_streets LIKE '%$search%' ¦¦ title LIKE '%$search%' ¦¦ town LIKE '%$search%' ¦¦ feeornofee LIKE '%$search%' ¦¦ lease LIKE '%$search%' ¦¦ phone LIKE '%$search%' ¦¦ contact LIKE '%$search%' ¦¦ contact LIKE '%$search%' ¦¦ office LIKE '%$search%' ¦¦ email LIKE '%$search%' ¦¦ rent LIKE '%$search%'", $db);

if ($query) 
{ 
echo "<table width=100% border=0 cellpadding=0 cellspacing=5 class=border_playlist_table><tr>";

while ($myrow = mysql_fetch_array($query)) { // Begin while 
    $title = $myrow["title"]; 
    $town = $myrow["town"];
    $contact = $myrow["contact"]; 
    $office = $myrow["office"]; 
    $phone = $myrow["phone"]; 
    $rent = $myrow["rent"]; 
    echo "<tr class=sub_1><td colspan=4>$title : $town</td></tr> 
    <tr bgcolor=#55556F><td><p><a href=$url target=_blank>$url</a></p></td> 
    <td><p>$title</p></td> 
    <td><p>$town</p></td> 
    <td><p>$contact</p></td></tr> 
    <tr bgcolor=#55556F><td colspan=4>$office</td></tr> 
    <tr bgcolor=#55556F><td colspan=4>$phone</td></tr> 
    <tr><td colspan=4>&nbsp;</td></tr>"; 
    } // end while 
    echo "</tr></table>"; 
} 
else 
{
   echo "Search string is empty. <br> Go back and type a string to search";          
}

?>

Open in new window

0
 

Author Closing Comment

by:genesisvh
ID: 35739114
Thanks for the quick response.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question