I have a car dealership page I took over. I tried to add in a new criteria to the showroom page of this website. http://morabitomotors.com/showroom.php When you’re looking at a vehicle listing I need to add a category that says “Vehicle Information” I thought I got it but I didn’t. When I test it I get an undefined index: error. Is it because the vehicles already posted do not have that information yet? After i upload my changes all vehicles added after would have that info added in using the add vehicle
I first added the criteria to this php file to add a vehicle to the database
in this area of the file[php]td>[/php].
This is the code for the entire file in case i was something else but I didn’t change any of the other code:
[php]<?php
$title = “Add/Change a Vehicle”;
$showSide = false;
include “…/sql.php”;
if ($_SESSION[‘admin’] != 1)
{
header(“Location: /admin”);
die();
}
$id = intval($_GET[‘id’]);
if ($id > 0)
{
$x = mysql_query(“select * from cars where id=$id”);
$car = mysql_fetch_array($x, MYSQL_ASSOC);
if (!$car) $vehicleDoesNotExist = true;
}
elseif (isset($_POST[‘id’]))
{
$changeId = intval($_POST[‘id’]);
if ($_POST['delete'] == "Delete Vehicle")
{
mysql_query("delete from cars where id=$changeId");
$x = mysql_query("select id from images where car_id=$changeId");
if (mysql_num_rows($x) > 0)
while ($y = mysql_fetch_array($x, MYSQL_ASSOC))
unlink("../images/vehicles/$changeId-" . $y['id'] . ".jpg");
mysql_query("delete from images where car_id=$changeId");
header("Location: /showroom.php");
die();
}
else
foreach ($_POST as $k => $v)
{
if ($k == "id" || $k == "showpayment" || $k == "showprice") continue;
$data[$k] = addslashes(stripslashes($v));
}
$data['showprice'] = $_POST['showprice'] == "on" ? 1 : 0;
$data['showpayment'] = $_POST['showpayment'] == "on" ? 1 : 0;
if ($changeId == 0) // new car
{
$keys = implode(",", array_keys($data));
$vals = implode("\",\"", $data);
$query = "insert into cars ($keys) values (\"$vals\")";
}
else // change car
{
$query = "update cars set ";
$query2 = "";
foreach ($data as $k=>$v)
$query2 .= ",$k=\"$v\"";
$query .= substr($query2, 1) . " where id=$changeId";
}
mysql_query($query) or die(mysql_error());
if ($changeId == 0)
$newid = mysql_insert_id();
else
$newid = $changeId;
header("Location: carpics.php?id=$newid");
die();
}
include “…/header.php”;
if ($vehicleDoesNotExist)
{
echo “Vehicle ID #$id no longer exists.”;
include “…/footer.php”;
die();
}
?>
Category: | Convertible Four-Door Sedan Hatchback Minivan/Van Motorcycle Sport/Utility Truck Two-Door Coupe Wagon |
Make: | |
Model: | |
Year: | |
Exterior: | |
Interior: | |
Transmission: | |
Vehicle Info: |
Engine: | |
Cylinders: | |
Numbers only (no letters/commas): | |
Mileage: | |
Price: | name="showprice"> Show Price |
Payment: | name="showpayment"> Show Payment |
[/php]
Then to the carpreview.php file that is nested in the page I placed a link to above http://morabitomotors.com/showroom.php in this area[php]<?php } ?>
<?php if ($car['engine']) { ?>
<?php if ($car['cylinders']) { ?>
<?php if ($car['mileage'] > 0) { ?>
<?php if ($car['showprice'] == "1") { ?>
<?php if ($car['showpayment'] == "1") { ?>
This is the complete file:
[php]<?php
function showCarPreview($car, $forCraigslist = false)
{
if (!$forCraigslist) {
?>
<?php
$x = mysql_query(“select count(*) from images where car_id=” . $car[‘id’]);
$c = end(mysql_fetch_array($x, MYSQL_ASSOC));
if ($c == 0)
$img = "/images/noimage.png";
else
$img = "/images/vehicles/" . $car['id'] . "-" . end(mysql_fetch_array(mysql_query("select id from images where car_id=" . $car['id'] . " and main=1"), MYSQL_ASSOC)) . "t.jpg";
echo "<a href=\"/viewcar.php?id=" . $car['id'] . "\"><img src=\"$img\" width=105></a>";
echo "<div>$c image";
if ($c != 1) echo "s";
echo "</div>";
?>
</div>
</div>
<?php } ?>
<div style="float: left; margin-top: -3px; width: 205px;">
<div class="cardesc"><b>Exterior:</b> <?=$car['exterior']?></div>
<div class="cardesc"><b>Interior:</b> <?=$car['interior']?></div>
<div class="cardesc"><b>Transmission:</b> <?=$car['transmission']?></div>
<?php if ($car['engine']) { ?><div class="cardesc"><b>Engine:</b> <?=$car['engine']?></div><?php } ?>
<?php if ($car['cylinders']) { ?><div class="cardesc"><b>Cylinders:</b> <?=$car['cylinders']?></div><?php } ?>
</div>
<div class="cardesc"><b>Vehicle Information:</b> <?=$car['vehicleinfo']?></div>
<div style="float: left; margin-top: -3px;">
<?php if ($car['mileage'] > 0) { ?><div class="cardesc"><b>Mileage:</b> <?=number_format($car['mileage'])?></div><?php } ?>
<?php if ($car['showprice'] == "1") { ?><div class="cardesc"><b>Price:</b> $<?=number_format($car['price'])?></div><?php } ?>
<?php if ($car['showpayment'] == "1") { ?><div class="cardesc"><b>Payment:</b> $<?=number_format($car['payment'])?></div><?php } ?>
</div>
<?php if (!$forCraigslist) { ?>
<div style="float: right; margin-right: 130px; font-size: 10pt;">
<input type="button" onclick="location='/finance.php';" style="cursor: pointer; font-weight: bold; background: #eee; padding: 5px; border: 1px solid #094863; color: red; text-decoration: none; font-size: 14pt;" value="We Finance" />
<?php if ($_SESSION['admin'] == 1) { ?>
<br/>
<!--<li><a href="/admin/addcar.php">Add a new vehicle</a><br/>-->
<li><a href="/admin/addcar.php?id=<?=$car['id']?>">Edit information</a><br/>
<li><a href="/admin/carpics.php?id=<?=$car['id']?>">Change pictures</a>
<li><a href="/admin/craigslist.php?id=<?=$car['id']?>">Craigslist template</a>
<?php } ?>
</div>
<div style="clear: both;"></div>
</div>
<?php
}
}
?>
[/php]
When i open the page on my test server in xampp I get this error: Notice: Undefined index: vehicleinfo in /Applications/XAMPP/xamppfiles/htdocs/test_new/carpreview.php on line 35
I’m not sure if it is because I missed something or the cars listed now don’t have that vehicle information on them yet. Any help is greatly appreciated.