5 Replies - 1422 Views - Last Post: 17 March 2013 - 05:43 AM Rate Topic: -----

#1 Chrisangel29  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 89
  • Joined: 25-January 13

Best way to get values in the same page ..(newbie)

Posted 17 March 2013 - 04:45 AM

Hello guys..is this the best way to get values in the same page and is this style good for writing php+html in the same page?
thankss :bigsmile:





<html>
<head>
</head>
<body>
     
     <b> Submit your infromation </b>
	 <br>
	 
     <form action = "FirstPage.php" method = "post">
	        First name: <input type = "text"   name  = "firstname" >     <br>
            Last  name: <input type = "text"   name  = "lastname"  >     <br>
			            <input type = "submit" value = "Submit"    >	
                        <input type = "reset"  value = "Reset"     >						
	 </form>
	  
</body>
</html>

 <?php	
 
     if (isset($_POST['firstname']) && isset($_POST['lastname']) )
     {
		 echo  'Firstname : '.$_POST['firstname']
			   .'<br>'.
		       'Lastname  : '.$_POST['lastname']
			   .'<br>';
			   
			   $firstName = $_POST['firstname'];
			   if( $firstName == 'mark' )
			   {
			       echo 'hello loser';
			   }
			       echo 'Not gonna happen today';
     }	 	 
 ?>





This post has been edited by Chrisangel29: 17 March 2013 - 05:08 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Best way to get values in the same page ..(newbie)

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3325
  • View blog
  • Posts: 11,246
  • Joined: 12-December 12

Re: Best way to get values in the same page ..(newbie)

Posted 17 March 2013 - 05:07 AM

It is the preferred modern approach to keep HTML separate from PHP. There is a tutorial here.

I would be more concerned about your poorly formed HTML page. In particular, the values you echo will be beyond the closing HTML-tag, which is invalid. I appreciate that this is just a rough sample, but I feel obliged to advise you:

All pages should have a valid DOCTYPE declaration;
All pages require a TITLE tag;
Don't use redundant, non-semantic, BR tags - learn to use CSS to format your page for display;
Give your form an ID.
Was This Post Helpful? 1
  • +
  • -

#3 Chrisangel29  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 89
  • Joined: 25-January 13

Re: Best way to get values in the same page ..(newbie)

Posted 17 March 2013 - 05:10 AM

Thanks man could you please edit my code and send me how it would be the correct way?

This post has been edited by Dormilich: 17 March 2013 - 01:19 PM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3325
  • View blog
  • Posts: 11,246
  • Joined: 12-December 12

Re: Best way to get values in the same page ..(newbie)

Posted 17 March 2013 - 05:14 AM

Yeah, no, not really. There are plenty of tutorials available, or books :)/>

This post has been edited by Dormilich: 17 March 2013 - 01:19 PM

Was This Post Helpful? -1
  • +
  • -

#5 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3325
  • View blog
  • Posts: 11,246
  • Joined: 12-December 12

Re: Best way to get values in the same page ..(newbie)

Posted 17 March 2013 - 05:27 AM

Well.. just to point you in the right direction:

<!DOCTYPE html>
<html>
<head>
    <title>An Important Title</title>
    <style type="text/css">
    /* create your css rules here. Or, preferably,
     * in an attached stylesheet. */
    </style>
</head>
<body>
     <h1>Submit your information</h1>
	 
     <form id="frmFirst" action="FirstPage.php" method="post">
        <label for="firstname">First name:</label>
	    <input type="text" name="firstname" id="firstname">
        <label for="lastname">Last name:</label>
        <input type="text" name  = "lastname" id="lastname">
		<input type="submit" value="Submit">	
        <input type="reset"  value="Reset">						
	 </form>
 <?php
     if (isset($_POST['firstname']) && isset($_POST['lastname']) ) {
		echo  "<p>Firstname : {$_POST['firstname']}</p>" .
		       "<p>Lastname  : {$_POST['lastname']}</p>";
			   
		$firstName = $_POST['firstname'];
        if ( $firstName == 'mark' ) {
            echo 'hello loser';
        } else {
            echo 'Not gonna happen today';
        }	       
     }	 	 
 ?>
</body>
</html>

This post has been edited by andrewsw: 17 March 2013 - 05:28 AM

Was This Post Helpful? 1
  • +
  • -

#6 Chrisangel29  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 89
  • Joined: 25-January 13

Re: Best way to get values in the same page ..(newbie)

Posted 17 March 2013 - 05:43 AM

Thanks for your time

This post has been edited by Dormilich: 17 March 2013 - 01:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1