Jpower24 Posted February 12, 2007 Share Posted February 12, 2007 I need to create a php script to.... declare and assign 3 integer variables, one for house number one for zip code and one for the area code. Use echo() statements to print each variable along with gettype() to assure each variable is of data type integer. I appreciate any help as I have almost no experience with php. Reply here or Jpower24@hotmail.com Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/ Share on other sites More sharing options...
The Little Guy Posted February 12, 2007 Share Posted February 12, 2007 <?php $house_addr = gettype(1234); $zip = gettype(12345); $area_code = gettype(123); if($house_addr != "integer"){ # tell users wrong datatype }else{ #run your house_addr code } if($zip != "integer"){ # tell users wrong datatype }else{ #run your zip code }if($area_code != "integer"){ # tell users wrong datatype }else{ #run area_code code } ?> Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/#findComment-182851 Share on other sites More sharing options...
Jpower24 Posted February 13, 2007 Author Share Posted February 13, 2007 im having a bit of trouble with that, i run it and nothing comes up. I think im supposed to use the echo command as echo 'text here'. Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/#findComment-183761 Share on other sites More sharing options...
wildteen88 Posted February 13, 2007 Share Posted February 13, 2007 If you use that code provided by The Little Guy then nothing will come up as you are not echo'ing anything. To make it echo something just add echo 'whatever' where the comments are in the if/else statements code blocks. A code block is defined in between the curly braces { and } Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/#findComment-183771 Share on other sites More sharing options...
Jpower24 Posted February 13, 2007 Author Share Posted February 13, 2007 I thought maybe # was short for echo. So now that that is cleared up, it's just one last thing. how could I make it echo the values back. something like echo 'The address is $house_addr' Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/#findComment-183777 Share on other sites More sharing options...
The Little Guy Posted February 13, 2007 Share Posted February 13, 2007 ues one of these: echo 'The address is '.$house_addr; or echo "The address is $house_addr"; Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/#findComment-183778 Share on other sites More sharing options...
wildteen88 Posted February 13, 2007 Share Posted February 13, 2007 Use double quotes instead if you want to echo variables values in a string. If you use single quotes PHP will treat variables as normal text (as-is). So use echo "The address is $house_addr"; instead or you can use concatenation (See The Little Guy's example above in his post) Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/#findComment-183779 Share on other sites More sharing options...
Jpower24 Posted February 13, 2007 Author Share Posted February 13, 2007 alright so now I have this. <?php $house_addr = gettype(1234); $zip = gettype(12345); $area_code = gettype(123); if($house_addr != "integer"){ echo "The number of the house is $house_addr"; } if($zip != "integer") { echo "The zip code is $zip"; } if($area_code != "integer"){ echo "The area code is $area_code"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/#findComment-183798 Share on other sites More sharing options...
wildteen88 Posted February 13, 2007 Share Posted February 13, 2007 And whats wrong with it now/what are you trying to do with it now. Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/#findComment-183802 Share on other sites More sharing options...
Jpower24 Posted February 13, 2007 Author Share Posted February 13, 2007 well I try and run it and get a blank screen. Theres a good chance, i don't know how to run it. If looks like it will run to you guys though thats good enough for me. Quote Link to comment https://forums.phpfreaks.com/topic/38192-solved-help-needed-beginner-here/#findComment-183812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.