Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help I’m PHP beginner.

    I have a problem regarding with my code or maybe to my PHP configuration. I write a simple code, when I execute it to IE, no value of my variable “name”, can anybody advice me what to do.

    here's my code:

    <html>
    <head>
    <title>Jet Search</title>
    </head>

    <body>
    <h2>Search for First name</h2>
    <form action="rname.php" method="post">
    Please Enter name:
    <br>
    <input name="name" type=text id="name">
    <br>
    <input type=submit value="Search">

    </form>
    </body>
    </html>

    Rname code

    <?
    echo $name;
    ?>
    Last edited by jetpower8888; 01-05-2006 at 01:41 PM.

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Location
    Liverpool
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Posted in wrong board but while I'm here:

    PHP Code:
    <?php
    echo $_POST['name'];
    ?>
    my mind is on a permanent tangent

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I'll try it

    thx, I'll try it but still no result.

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    PHP Code:
    <? if(!empty($_POST)){
    echo 
    "This is the form data I recieved:<br />"
    print_r($_POST);
    }
    else
    {
    echo 
    "No form data recieved. "
    }
    Last edited by firepages; 01-05-2006 at 05:00 PM.

  • #5
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks NancyJ, your code gives me a result by the way without using print_r($_POST) statement, instead using simply echo “$var” statement. I think it’s my PHP configuration is the problem, can you give some information about configuring PHP that work smoothly, I’m using PHP-4.3.11 XP IE Apache 2.

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this, and let us know what output you get:

    PHP Code:
    <?php
    echo 'PHP Script Output: ';
    if( !empty( 
    $_POST['name'] ) ){
      echo 
    $_POST['name'];
    } else {
      echo 
    'No data sent';
    }
    ?>

  • #7
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Result PHP Script Output: Gaw

    Result

    PHP Script Output: Gaw

    Thanks Missing-Score, for your nice code, without using $_POST, instead using a simply echo “$name” statement.

    Just like this:

    <?
    echo $name;
    ?>

    Can I get the value of var $name, with this code in my computer no result.

    Is this a PHP configuration problem? can you give some information about configuring PHP that work smoothly, I’m using PHP-4.3.11 XP IE Apache 2.

  • #8
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Using just $name works with register globals set on in your php.ini. It's off by default because it's generally considered to be a security issue. You can read more about it here: http://us3.php.net/register_globals

    Here's a function that emulates register globals in the post array, but it's subject to the same problems and should be used sparingly or not at all if you can help it.

    PHP Code:
    if (isset($_POST))
    {
        foreach (
    $_POST as $key=>$value)
        {
            ${
    $key} = $value;
        }
    }

    if (isset(
    $name))
    {
        echo 
    $name;


  • #9
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Yes $name is easier, but its bad form if, like ralph l mayo said, you are on a server that doesnt use them. If you are learning a programing language its best to learn with proper form then when you are comfortable with thoose use the shortcuts if you can.
    Why not thank me?

    http://adamsworld.name

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,618
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Write your code so it will work with register globals off and it will still work with register globals on. This will avoid the need to change your code once your host becomes security concious.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #11
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks!!!

    Thanks guy


  •  

    Posting Permissions

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