?
Solved

Help with If statements

Posted on 2001-09-18
5
Medium Priority
?
195 Views
Last Modified: 2008-03-06
Okay, I created a form to search for makes and models of cars.  When I submit that form, I created a php page that will process it and show the results.

Here is what I have done so far and I get a parse error :(

<?
if ($submit == "Search Inventory")
{
/* This is where I start to have problems...The user
    can either select a Make or leave it at the default
    -- select all --.  They can also select a Make and
    leave the model at the default --select all--.
    I was trying to see if both were set then use the
    values from those select boxes in the query.  If one
    had a value and the other one had the select all  
    option then the query is as follows.  */

if (isset($Make) && isset($Model))
{
$query = "select * from tblcarinventory where Make='$Make' and Model='$Model' order by Make asc, Model asc ";
}

if (isset($Make) && $Model ="-- select all -- "))
{
$query = "select * from tblcarinventory where Make='$Make' order by Make asc, Model asc ";
}


$result = safe_query($query);
if ($result)
{
     while ($row = mysql_fetch_array($result))

     {
     print "<table border=2 width=55% bordercolor=black>";
     print "<tr>";
     print "<td width=40%><b>New?:</b></td>";
     print "<td width=60%>";
     print $row["NeworUsed"];
     print "</td>";
      print "</tr>";
     print "<tr>";
     print "<td width=40%><b>VIN #:</b></td>";
     print "<td width=60%>";
     print $row["VIN_Number"];
     print "</td>";
     print "</tr>";
     print "<tr>";
     print "<td width=40%><b>Year:</b></td>";
     print "<td width=60%>";
     print $row["CarYear"];
     print "</td>";
     print "</tr>";
     print "<tr>";
     print "<td width=40%><b>Make:</b></td>";
     print "<td width=60%>";
     print $row["Make"];
     print "</td>";
     print "</tr>";
     print "<tr>";
     print "<td width=40%><b>Model</b></td>";
     print "<td width=60%>";
     print $row["Model"];
     print "</td>";
     print "</tr>";
     print "<tr>";
     print "<td width=40%><b>Exterior Color:</b></td>";
     print "<td width=60%>";
     print $row["ExtColor"];
     print "</td>";
     print "</tr>";
     print "<tr>";
     print "<td width=40%><b>Interior Color:</b></td>";
     print "<td width=60%>";
     print $row["IntColor"];
     print "</td>";
     print "</tr>";
     print "<tr>";
     print "<td width=40%><b>Miles:</b></td>";
     print "<td width=60%>";
     print number_format($row["Miles"]);
     print "</td>";
     print "</tr>";
     print "<tr>";
     print "<td width=40%><b>Price:</b></td>";
     print "<td width=60%>";
     print "$";
     print number_format($row["Price"]);
     print "</td>";
     print "</tr>";
     print "<tr>";
     print "<td width=40%><b>Equipment:</b></td>";
     print "<td width=60%>";
     print $row["Equipment"];
     print "</td>";
     print "</tr>";
     print "<br>\n";
     print "<br>\n";
     print "<br>\n";
     print "</table>";

     }
     mysql_free_result($result);
}


}
?>


Any help would be greatly appreciated.

Zippy21
0
Comment
Question by:zippy21
  • 3
5 Comments
 
LVL 4

Expert Comment

by:heddesheimer
ID: 6492562
you forgot an opening brace in an if statement in line 21 (just check your error messages :-) )
it should read:

if (isset($Make) && ($Model ="-- select all -- "))

hope that helps

Marian
0
 
LVL 8

Expert Comment

by:us111
ID: 6492647
I would suggest to convert

while ($row = mysql_fetch_array($result))
 {
    print "<table border=2 width=55% bordercolor=black>";
    print "<tr>";
    print "<td width=40%><b>New?:</b></td>";
    print "<td width=60%>";

into

while ($row = mysql_fetch_array($result))
 {
?>
 <table border=2 width=55% bordercolor=black>
  <tr>
   <td width=40%><b>New?:</b></td>
   <td width=60%><?print $row["NeworUsed"];?>
...
...
...

it's more convenient....and it will avoid (a little bit) to get some parse errors
0
 
LVL 8

Expert Comment

by:us111
ID: 6492651
and you forgot a =:

if (isset($Make) && ($Model = = "-- select all -- "))
0
 
LVL 8

Accepted Solution

by:
us111 earned 200 total points
ID: 6492655
an advice:
if (isset($Make) && $Model ="-- select all -- "))
{
  $query = "select * from tblcarinventory where Make='$Make' order by Make asc, Model asc ";
}

if you have  only one line after the if, don't use { and }

if (isset($Make) && $Model ="-- select all -- "))
       $query = "select * from tblcarinventory where Make='$Make' order by Make asc, Model asc ";

is the same

The less you have some {}, the less you will have some parse errors.
0
 
LVL 1

Expert Comment

by:sweatje
ID: 6496390
I have seen it recommented elsewhere that you do all of your if comparisons as "-- selectt all --" == $Model.  That way if you accidentally forget the second =, it will result in a script error rather than the unintended consequence of a variable assignment.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

862 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