Forum Moderators: coopster
I am trying to work out valid VAT number by having user input a number in 9 individual cells, mutliplying each of the first 7 cell by a different sum. Then adding these together and doing a sum to calculate valid vat number. Hopes this make sense?
/* check vat number
$vat1='($a*8)+($b*7)+($c*6)+($d*5)+($e*4)+($f*3)+($g*2)';
$vat2='($vat1-97)';
$vat3='($h*10)+($j)';
if ($vat2 > -9)
{
$vat2='($vat2-97)';
if ($vat2 > -9)
{
$vat2='($vat2-97)';
if ($vat2 > -9)
{
if ($vat2!= '$vat3')
{
unset($do);
$message_new = "VAT Number not valid";
include("login_form.inc");
exit();
}
}
}
}
else
{
$VAT_no='$a,$b,$c,$d,$e,$f,$g," ",$h,$j';
$today = time("Y-m-d");
$sql = "INSERT INTO member (loginName,createDate,password,firstName,lastName,company,address1,address2,
town,county,postcode,email,phone,fax,VAT_no) VALUES
('$newname','$today','$newpass','$firstName','$lastName','$company','$address1','$address2',
'$town','$county','$postcode','$email','$phone','$fax','$VAT_no')";
mysql_query($sql);
$xsql = "INSERT INTO vat (LoginName,a,b,c,d,e,f,g,h,j,VAT_no) VALUES
('$newname','$a','$b','$c','$d','$e','$f','$g','$h','$j','$VAT_no')";
It doesn't actually come up with a error at all. It just ignores the script.
In UK we have VAT numbers. I want a member entering a VAT number into seperate fields like this:
1 2 3 4 5 6 7 8 2
To work out a valid vat number the first seven numbers are added like this:
$vat1=(1*8)+(2*7)+(3*6)+(4*5)+(5*4)+(6*3)+(7*2).
=112
then 97 is to be subtracted from this number until is reached a two numbered minus number. Eg.
112-97=15
15-97=-82
This should equal the last two numbers of VAT (ie.8 2).
I hope this explains what I am trying to do. It's hard to explain.
Chris
Don't write $a = '2 + 3' because that's a string. SO if you put:
$a = 1;
$b = 2;//and write:
$val = '$a + $b';//you'll get a string with exactly this: $a + $b, and not 3.
(if you write a variable between ' ' it is not processed as a variable, but as a text.
Write:
/* check vat number *///You have to end this comment opening. It must go in pairs: /* */. The sign // comments the one line
$vat1 = $a*8 + $b*7 + $c*6 + $d*5 + $e*4 + $f*3 + $g*2;//multiplying is done before adding
$vat2 = $vat1 - 97;//I recommend using space between dash, sometimes it can be seen as part of a variable
$vat3 = $h*10 + $j;
if ($vat2 > -9)
{
$vat2 = $vat2 - 97;
if ($vat2 > -9)
{
$vat2 = $vat2 - 97;
if ($vat2 > -9)
{
if ($vat2!= $vat3)//here you had if $vat2 is different than a string: $var3 (not what's in that variable). So it was always true, however as you didn't end the */ nothing was evaluated:)
{
unset($do);
$message_new = "VAT Number not valid";
include("login_form.inc");
exit();
}
}
}
}
else
{
$VAT_no = $a.$b.$c.$d.$e.$f.$g." ".$h.$j;//dot is the sticking char, not comma. I suppose you wanted the number to be eg. 1234567 12, not 1,2,3,4,5,6, ,1,2?
$today = time("Y-m-d");
$sql = "INSERT INTO member (loginName,createDate,password,firstName,lastName,company,address1,address2,
town,county,postcode,email,phone,fax,VAT_no) VALUES
('$newname','$today','$newpass','$firstName','$lastName','$company','$address1','$address2',
'$town','$county','$postcode','$email','$phone','$fax','$VAT_no')";//here the '$var' will work as '2', because you started the string with " " and not with ' '
mysql_query($sql) or die(mysql_error()); //for the sake of debugging I recommend all errors reporting
$xsql = "INSERT INTO vat (LoginName,a,b,c,d,e,f,g,h,j,VAT_no) VALUES
('$newname','$a','$b','$c','$d','$e','$f','$g','$h','$j','$VAT_no')"; //do you really need the $a, $b? You have them already in $VAT_no
Name chaps comes from abbreviation of the full name: CHór Akademicki Politechniki Szczecinskiej (Technical University of Szczecin Academic Choir). Szczecin is the city where I live (Poland).
Now, however it comes up with this error:
Parse error: parse error, unexpected T_DEFAULT in d:\inetpub\wwwroot\clientwebspace\www.sculpturesofafrica.com\Login\Login.php on line 166
The program was working before I added the code for the VAT checker. can you explain this?
Thanks, Michal.
Chris
T_ means type, so the error means that somewhere in the code you have variable that shouldn't be there. eg this code will return error: if($a $b = 1;, because the bracket ) is missing, however the error will be: parse error, unexpected T_VARIABLE in ... line ... So you see, the solution is not what the parser thinks.
You might be missing a ), }, ;, " or '. So just post the lines, or try to find error on your own.
Also a good way to finding an error is to comment few lines of the code and seeing if it compiles then, then the error is in those few lines.
Good luck!
Michal Cibor