VIN Decoder Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
87ASC
Forum Newbie
Posts: 5
Joined: Sat Aug 25, 2007 3:36 am

VIN Decoder Help

Post by 87ASC »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I need some help with a VIN Decoder I am making, so basically what it is, is that the user put's in the Consecutive Unit Number (CUN) into the textbox and he/she click's submit and then it tell's you information about your car. Now I am a beginner in PHP but I do understand some about it and I do have some code I already made but it didn't work. I was thinking some kind of an array that show's all of the CUN's then when the user's CUN they entered match up with it then it get's the text to display and if the CUN isn't found it gives a error message like "Could not find your CUN in our list of CUNs."
Here is the code i've gotten.
The textbox page code:
[syntax="html"]
Just enter in your last 6 number's from your VIN (e.g. 1FABP40A6HF000001 so the information you would enter is 000001)
<form action="ascmclarenmustangresults.php" method="post">
CUN: <input type="text" name="vintextbox" />
<br />
<input name="submit" type="submit" />
</form>
The PHP result's code:[/syntax]

Code: Select all

<?php
$cun = $_POST["vintextbox"];
if ($cun["vintextbox"] == '000001')
{
	echo Car number $cun00["vintextbox"] is a 1987.</br>
}
if ($cun["vintextbox"] == '000002')
{
	echo Car number $cun["vintextbox"] is a 1988.</br>
}
if ($cun["vintextbox"] == '000003')
{
	echo Car Number $cun ["vintextbox"] is a 1989.</br>	
}
{
else

	echo Could not find your CUN in our list of CUNs.</br>
}
Thank's.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You're missing quotes around the strings you are attempting to echo, which is most likely the error you are getting.
User avatar
87ASC
Forum Newbie
Posts: 5
Joined: Sat Aug 25, 2007 3:36 am

Post by 87ASC »

Ok, so that would be all that would have to be done for it to work? Also should it look like this?

Code: Select all

<?php 
$cun = $_POST["vintextbox"]; 
if ($cun["vintextbox"] == '000001') 
{ 
        echo "Car number $cun00["vintextbox"] is a 1987."</br> 
} 
if ($cun["vintextbox"] == '000002') 
{ 
        echo "Car number $cun["vintextbox"] is a 1988."</br> 
} 
if ($cun["vintextbox"] == '000003') 
{ 
        echo "Car Number $cun ["vintextbox"] is a 1989."</br>      
} 
{ 
else 

        echo "Could not find your CUN in our list of CUNs."</br> 
}
Thank's.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Read the manual's page on strings: http://php.net/language.types.string
User avatar
87ASC
Forum Newbie
Posts: 5
Joined: Sat Aug 25, 2007 3:36 am

Post by 87ASC »

feyd wrote:Read the manual's page on strings: http://php.net/language.types.string
I tried that, I read up on it, what I think is the problem is that their are too many if and esle statement's. I would think their is some kind of other way to do this, I was thinking some kind of an array.
Thank's.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

An array would be useful here (so would a database if there's a lot of them)

Code: Select all

$cuns = array('000001' => '19xx model', '000002' => '199x model');

if(!empty($_POST['cun']) && in_array($_POST['cun'], $cuns))
{
    echo $cuns[$_POST['cun']];
} else
{
     echo 'error';
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Or perhaps even a switch() statement?
User avatar
87ASC
Forum Newbie
Posts: 5
Joined: Sat Aug 25, 2007 3:36 am

Post by 87ASC »

scottayy wrote:An array would be useful here (so would a database if there's a lot of them)

Code: Select all

$cuns = array('000001' => '19xx model', '000002' => '199x model');

if(!empty($_POST['cun']) && in_array($_POST['cun'], $cuns))
{
    echo $cuns[$_POST['cun']];
} else
{
     echo 'error';
}
I read up on the function's you have in their and it does make sense, but the only problem is that it alway's say's error, I tried different thing's but it say's error. I renamed the textbox to "cun" like you have it named on here and it still come's back with error. Their is going to be a lot of them, but I can't even get a database to work so I can setup a phpBB forum and it won't work, you know of any good tutorial's for creating a database for php? Thank's.
Everah wrote:Or perhaps even a switch() statement?
That sound's like a good idea too, but how exactly would I do that? Thank's.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
87ASC
Forum Newbie
Posts: 5
Joined: Sat Aug 25, 2007 3:36 am

Post by 87ASC »

feyd wrote:Switch in_array() for array_key_exists().
Great! It work's! How is it that array_key_exists() work's instead of in_array()? How do make a newline? I read that you would have to make a new:

Code: Select all

<?php
?>
Their has to be a easier way.
Thank's.
Post Reply