Results 1 to 6 of 6

Thread: Php Post?

  1. #1
    Join Date
    Jul 2007
    Location
    England
    Posts
    41
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Php Post?

    What I am trying to do is take text from one page, and place it on another page. The text MUST only be between <name="body"> and </name>.

    This is the page with the text on;

    index.htm
    Code:
    <html>
    <body>
    <name="text">
    Hello and welcome to the website.
    </name>
    </body>
    </html>
    Then, I have another page, which the text from index.htm is placed onto;

    show.php
    Code:
    <html>
    <body>
    <?php
    $text = $_POST['text'];
    ?>
    The text you wanted was;
    <?php echo $name ?>
    </body>
    </html>
    Ok, firstly, is there any reason why that wouldn't work?

    Now, what i really came here for;

    I have 3 pages, index.htm, services.htm and help.htm. Each of these will be set up the same as index.htm, with some text in <name> tags.

    When a user click a link, they must go to show.php (the page where the text is placed onto). I want to be able to identify the page from which they came from, and place the text from that page on this show.php.

    If I haven't been very clear, please ask as I rally need this help.

    Thanks

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Well, from what I understand you cannot make something that will do that because <name> isn't a tag. you would need to do this:
    PHP Code:
    <html>
    <
    body>
    <
    p name="text">
    Hello and welcome to the website.
    </
    p>
    </
    body>
    </
    html
    Jeremy | jfein.net

  3. #3
    Join Date
    Jul 2007
    Location
    England
    Posts
    41
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    OK thanks Nile =)

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Can you +thanks me please? By clicking on the
    under my post?
    Jeremy | jfein.net

  5. #5
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Don't think you should ask people to thank you... it's something the poster does at their own will.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Hi MrRSMan,

    Have a look at the following code

    File 1:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    	<head>
    		<title> </title>
    		<style type="text/css">
    		
    		</style>
    		<script type="text/javascript">
    			function redirect(){
    				location.href = "get.php?text=" + document.body.getElementsByTagName('div')[0].getAttribute('text');
    			}
    			
    			function getTheValue(form){
    				var txt = document.createElement('input');
    				txt.type = 'text';
    				txt.value = document.body.getElementsByTagName('div')[0].getAttribute('text');
    				txt.name = 'text';
    				txt.style.display = 'none';
    				form.appendChild(txt);
    				
    				return true;
    			}
    		</script>
    	</head>
    	<body>
    		<div text="your_text_value_goes_here"><a href="#" onclick="javascript: redirect();">Click To Load - GET METHOD</a> <div>
    		<br />
    		<form name="form1" action="get.php" method="post" onsubmit="return getTheValue(this);">
    			<input type="submit" name="submit" value="Submit POST" />
    		</form>
    	</body>
    </html>
    File 2:

    PHP Code:
    <?php
        
    if($_SERVER['REQUEST_METHOD'] == 'GET')
            print 
    "The value you've transferred from the HTML page through GET method is " $_GET['text'];
        else if(
    $_SERVER['REQUEST_METHOD'] == 'POST')
            print 
    "The value you've transferred from the HTML page through POST method is " .$_POST['text'];        
    ?>
    1. Put both files inside your web publish folder.

    2. Make sure that you name the PHP file as 'get.php'

    3. Browse the HTML file and click either the hyper link or the button.

    4. Hyper link will demonstrates a GET HTTP method in PHP

    5. Button will demonstrates a POST HTTP method in PHP

    Hope this help and please let me know if there is any confusion in the provided code.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •