How do you add a new criteria? Am I missing something?

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 if ($car['id']) { ?><?php } ?>
<?php include "../footer.php"; ?>

[/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 } ?>


Exterior:  <?=$car['exterior']?>

Interior:  <?=$car['interior']?>

Transmission:  <?=$car['transmission']?>

<?php if ($car['engine']) { ?>
Engine:  <?=$car['engine']?>
<?php } ?>
<?php if ($car['cylinders']) { ?>
Cylinders:  <?=$car['cylinders']?>
<?php } ?>

Vehicle Information:  <?=$car['vehicleinfo']?>


<?php if ($car['mileage'] > 0) { ?>
Mileage:  <?=number_format($car['mileage'])?>
<?php } ?>
<?php if ($car['showprice'] == "1") { ?>
Price:  $<?=number_format($car['price'])?>
<?php } ?>
<?php if ($car['showpayment'] == "1") { ?>
Payment:  $<?=number_format($car['payment'])?>
<?php } ?>[/php].

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>&nbsp; <?=$car['exterior']?></div>
		<div class="cardesc"><b>Interior:</b>&nbsp; <?=$car['interior']?></div>
		<div class="cardesc"><b>Transmission:</b>&nbsp; <?=$car['transmission']?></div>
		<?php if ($car['engine']) { ?><div class="cardesc"><b>Engine:</b>&nbsp; <?=$car['engine']?></div><?php } ?>
		<?php if ($car['cylinders']) { ?><div class="cardesc"><b>Cylinders:</b>&nbsp; <?=$car['cylinders']?></div><?php } ?>
	</div>
    	<div class="cardesc"><b>Vehicle Information:</b>&nbsp; <?=$car['vehicleinfo']?></div>
	<div style="float: left; margin-top: -3px;">
		<?php if ($car['mileage'] > 0) { ?><div class="cardesc"><b>Mileage:</b>&nbsp; <?=number_format($car['mileage'])?></div><?php } ?>
		<?php if ($car['showprice'] == "1") { ?><div class="cardesc"><b>Price:</b>&nbsp; $<?=number_format($car['price'])?></div><?php } ?>
		<?php if ($car['showpayment'] == "1") { ?><div class="cardesc"><b>Payment:</b>&nbsp; $<?=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.

I am this information is stored in a database somewhere. Did you update the table with the new column (or create a new table that holds the data)?

No. I’m having trouble finding that data base. I kind of know that I may have to get in there and alter things. What would that database be named typically and where should I start to look for that database? Please. If you don’t mind.

No idea what the name or anything else would be, but this file, sql.php, may let you know where and give you the credentials to access it.

I thought so. I logged onto the godaddy control panel and clicked on mysql. I log into phpmyadmin and I don’t know what to do after that. Can you lead me in the right direction after that? I suspect it’s going to look like the myphp panel in xampp. I don’t like godaddy all that much but I didn’t pick it.

I just need to add it to this table on the attached picture and I’m set?


Possibly. Depends on the detail you want to add. If you just want to add a blurb, then that would probably work. If on the otherhand, you want categorized spcefics like.

engine: 5.6L V8
color: Silver
doors: 4
Features: ABS

Then, you are likely going to need a new table, although you could technically just throw that into a text datatype and type everything out.

I am so sorry I am trying to add in vehicleinfo but I’m lost at the last part. I tried unsigned attribute, NULL, default 1, and extra set to auto increment but I got a syntax error.

Am I confused on what default means? I placed 1 there because user 1 is admin.


RE: blurb

Yes. It’s a text box for the user to paste vehicle information they get from the auction. It’s just text with no connection to anything.

[php]ALTER TABLE
tablename
ADD vehicleInfo VARCHAR(3000) DEFAULT null
AFTER category[/php]

Replace " tablename" with your actual table name.

OK. So I should make a new table with it’s name ‘vehicleinfo’?

Depends on how you want to do it. If this is simple and will stay that way, add the column.

PHPmyAdmin allows you to create tables.

Thank you so much for your help.

Next major ordeal is to update and remove the MySQL_ functions [mysqli_ is the new version or PDO is the current standard]and start replacing variable concatenation with prepared statements.

I know. I already warned the client about this. Do you know when that will be implemented? The version of php on his server is 5.6, to my understanding the changes don’t take effect until php 7.

It’s not about it being implemented, the mysql_* functions are removed from PHP7. Meaning if the host updates the server the site/system dies, big time.

Not just that, those function were removed for a reason. So, when you can it is best to update the code as you are messing with it anyway.

Will do. Already working on a new site. This one will be replaced shortly. Thanks guys.

Your database design is incorrect. You are duplicating data which violates Database Normalization standards. If you want to do this right look up and study Database Normalization. It is important to know and not difficult to learn.

Thank everyone. It’s not my code. I didn’t write this. I took this site over. I don’t even know when it was done. I’m going through this version of the site, fixing what I can to get it a little better until we change over to a completely different style in which I’ll have control of every aspect.

Sponsor our Newsletter | Privacy Policy | Terms of Service