Solved

Help with If statements

Posted on 2001-09-18
5
183 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 50 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
is this a cms? 8 60
Crazy text will not be removed no matter what I try! 13 29
PHP and google maps 13 44
Creating Functions in phpMyAdmin 8 12
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

776 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