Page 1 of 1

VIN Decoder Help

Posted: Sat Aug 25, 2007 3:52 am
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]

Posted: Sat Aug 25, 2007 6:05 am
by feyd
You're missing quotes around the strings you are attempting to echo, which is most likely the error you are getting.

Posted: Sat Aug 25, 2007 6:30 am
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.

Posted: Sat Aug 25, 2007 7:05 am
by feyd
Read the manual's page on strings: http://php.net/language.types.string

Posted: Sat Aug 25, 2007 8:14 pm
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.

Posted: Sat Aug 25, 2007 10:48 pm
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';
}

Posted: Sun Aug 26, 2007 1:35 am
by RobertGonzalez
Or perhaps even a switch() statement?

Posted: Sun Aug 26, 2007 4:06 am
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.

Posted: Sun Aug 26, 2007 7:54 am
by feyd

Posted: Sun Aug 26, 2007 8:33 am
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.