PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 12th, 2013, 12:39 PM
dlmagers dlmagers is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Location: Rocky Mount, NC
Posts: 16 dlmagers User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 38 m 11 sec
Reputation Power: 0
Send a message via Yahoo to dlmagers
Facebook
PHP-General - Just a Simple PHP form Processing Freelance

Hello, I am trying to teach myself how to process a simple form in php. Here is what I want to do. I have a simple form.html document and I want to have input fields for First Name and Last Name and Gender.

The Gender field I want to be able to send them the right message if they enter 'M' for Male or 'F' for Female I want to be able to say something like 'Welcome 'Mr or Mrs' First Name and Last Name' in an echo statement.

Here is the code I have thus far.
I have this in the body of my welcome.php page

Code:
 <?php

//import form information 
$first = $_POST['first'];
$last = $_POST['last'];
$gender = $_POST['gender'];


 
 if($gender=="M"){
	 echo Thank you for your submission;
	 echo 'Hello, Mr. <?php echo $first $last ?>, Welcome to my Portfolio!  I will be getting back with you as soon as possible';
 }elseif($gender == 'F'){
 	 echo 'Thank you for your submission';
	 echo 'Hello, Mrs. <?php echo $first $last ?> Welcome to my Portfolio!  I will be getting back with you as soon as possible'; 
 }
 ?>


And here is my form on my html page

Code:
<form method="post" action="welcome.php">
                
                <p>
                  <label for="first">First Name:</label> 
                  <input type="text" name="$first" id="first"><br />
                  <label for="last">Last Name:</label> 
                  <input type="text" name="$last" id="last"><br />
                  <label for="gender">Type 'M' for Male or 'F' for Female:</label>
                  <input type="text" name="$gender" id="gender" /><br />
                    
                  <br>
                </p>
                
                <input id="subbut" type="submit" value="Send Comment">
</form>


I am not sure what is going on. From all the books I have read and tutorials on the internet I still get a error message through Dreamweaver.

Would someone be so kindto point me in the right direction. I would greatly appreciate it.

Thank you in advance.

Reply With Quote
  #2  
Old February 12th, 2013, 12:51 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
1) Please enclose your code in [ PHP ] tags. See the sticky at the top of this forum.
2) What error are you getting? Dreamweaver only does a fair job of warning you about HTML errors but it does nothing about PHP errors. It just helps to a limited extent by formatting your PHP for you.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old February 12th, 2013, 01:01 PM
Nanomech's Avatar
Nanomech Nanomech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: The Pleiades
Posts: 192 Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 23 h 7 m 18 sec
Reputation Power: 7
Send a message via Skype to Nanomech
You do know that 'm' is not the same as 'M' and 'f' is not the same as 'F'. Don't allow your program too much room for mistakes.

Give them 2 radio buttons.
Code:
Male<input type="radio" name="gender" value="Male" /><br />
Female:<input type="radio" name="gender" value="Female" />


Then change your welcome.php to this:
PHP Code:
//import form information 
$first $_POST['first'];
$last $_POST['last'];
$gender $_POST['gender'];


 if(
$gender=="Male"){
     echo 
"Thank you for your submission";
     echo 
"Hello, Mr. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible";
 }else(
$gender == "Female"){
      echo 
"Thank you for your submission";
     echo 
"Hello, Mrs. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible"
 } 


You had a few errors; no quotations around your first string, use of open and closing <php?> tags while already in 'PHP mode' and an unnecessary 'elseif' statement because there is only 2 possible answers, so it's either one or the other so you only need an if else, not an if elseif else. Be aware if you use an if elseif, then you MUST have an 'else' statement ending the elseif. You can do an 'if' on it's own though without an else. Still use a textbox to get their names but in cases when you know there is a limited amount of possible values and only certain ones, you should display a drop down list, or checkboxes/radio buttons IMO.

Hope this helps.

Regards,

NM.
__________________
"WERE NOT WORTHY!"
"WERE NOT WORTHY!"

Last edited by Nanomech : February 12th, 2013 at 01:05 PM.

Reply With Quote
  #4  
Old February 12th, 2013, 01:31 PM
dlmagers dlmagers is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Location: Rocky Mount, NC
Posts: 16 dlmagers User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 38 m 11 sec
Reputation Power: 0
Send a message via Yahoo to dlmagers
Facebook
Still something not right

I tried the code

Code:
<form method="post" action="welcome.php">
                
                <p>
                  <label for="first">First Name:</label> 
                  <input type="text" name="$first" id="first"><br />
                  <label for="last">Last Name:</label> 
                  <input type="text" name="$last" id="last"><br />
                  Male<input type="radio" name="gender" value="Male" /><br />
				  Female:<input type="radio" name="gender" value="Female" />
                    
                  <br>
                </p>
                
                <input id="subbut" type="submit" value="Send Comment">
</form>


for my html document and for that welcome.php file I changed the code to the following:

Code:
 <?php
//import form information  
$first = $_POST['first']; 
$last = $_POST['last']; 
$gender = $_POST['gender']; 


 if($gender=="Male"){ 
     echo "Thank you for your submission"; 
     echo "Hello, Mr. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible";
  }else($gender == "Female"){ 
      echo "Thank you for your submission"; 
     echo "Hello, Mrs. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible"; 
  }
  ?>


The response that I first got wanted to see the entire code which is:

Code:

<!DOCTYPE html>
<html lang="en">
<head>


        <meta charset="utf-8">
        <title>Diana Magers | Contact Page</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="#">
        <meta name="author" content="Diana Magers">
        
        <link rel="stylesheet" media="screen,projection" href="css/ui.totop.css" />
        
        <link href="./css/style.css" rel="stylesheet">
        <link rel="stylesheet" href="css/easy.css" media="screen" />
		<link rel="stylesheet" href="css/easyprint.css" media="print" />

     

<style type="text/css">
		@import url("css/Prociono_Regular/stylesheet.css");
		@import url("css/Vollkorn/stylessheet.css");

		
		 h4 {
			font-size: 24px;
			color: #F3C;
			font-family:Vollkorn;
		}
		
	
		 h2 {
			font-family: 'VollkornRegular';
		}
		
		 p {
	font-family: Vollkorn;
	font-size: x-large;
	color: #003;
	padding-left: 50px;
		}
		
.background-illusion .container div p {
	font-size: 16px;
}
</style>



        <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]--> 
        
        <script src="jquery.min.js" type="text/javascript"></script> 
       	<script type="text/javascript" src="js/easy.js"></script>
		<script type="text/javascript" src="js/main.js"></script>
        <script src="./js/less.js"type="text/javascript"></script>
        <script src="./js/cufon.js"type="text/javascript"></script>
        <script src="jquery.min.js" type="text/javascript"></script> 
        
        







</head> 
<body>
        <header class="background-illusion">
        <img src="./img/logo1.png" class="logo" alt="" /></header>
        
<div class="container">
        <h1><span class="left">Contact</span><span class="right">Me</span></h1>
 <p>&nbsp;</p>
              <p>&nbsp;</p>
  <?php
//import form information  
$first = $_POST['first']; 
$last = $_POST['last']; 
$gender = $_POST['gender']; 


 if($gender=="Male"){ 
     echo "Thank you for your submission"; 
     echo "Hello, Mr. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible";
  }else($gender == "Female"){ 
      echo "Thank you for your submission"; 
     echo "Hello, Mrs. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible"; 
  }
  ?>
</div>
        <div id="toTop"></div>        
        
<footer class="background-illusion">
            <div class="container">
               


              </div>
  </div>
</footer>
        
        	<!-- jquery -->	
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
	<!-- easing plugin ( optional ) -->
<script src="js/easing.js" type="text/javascript"></script>
	<!-- UItoTop plugin -->
<script src="js/jquery.ui.totop.js" type="text/javascript"></script>
	<!-- Starting the plugin -->
<script type="text/javascript">
		$(document).ready(function() {
			
			var defaults = {
	  			containerID: 'toTop', // fading element id
				containerHoverID: 'toTopHover', // fading element hover id
				scrollSpeed: 1200,
				easingType: 'linear' 
	 		};
			
			
			$().UItoTop({ easingType: 'easeOutQuart' });
			
		});
	</script>
    
	
</body>
</html>


And here is my index.html file

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Diana Magers | Contact Me</title>
        
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="#">
        <meta name="author" content="Diana Magers">
        
        <link rel="stylesheet" media="screen,projection" href="css/ui.totop.css" />
        
        <link href="./css/style.css" rel="stylesheet">
        <link rel="stylesheet" href="css/easy.css" media="screen" />
		<link rel="stylesheet" href="css/easyprint.css" media="print" />

     

<style type="text/css">
		@import url("css/Prociono_Regular/stylesheet.css");
		@import url("css/Vollkorn/stylessheet.css");

		
		 h4 {
			font-size: 24px;
			color: #F3C;
			font-family:Vollkorn;
		}
		
	
		 h2 {
			font-family: 'VollkornRegular';
		}
		
		 p {
	font-family: Vollkorn;
	font-size: x-large;
	color: #003;
	margin-top: 25px;
	margin-right: auto;
	margin-bottom: 25px;
	margin-left: auto;
		}
		
.background-illusion .container div p {
	font-size: 16px;
}
</style>


        <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]--> 
        
        <script src="jquery.min.js" type="text/javascript"></script> 
       	<script type="text/javascript" src="js/easy.js"></script>
		<script type="text/javascript" src="js/main.js"></script>
        <script src="./js/less.js"type="text/javascript"></script>
        <script src="./js/cufon.js"type="text/javascript"></script>
        <script src="jquery.min.js" type="text/javascript"></script> 
        
       

</head> 
<body>
        <header class="background-illusion">
        <img src="./img/logo1.png" class="logo" alt="" /></header>
        
        <div class="container">
        <h1><span class="left">Contact</span><span class="right">Me</span></h1>
       
       
        <form method="post" action="welcome.php">
                
                <p>
                  <label for="first">First Name:</label> 
                  <input type="text" name="$first" id="first"><br />
                  <label for="last">Last Name:</label> 
                  <input type="text" name="$last" id="last"><br />
                  Male<input type="radio" name="gender" value="Male" /><br />
				  Female:<input type="radio" name="gender" value="Female" />
                    
                  <br>
                </p>
                
                <input id="subbut" type="submit" value="Send Comment">
</form>

</div>
        <div id="toTop"></div>        
        
<footer class="background-illusion">
            <div class="container">
                <div align="center">
                  <p>Copyright © 2013 | <a href="http://dianamagers.com">Diana Magers</a> | Spring Semester 2013 </p>
                  <p>&nbsp;</p>
                  <script language="javascript">
<!--
document.write("<i>Last updated "+document.lastModified+"<I>");
//--></script>


                </div>
            </div>
        </footer>
        
        	<!-- jquery -->	
	<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
	<!-- easing plugin ( optional ) -->
	<script src="js/easing.js" type="text/javascript"></script>
	<!-- UItoTop plugin -->
	<script src="js/jquery.ui.totop.js" type="text/javascript"></script>
	<!-- Starting the plugin -->
	<script type="text/javascript">
		$(document).ready(function() {
			
			var defaults = {
	  			containerID: 'toTop', // fading element id
				containerHoverID: 'toTopHover', // fading element hover id
				scrollSpeed: 1200,
				easingType: 'linear' 
	 		};
			
			
			$().UItoTop({ easingType: 'easeOutQuart' });
			
		});
	</script>
    
	
</body>
</html>


Reply With Quote
  #5  
Old February 12th, 2013, 01:42 PM
Nanomech's Avatar
Nanomech Nanomech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: The Pleiades
Posts: 192 Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 23 h 7 m 18 sec
Reputation Power: 7
Send a message via Skype to Nanomech
Make index.html into index.php . You can't run PHP in a .html file unless you change a specific value in a PHP's .htaccess file.

I still don't understand where welcome.php comes into it. The first code block's <title> is 'Contact Us' and the second is your index.html.

Try what I said and I think it should work. Try changing the 'action' attribute of your form to 'index.php'. Then change index.html to index.php and put your form processing code at the VERY TOP of yourdocument, even before your HTML doctype.

Regards,

NM.

Last edited by Nanomech : February 12th, 2013 at 01:45 PM.

Reply With Quote
  #6  
Old February 12th, 2013, 03:01 PM
dlmagers dlmagers is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Location: Rocky Mount, NC
Posts: 16 dlmagers User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 38 m 11 sec
Reputation Power: 0
Send a message via Yahoo to dlmagers
Facebook
Ok check this out

http://dianamagers.com/Contact/index.php


This is the source code

Code:
 <?php
//import form information  
$first = $_POST['first']; 
$last = $_POST['last']; 
$gender = $_POST['gender']; 


 if($gender=="Male"){ 
     echo "Thank you for your submission"; 
     echo "Hello, Mr. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible";
  }else($gender == "Female"){ 
      echo "Thank you for your submission"; 
     echo "Hello, Mrs. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible"; 
  }
  ?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Contact Me</title>
        
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="#">
        <meta name="author" content="Diana Magers">
        
        <link rel="stylesheet" media="screen,projection" href="css/ui.totop.css" />
        
        <link href="./css/style.css" rel="stylesheet">
        <link rel="stylesheet" href="css/easy.css" media="screen" />
		<link rel="stylesheet" href="css/easyprint.css" media="print" />

     

<style type="text/css">
		@import url("css/Prociono_Regular/stylesheet.css");
		@import url("css/Vollkorn/stylessheet.css");

		
		 h4 {
			font-size: 24px;
			color: #F3C;
			font-family:Vollkorn;
		}
		
	
		 h2 {
			font-family: 'VollkornRegular';
		}
		
		 p {
	font-family: Vollkorn;
	font-size: x-large;
	color: #003;
	margin-top: 25px;
	margin-right: auto;
	margin-bottom: 25px;
	margin-left: auto;
		}
		
.background-illusion .container div p {
	font-size: 16px;
}
</style>


        <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]--> 
        
        <script src="jquery.min.js" type="text/javascript"></script> 
       	<script type="text/javascript" src="js/easy.js"></script>
		<script type="text/javascript" src="js/main.js"></script>
        <script src="./js/less.js"type="text/javascript"></script>
        <script src="./js/cufon.js"type="text/javascript"></script>
        <script src="jquery.min.js" type="text/javascript"></script> 
        
       

</head> 
<body>
        <header class="background-illusion">
        <img src="./img/logo1.png" class="logo" alt="" /></header>
        
        <div class="container">
        <h1><span class="left">Contact</span><span class="right">Me</span></h1>
      
       
        <form method="post" action="index.php">
                
                <p>
                  <label for="first">First Name:</label> 
                  <input type="text" name="$first" id="first"><br />
                  <label for="last">Last Name:</label> 
                  <input type="text" name="$last" id="last"><br />
                  Male<input type="radio" name="gender" value="Male" /><br />
				  Female:<input type="radio" name="gender" value="Female" />
                    
                  <br>
                </p>
                
                <input id="subbut" type="submit" value="Send Comment">
</form>

</div>
        <div id="toTop"></div>        
        
<footer class="background-illusion">
            <div class="container">
                <div align="center">
                  <p>Copyright © 2013 | <a href="http://dianamagers.com">Diana Magers</a> | Spring Semester 2013 </p>
                  <p>&nbsp;</p>
                  <script language="javascript">
<!--
document.write("<i>Last updated "+document.lastModified+"<I>");
//--></script>


                </div>
            </div>
        </footer>
        
        	<!-- jquery -->	
	<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
	<!-- easing plugin ( optional ) -->
	<script src="js/easing.js" type="text/javascript"></script>
	<!-- UItoTop plugin -->
	<script src="js/jquery.ui.totop.js" type="text/javascript"></script>
	<!-- Starting the plugin -->
	<script type="text/javascript">
		$(document).ready(function() {
			
			var defaults = {
	  			containerID: 'toTop', // fading element id
				containerHoverID: 'toTopHover', // fading element hover id
				scrollSpeed: 1200,
				easingType: 'linear' 
	 		};
			
			
			$().UItoTop({ easingType: 'easeOutQuart' });
			
		});
	</script>
    
	
</body>
</html>

Reply With Quote
  #7  
Old February 12th, 2013, 03:03 PM
dlmagers dlmagers is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Location: Rocky Mount, NC
Posts: 16 dlmagers User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 38 m 11 sec
Reputation Power: 0
Send a message via Yahoo to dlmagers
Facebook
Logic

This logic appears correct but it keeps giving me an error is on line 10.

Code:
Parse error: syntax error, unexpected T_VARIABLE, expecting '}' in /hermes/bosoraweb013/b122/ipg.dianamagerscom/Contact/index.php on line 10

Reply With Quote
  #8  
Old February 12th, 2013, 03:53 PM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2003
Posts: 2,476 ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 4 h 17 m 41 sec
Reputation Power: 2194
php Code:
Original - php Code
  1. if($gender=="Male"){
  2.      echo "Thank you for your submission";
  3.      echo "Hello, Mr. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible";
  4.   }else($gender == "Female"){
  5.       echo "Thank you for your submission";
  6.      echo "Hello, Mrs. {$first $last}, Welcome to my Portfolio! I will be getting back with you as soon as possible";
  7.   }


There is no

php Code:
Original - php Code
  1. if (condition) {
  2. } else (condition) {
  3.  
  4. }


construct in PHP. There's

php Code:
Original - php Code
  1. if (condition) {
  2.  
  3. } else if (condition) {
  4.  
  5. }
.

But, unless you're providing more that one gender, a simple if/else

php Code:
Original - php Code
  1. if (condition) {
  2.  
  3. } else {
  4.  
  5. }
should suffice.
__________________
I ♥ ManiacDan & requinix

This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!

Last edited by ptr2void : February 12th, 2013 at 03:58 PM.

Reply With Quote
  #9  
Old February 12th, 2013, 04:07 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 294 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 5 m 6 sec
Reputation Power: 5
Please correct me if I'm wrong, but I believe ptr2void is correct for the most part, cept I don't believe there's exactly a

PHP Code:
if (condition) {
 
} else if (
condition) {
 



but more a

PHP Code:
if (condition) {
 
} elseif (
condition) {
 
} else {




Nanomech did a fair job trying to point this out. This is why your script feels such is missing.

EDIT: And a note... Since you're echo-ing in double quotes, it may also help to remove your curly brackets around the user's name. Or are these to be printed on the visible content page in the end?

EDIT2: And just a thing to throw out there... As far as the female member, perhaps something to decide between Mrs and Ms? Not sure best way to decide this other than directly querying whether married or not. Or perhaps a different manner of referencing male/female? Sir/Madam or such?

Last edited by Triple_Nothing : February 12th, 2013 at 04:12 PM.

Reply With Quote
  #10  
Old February 12th, 2013, 04:13 PM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2003
Posts: 2,476 ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 4 h 17 m 41 sec
Reputation Power: 2194

Reply With Quote
  #11  
Old February 12th, 2013, 04:14 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 294 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 5 m 6 sec
Reputation Power: 5
Removed...

Last edited by Triple_Nothing : February 12th, 2013 at 07:10 PM.

Reply With Quote
  #12  
Old February 12th, 2013, 04:24 PM
dlmagers dlmagers is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Location: Rocky Mount, NC
Posts: 16 dlmagers User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 38 m 11 sec
Reputation Power: 0
Send a message via Yahoo to dlmagers
Facebook
I agree totally

Quote:
Originally Posted by Triple_Nothing
Please correct me if I'm wrong, but I believe ptr2void is correct for the most part, cept I don't believe there's exactly a

PHP Code:
if (condition) {
 
} else if (
condition) {
 



but more a

PHP Code:
if (condition) {
 
} elseif (
condition) {
 
} else {




Nanomech did a fair job trying to point this out. This is why your script feels such is missing.

EDIT: And a note... Since you're echo-ing in double quotes, it may also help to remove your curly brackets around the user's name. Or are these to be printed on the visible content page in the end?

EDIT2: And just a thing to throw out there... As far as the female member, perhaps something to decide between Mrs and Ms? Not sure best way to decide this other than directly querying whether married or not. Or perhaps a different manner of referencing male/female? Sir/Madam or such?


I agree totally. I fixed it to Ms. instead of Mrs. Because you are right in my case I wouldn't want to be called 'Mrs.' since I am not married. Good point.

Reply With Quote
  #13  
Old February 12th, 2013, 04:41 PM
dlmagers dlmagers is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Location: Rocky Mount, NC
Posts: 16 dlmagers User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 38 m 11 sec
Reputation Power: 0
Send a message via Yahoo to dlmagers
Facebook
Made a few changes else if \\ else and Mrs. to Ms.

Made a few changes and after completing the form all it does is clears my selection. In my browser, it says that Gender was not selected before I even start to fill out the form. After filling out the form it comes up what I want but it doesn't display the $first and $last name <variable>. I know I am close to this but I am trying to be patient. I appreciate everyone's help in this matter.

http://dianamagers.com/Contact/index.php

Code:
 <?php
//import form information  
$first = $_POST['first']; 
$last = $_POST['last']; 
$gender = $_POST['gender']; 


 if($gender=="Male"){ 
     echo "Thank you for your submission"; 
     echo "Hello, Mr. $first $last, Welcome to my Portfolio! I will be getting back with you as soon as possible";
  }else if($gender == "Female"){ 
      echo "Thank you for your submission"; 
      echo "Hello, Ms. $first $last, Welcome to my Portfolio! I will be getting back with you as soon as possible"; 
  }else {
		echo "A Gender was not selected";  
  }
 
  ?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Contact Me</title>
        
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="#">
        <meta name="author" content="Diana Magers">
        
        <link rel="stylesheet" media="screen,projection" href="css/ui.totop.css" />
        
        <link href="./css/style.css" rel="stylesheet">
        <link rel="stylesheet" href="css/easy.css" media="screen" />
		<link rel="stylesheet" href="css/easyprint.css" media="print" />

     

<style type="text/css">
		@import url("css/Prociono_Regular/stylesheet.css");
		@import url("css/Vollkorn/stylessheet.css");

		
		 h4 {
			font-size: 24px;
			color: #F3C;
			font-family:Vollkorn;
		}
		
	
		 h2 {
			font-family: 'VollkornRegular';
		}
		
		 p {
	font-family: Vollkorn;
	font-size: x-large;
	color: #003;
	margin-top: 25px;
	margin-right: auto;
	margin-bottom: 25px;
	margin-left: auto;
		}
		
.background-illusion .container div p {
	font-size: 16px;
}
</style>


        <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]--> 
        
        <script src="jquery.min.js" type="text/javascript"></script> 
       	<script type="text/javascript" src="js/easy.js"></script>
		<script type="text/javascript" src="js/main.js"></script>
        <script src="./js/less.js"type="text/javascript"></script>
        <script src="./js/cufon.js"type="text/javascript"></script>
        <script src="jquery.min.js" type="text/javascript"></script> 
        
       

</head> 
<body>
        <header class="background-illusion">
        <img src="./img/logo1.png" class="logo" alt="" /></header>
        
        <div class="container">
        <h1><span class="left">Contact</span><span class="right">Me</span></h1>
      
       
        <form method="post" action="index.php">
                
                <p>
                  <label for="first">First Name:</label> 
                  <input type="text" name="$first" id="first"><br />
                  <label for="last">Last Name:</label> 
                  <input type="text" name="$last" id="last"><br />
                  Male<input type="radio" name="gender" value="Male" /><br />
				  Female:<input type="radio" name="gender" value="Female" />
                    
                  <br>
                </p>
                
                <input id="subbut" type="submit" value="Send Comment">
</form>

</div>
        <div id="toTop"></div>        
        
<footer class="background-illusion">
            <div class="container">
                <div align="center">
                  <p>Copyright © 2013 | <a href="http://dianamagers.com">Diana Magers</a></p>
                  <p>&nbsp;</p>
                  <script language="javascript">
<!--
document.write("<i>Last updated "+document.lastModified+"<I>");
//--></script>


                </div>
            </div>
        </footer>
        
        	<!-- jquery -->	
	<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
	<!-- easing plugin ( optional ) -->
	<script src="js/easing.js" type="text/javascript"></script>
	<!-- UItoTop plugin -->
	<script src="js/jquery.ui.totop.js" type="text/javascript"></script>
	<!-- Starting the plugin -->
	<script type="text/javascript">
		$(document).ready(function() {
			
			var defaults = {
	  			containerID: 'toTop', // fading element id
				containerHoverID: 'toTopHover', // fading element hover id
				scrollSpeed: 1200,
				easingType: 'linear' 
	 		};
			
			
			$().UItoTop({ easingType: 'easeOutQuart' });
			
		});
	</script>
    
	
</body>
</html>

Last edited by dlmagers : February 12th, 2013 at 04:43 PM. Reason: forgot to show my url

Reply With Quote
  #14  
Old February 12th, 2013, 06:47 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 294 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 5 m 6 sec
Reputation Power: 5
A gender was not selected wil display simply because your if/then is running at the loading of the page, even if no submission was made. You are also getting more errors, which I assume your server is not passing on. When arriving at the page initially, you are trying to set some variables from a $_POST[] that was never made.

Just to keep these seperate, I usually write all this upper scripting in a simple if/then inquiring which stage of login we are. The action attribute in your form tag may benifit if changed to something like "index.php?stage=2". Then, wrapping around your top processing, would be an if() statement asking if(isset($_GET['stage']) && $_GET['stage'] == 2) then run those items.

The way you defined your names in the textbox name field is incorrect. Remove the $ from those.

Reply With Quote
  #15  
Old February 12th, 2013, 06:54 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 43 m 47 sec
Reputation Power: 6991
Code:
<label for="first">First Name:</label> 
<input type="text" name="$first" id="first"><br />
<label for="last">Last Name:</label> 
<input type="text" name="$last" id="last"><br />

Your name attributes should not have a $ in front of them.

----

To preserve the submitted values, you must output them back out to the HTML in the value attribute:
PHP Code:
<label for="first">First Name:</label
<
input type="text" name="first" id="first" value="<?php echo htmlentities($first, ENT_QUOTES, 'UTF-8'); ?>"><br />
<
label for="last">Last Name:</label
<
input type="text" name="last" id="last" value="<?php echo htmlentities($last, ENT_QUOTES, 'UTF-8'); ?>"><br /> 


----

To check a radio button by default, you must use the checked attribute:
PHP Code:
<input type="radio" name="gender" value="Male" <?php if($gender == "Male") echo "checked"?> /> 


----

This block will throw errors if your form is on the same page as your processing code:
PHP Code:
 $first $_POST['first']; 
$last $_POST['last']; 
$gender $_POST['gender']; 


Use isset instead:
PHP Code:
 $first = isset($_POST['first']) ? $_POST['first'] : ''
$last = isset($_POST['last']) ? $_POST['last'] : ''
$gender = isset($_POST['gender']) ? $_POST['gender'] : ''


----

If you don't want to display an error message on the initial load, change your }else{ block in the gender check to }elseif(!empty($_POST['gender'])){

Quote:
An if() can run on its own w/o an else, but on a multi-stage, there must be an else at the end.

There is no situation in PHP in which an else block is required.

----

PHP Code:
echo "Hello, Mr. $first $last, Welcome to my Portfolio! I will be getting back with you as soon as possible"

To prevent XSS attacks, you must use htmlentities.

PHP Code:
echo "Hello, Mr. " htmlentities($firstENT_QUOTES'UTF-8') , htmlentities($lastENT_QUOTES'UTF-8') , "Welcome to my Portfolio! I will be getting back with you as soon as possible"
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Just a Simple PHP form Processing Freelance

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap