There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot computer connection crash css dell drive driver drivers email error ethernet excel explorer firefox firefox 3 hard drive internet internet explorer itunes laptop linux malware monitor network networking outlook outlook 2003 outlook express password printer problem problems ram router security slow software sound sprtcmd.exe trojan usb virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
PHP script syntax help


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
lightnb's Avatar
Senior Member with 780 posts.
 
Join Date: Jun 2002
Location: Seattle
Experience: Advanced
05-May-2006, 01:55 AM #1
PHP script syntax help
I'm working on a script that takes all the values in a form, and calculates what it can based on which fields the user filed in.

I have created a rough outline, but don't know all of the correct syntax to use, especially the parts where it needs to go back to the begining, and the math functions.

If somone could correct the code for just one of the lines, I could probably figure out the rest from that.

thanks,

Nick


PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<?PHP


//when the user clicks the calculate button, get these variables from the form fields, and start running the script

$HD;
$VD;
$TD;

$Dv;
$Dh;

$PC;
$FC;

$V;
$A;
$W;

$FA;
$MFv;
$MFh;

$GT1
$GT2

//begin executing the script

//we check to see if the user has filled in at least two variables

if at least two of the varibles are set {continue the script}else{die 'you must fill in at least two felds before calculating!!'};

//Check if when can solve for TD, or if TD was specified by the user.

if $TD isset {if $TD == anything thats not a number{die 'td must be a number!!'};
if 
$HD isset {if $HD == anything thats not a number{die 'hd must be a number!!'};
if 
$VD isset {if $VD == anything thats not a number{die 'vd must be a number!!'};

if 
user gives $HD and $VD and $TD {if $HD squared times $VD squared $TD squared, do nothing and continue the script
}else{die "We're sorry, but you can't change the laws of physics!"};

// solve for TD
if user gives $HD and $VD and NOT $TD {solve for $TD, and set $TD the answer};

if 
user gives $TD and not $VD and not $HD {continue running the script};






//check if TD, MF, and D exist, and if they are numbers


if $TD isset {if $TD == anything thats not a number{die 'td must be a number!!'};
if 
$Dv isset {if $Dv == anything thats not a number{die 'd must be a number!!'};
if 
$Dh isset {if $Dh == anything thats not a number{die 'd must be a number!!'};
if 
$MFh isset {if $MFh == anything thats not a number{die 'mfh must be a number!!'};
if 
$MFv isset {if $MFv == anything thats not a number{die 'mfv must be a number!!'};



//check for and solve possible variances of d = mf * td for the verticle axis

if the user is stupid and gives us Dv and MFv and TD {we chack to see if dv=mfv*TD, and if it doeswe ignore it, and continue} else {die 'We remind them that physics cannot be altered!!!'};

if 
we have TD and MFv and not Dv {solve for D using MFv TD and set $Dv to the answer}

else if 
we have TD and Dv and not MFv {solve for MFv using D TD and set $mfv to the answer}

else if 
we have Dv and MFv and not TD {solve for TD using Dv /MFv and set $TD to the answer};




//check for and solve possible variances of d = mf * td for the horizontal axis

if we have TD and MFh and not Dh {solve for Dh using MFh TD and set $Dh to the answer};

if 
we have TD and Dh and not MF {solve for MFh using Dh TD and set $mfh to the answer};

if 
we have Dh and MFh and not TD {solve for TD using Dh /MFh and set $TD to the answer};

if 
the user is stupid and gives us Dh and MFh and TD {we chack to see if dh=mfh*TD, and if it doeswe ignore it, and continue} else {die 'We remind them that physics cannot be altered!!!'};




//we check if we have FA, and if it's a number (we already know MF is a number, or we would have died)

if $FA isset {if $FA == anything thats not a number{die 'FA must be a number!!'};

//we solve for variances of mf=2 x TAN (FA/2)

if we have MF and not FA {we solve for FA, and set $FA to the answer};
if 
we have FA and not MF {we solve for MF, and set $MF to the answer};

//if we have MF now and didn't before, we go back to the top of the script (where is says 'begine executing the script'), and run it again now that we have a new variable set

if we have MF now and didnt before {go back to top and run again with the new variable};




//we check and see if we have pc and if its a number

if $PC isset {if $PC == anything thats not a number{die 'pc must be a number'};

//conver the gel transmission rates from percents to decimals, if they exist

if $GT1 {we convert the percent entered by the user to a decimal and save it to $GT1};
if 
$GT2 {we convert the percent entered by the user to a decimal and save it to $GT2};

// if we can, we consider the gel transmission before going on


if $FC isset and $PC !isset {
    if 
$FC and $GT1 and not $GT2 isset {solve for $PC using FC/$GT1=$PC and save the answer as $PC
    
}else if{ $FC and $GT2 and not $GT1 isset {solve for $PC using FC/$GT2=$PC and save the answer as $PC
    
}else if{ $FC and $GT1 and $GT2 isset {solve for $PC using FC/$GT2/$GT1=$PC and save the answer as $PC};
    
    

if 
$FC and $GT1 isset {multiple $FC by $GT1 and save the answer as $FC}
if 
$FC and $GT2 isset {multiple $FC by $GT2 and save the answer as $FC}

//we solve for variances of fc= pc /(tdv squared)

if we have PC and TD and not FC {we solve for PC, and set $PC to the answer and if $GT1 isset {we multiply the new $FC by $GT1 and store the answer as $FC} and if $GT2 isset, we multiple $FC by $GT2 as well, and aginstore the answer as $FC

}else if we have FC and TD and not PC {we solve for PC, and set $FC to the answer

}else if we have PC and FC and not TD {we solve for TD and set $TD the answer

}else if we dont have PC and dont have FC and dont had TD {we ignore this set, and carry on

}else if we have TD and FC and PC {if FC and PC and TD calculate out corectly {carry on}else{die 'physics cannot be changed'};


//if we have TD now and didn't before, we go back to the top of the script (where is says 'begine executing the script'), and run it again now that we have a new variable set

if we have TD now and didnt before {go back to top and run again with the new variable};

//Now that we have out answers, lets spit them out, and go to bed, since it's 4 AM

if $MFv isset {spit it out into the approprate field on the form];
if 
$MFh isset {spit it out into the approprate field on the form];
if 
$GT1 isset {spit it out into the approprate field on the form];
if 
$GT2 isset {spit it out into the approprate field on the form];
if 
$HD isset {spit it out into the approprate field on the form];
if 
$VD isset {spit it out into the approprate field on the form];
if 
$TD isset {spit it out into the approprate field on the form];
if 
$Dv isset {spit it out into the approprate field on the form];
if 
$Dh isset {spit it out into the approprate field on the form];
if 
$PC isset {spit it out into the approprate field on the form];
if 
$FC isset {spit it out into the approprate field on the form];
if 
$FA isset {spit it out into the approprate field on the form];
if 
$V isset {spit it out into the approprate field on the form];
if 
$A isset {spit it out into the approprate field on the form];
if 
$W isset {spit it out into the approprate field on the form];


?>
</body>
</html>
lightnb's Avatar
Senior Member with 780 posts.
 
Join Date: Jun 2002
Location: Seattle
Experience: Advanced
05-May-2006, 02:09 AM #2
is this valid to see if the variable isn't a number?

PHP Code:
if $TD isset {if !is_numeric($TD){die 'td must be a number!!'}; 
kbazsi's Avatar
Member with 31 posts.
 
Join Date: Mar 2006
Location: Romania
Experience: Intermediate
05-May-2006, 09:04 AM #3
The correct syntax is:
PHP Code:
if( isset( $TD ) ) { if( !is_numeric($TD) ){ die( 'td must be a number!!' ); } } 
lightnb's Avatar
Senior Member with 780 posts.
 
Join Date: Jun 2002
Location: Seattle
Experience: Advanced
05-May-2006, 05:35 PM #4
Thank you.

How do you do the more advanced ones where there are multiple conditions?

PHP Code:
if( isset( $TD ) and isset($MF) and !isset($Dv) ) { multiply($TD $MF ), and store answer as ($Dv);} 
thanks again.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:33 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.