PhP Newbie needs help w/ first script modification

edited August 2004 in Internet & Media
Hello,

Just starting PHP and his is my very first script modification.
Everything works fine until the end of the server parses the last part where the script takes the user to the reg.html page but the selected 'user name' is not posted in the input box (name='user').

Do I need to include something in the value of the 'user' text box on the reg.html page? Script page sequence= addUser.php / user.php / reg.htm

Any help would be most appreciated for this newbie.

Thanks in advance....

addUser.php



[PHP] <?php
}
else{
// Open the users file
$fp = fopen("users.php", "a");

// Append the new user to end of users file
fwrite($fp, $string);

// Close the file
fclose($fp);

// Redirect to index
header("location: ../dnr-sub2-15mg.htm#dwn");

//show form again with posted variables i.e.:
echo "<input type=\"text\" name=\"user\" value=\"".$_POST."\">";
}
}
else{
?>[/PHP]

[PHP]<form method = "post" action = "<?php print($_SERVER); ?>">[/PHP]

[PHP]<input type="hidden" name="user" value="<?php echo $_POST;?>" >[/PHP]

Comments

  • ShortyShorty Manchester, UK Icrontian
    edited August 2004
    [php]
    <form method = "post" action = "<?php echo $_SERVER; ?>">
    [/php]

    Or the form won't work properly :)

    How about showing us the rest of the scripts in seperate PHP tags and then we have more of an idea what you are attempting to do :)
  • edited August 2004
    Shorty wrote:
    [php]
    <form method = "post" action = "<?php echo $_SERVER; ?>">
    [/php]

    Or the form won't work properly :)

    How about showing us the rest of the scripts in seperate PHP tags and then we have more of an idea what you are attempting to do :)


    Hi Shorty,


    Thanks for your prompt response. Here is the total code.

    [PHP]<?php
    session_start();
    header("Cache-control: private");

    if(@$_SESSION) header("location: login.php");
    elseif(@$_POST){
    $user = htmlspecialchars(strtolower($_POST["user"]));
    $string = "\r\n". $user. "<del>".

    $file = file("users.php") or die("Problem getting the user details flat-file [users.php]");

    $totalLines = sizeof($file);

    $line = 0;
    $match = 0;
    do{
    if("//" != substr($file[$line], 0, 2)){
    @list($SUBDOMAIN) = explode("<del>", $file[$line]);

    if((strtolower($user) == strtolower($SUBDOMAIN))) $match = 1;
    else $match = 0;
    }

    if($match) break;

    $line++;
    } while($line < $totalLines);

    if($match){

    ?>
    <script language = "javascript" type = "text/javascript">
    <!-- // Go back
    alert("SUBDOMAIN already taken, taking you back to choose another");
    history.go(-1);
    -->
    </script>
    <?php
    }
    else{
    $fp = fopen("users.php", "a");

    fwrite($fp, $string);

    fclose($fp);

    header("location: ../dnr-sub2-15mg.htm#dwn");

    echo "<$input type=\"text\" name=\"user\" value=\"".$_POST."\">";

    }
    }
    else{
    ?>
    [/PHP]
  • edited August 2004
    The script has just been updated with a few corrections (8/13/04)

    [PHP]
    addUser.php
    <?php
    session_start();
    header("Cache-control: private");

    if(@$_SESSION) header("location: login.php");
    elseif(@$_POST){
    $user = htmlspecialchars(strtolower($_POST["user"]));
    $string = "\r\n". $user. "<del>".

    $file = file("users.php") or die("Problem getting the user details flat-file [users.php]");

    $totalLines = sizeof($file);

    $line = 0;
    $match = 0;
    do{
    if("//" != substr($file[$line], 0, 2)){
    @list($NAME) = explode("<del>", $file[$line]);

    if((strtolower($user) == strtolower($user))) $match = 1;
    else $match = 0;
    }

    if($match) break;

    $line++;
    } while($line < $totalLines);

    if($match){

    ?>
    <script language = "javascript" type = "text/javascript">
    <!-- // Go back
    alert("NAME already taken, taking you back to choose another");
    history.go(-1);
    -->
    </script>
    <?php
    }
    else{
    $fp = fopen("users.php", "a");

    fwrite($fp, $string);

    fclose($fp);

    header("location: reg.php#dwn");

    echo "<$input type=\"text\" name=\"user\" value=\"".$_POST."\">";

    }
    }
    else{
    ?>


    <form NAME="form1" method = "post" action = "<?php echo $_SERVER; ?>">
    <input type="hidden" name="user" value="<?php echo $_POST;?>" >

    <input name="user" type="text" class="text" id="user">
    <input type="button" value="submit">
    </form>

    End of addUser.php


    reg.php

    <form action="xxxx.com" method="post" name="visibleForm" target="_blank" onSubmit="return check(this);">

    <input type="text" name="name">
    <input type="text" name="organization">
    <input type="text" name="address">
    <input type="text" name="city">
    <input type="text" name="state">
    <input type="text" name="zip">
    <input type="text" name="email">
    <input type="text" name="phone">
    <input type="text" name="user" value="<?php echo $_POST;?>">

    <input type="button" value="submit">
    </form>
    End of reg.php
    [/PHP]
    But the same problem exist, the user input on addUser.php input box is not being sent to for the reg.php to echo/post in the "user" input field upon loading.

    Do you think that the error may be in one of the following lines?
    [PHP]
    addUser.php
    echo "<$input type=\"text\" name=\"user\" value=\"".$_POST."\">";
    [/PHP] or,

    [PHP]
    reg.php----
    <input type="text" name="user" value="<?php echo $_POST;?>">
    [/PHP]

    Thanks
  • a2jfreaka2jfreak Houston, TX Member
    edited August 2004
    Yeah, I think the error is on:
    [php]
    echo "<$input . . .
    [/php]

    it should be
    [php]
    echo '<input type="text" name="user" value="' . $_POST["user"] . '" />';
    [/php]
  • edited August 2004
    a2jfreak wrote:
    Yeah, I think the error is on:
    [php]
    echo "<$input . . .
    [/php]

    it should be
    [php]
    echo '<input type="text" name="user" value="' . $_POST["user"] . '" />';
    [/php]

    Hello,

    Thanks for your response.
    I changed that line in the addUser.php file, but still the same. Any other thoughts could be helpful.

    Do I need to echo the form html tag as well in the addUser.php script?

    I also put this at the top of my reg.php page to test array[PHP]<?php
    print_r($_POST);
    ?>[/PHP] and receive Array() when testing. I think this mean the array is empty, if true then nothing is being sent from the addUser.php form to post to the reg.php "user" input field. Does that sound right?

    Thanks Again,
  • a2jfreaka2jfreak Houston, TX Member
    edited August 2004
    Use this instead.

    [php]
    foreach ($_POST as $key => $value) {
    echo "$key = $value";
    }
    [/php]
  • edited August 2004
    a2jfreak wrote:
    Use this instead.

    [php]
    foreach ($_POST as $key => $value) {
    echo "$key = $value";
    }
    [/php]

    Hi a2jfrea,

    Thanks for hanging in there with this confussed PHP newbie.
    Just tested the above code but no change....
  • a2jfreaka2jfreak Houston, TX Member
    edited August 2004
    Can you post a .zip of the files so I can take a look at them?
  • edited August 2004
    Ok, thanks, I'll do that now and post a link in my next reply.
  • edited August 2004
    OK, here's the link to the zip files: http://host-2day.com/bird/phpTest.zip
  • a2jfreaka2jfreak Houston, TX Member
    edited August 2004
    Not sure exactly what all you are trying to accomplish, but this at least passes the "user" value from addUser.php to reg.php
  • edited August 2004
    a2jfreak,

    Thanks for taking the time to thouroughly review my script. I unzipped the files from what you posted to the forum, tested it and have the same results. I briefly checked all files and they appear to be the same. Did I download the same copy I sent you?

    Oh, what I'm needing to accomplish is to have a user select a user name, if not available the user is sent back to addUser.php to select a different name. Aftert the script checks the flatbase DB file and finds an avilable name the user is redirected to the reg.php page with the selected name already posted in the "user" field, and all they need to do is complete the other filds and submit.

    Please check to see that you have the zip file you made changes to for me to test.

    Many Thanks Again,
  • a2jfreaka2jfreak Houston, TX Member
    edited August 2004
    Make sure you're downloading the zip file I attached, not the one you linked to.

    all I made it do is send the "user" value to reg.php from userAdd.php.

    I load userAdd.php in the browser. Type "xyz" and press enter. It then went to reg.php with the last field populated with "xyz."
  • edited August 2004
    a2jfreak,

    U the man!!...... yes it works now.
    Funny how newbies like me take forever to see what's right in front of them.
  • a2jfreaka2jfreak Houston, TX Member
    edited August 2004
    Glad I could help.
Sign In or Register to comment.