Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 48

Thread: More than one input to a form question - how to process?

  1. #21
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Finished script just incase it's needed.
    PHP Code:
    <?php 

    if(isset($_POST['submit'])){ 

    if(@
    preg_match("/\r/",$_POST['names']))
    {
    $names preg_split("/\r/",$_POST['names']);
    }
    else if(@
    preg_match("/\n/",$_POST['names']))
    {
    $names preg_split("/\n/",$_POST['names']);
    }
    else
    {
    $names = @preg_split("/ /",$_POST['names']);
    }

     foreach (
    $names as $thename) {
       echo 
    'Hi '.$thename.'<br>'
     } 

    else 

    echo 
    '<form method = "POST" action = "">'
    echo 
    '<p>Names</p>'
    echo 
    '<p><textarea rows="10" name="names" cols="37"></textarea></p>'
    echo 
    '<p><input type="submit" value="Submit" name="submit"></p>'
    echo 
    '</form>'

    ?>
    Last edited by smithster; 12-14-2007 at 08:00 PM.

  2. #22
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Great work! By the way, what is the difference between \n and the [\n,] that you had? I don't use preg function very much, so I don't really know much about that stuff.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #23
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok, next part of this! I thought I'd be ok from here but no!! What if I wanted to pair off a username with a password like this.....

    user1 : pass1
    user2 : pass2
    user3 : pass3
    and so on...... (without spaces though as : and p together gives a lol)

    I thought this would be ok...
    PHP Code:
     foreach ($usernames as $users && $passwords as $pass){ 
    Output....
    Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ')'
    Also tried...
    PHP Code:
     foreach ($usernames as $users || $passwords as $pass){
    and 
    also
     
    foreach ($usernames as $users) && ($passwords as $pass){ 
    All give the same error.

    Any ideas?

    Thanks again,

    Smithster.

    edit......

    almost got it. Slight output problem though....
    PHP Code:
     foreach ($usernames as $users){
    foreach (
    $passwords as $pass){
    $contentusers ''.$users.':'.$pass.'<br>';
    echo 
    $contentusers;
     }

    user1 : pass1
    user1 : pass2
    user1 : pass3
    user1 : pass4
    user2 : pass1
    user2 : pass2
    user2 : pass3
    user2 : pass4
    user3 : pass1
    user3 : pass2
    user3 : pass3
    user3 : pass4
    user4 : pass1
    user4 : pass2
    user4 : pass3
    user4 : pass4
    Last edited by smithster; 12-14-2007 at 09:19 PM.

  4. #24
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    I don't have access to my WAMP server, so I can't test this. But try it:
    PHP Code:
    <?php

    if(isset($_POST['submit'])){  

    if(@
    preg_match("/\r/",$_POST['names'])) 

    $names preg_split("/\r/",$_POST['names']); 

    else if(@
    preg_match("/\n/",$_POST['names'])) 

    $names preg_split("/\n/",$_POST['names']); 


    foreach (
    $names as $thename) { 
       
    $info preg_split("/:/",$thename);
       echo 
    "Name: ".$info[0]." Password: ".$info[1].'<br>';
    }  
    }  
    else  
    {  
    echo 
    '<form method = "POST" action = "">';  
    echo 
    '<p>Names</p>';  
    echo 
    '<p><textarea rows="10" name="names" cols="37"></textarea></p>';  
    echo 
    '<p><input type="submit" value="Submit" name="submit"></p>';  
    echo 
    '</form>';  
    }  
    ?>
    This is the easiest way I can think of, and it is the closest to your original code.

    EDIT: Make sure you get the right one. . . I edited it (had a wrong var name)
    I'm not sure if this is what your looking for, but it should work. . .
    Last edited by Jas; 12-14-2007 at 09:52 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  5. #25
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    This isn't going to work.

    Here's the script updated with yours added in.
    PHP Code:
    <?php 

    if(isset($_POST['submit'])){ 

    if(@
    preg_match("/\r/",$_POST['names'])) 

    $names preg_split("/\r/",$_POST['names']); 

    else if(@
    preg_match("/\n/",$_POST['names'])) 

    $names preg_split("/\n/",$_POST['names']); 
    }
    if(@
    preg_match("/\r/",$_POST['passwords'])) 

    $passwords preg_split("/\r/",$_POST['passwords']); 

    else if(@
    preg_match("/\n/",$_POST['passwords'])) 

    $passwords preg_split("/\n/",$_POST['passwords']); 
    }

    foreach (
    $names as $thename) { 
    $info preg_split("/:/",$thename);
    echo 
    "Name: ".$info[0]." Password: ".$info[1].'<br>'


    else 

    echo 
    '<form method = "POST" action = "">'
    echo 
    '<p>Names</p>'
    echo 
    '<p><textarea rows="10" name="names" cols="37"></textarea></p>';
    echo 
    '<p>Passwords</p>'
    echo 
    '<p><textarea rows="10" name="passwords" cols="37"></textarea></p>';
    echo 
    '<p><input type="submit" value="Submit" name="submit"></p>'
    echo 
    '</form>'

    ?>
    Output....
    Name: paul Password:
    Name: smith Password:
    Name: emma Password:
    Name: john Password:
    There isn't anything telling it what to do with the passwords and that's the part I'm struggling with.

  6. #26
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    I didn't know what your form looked like. My way was in the names text box you typed Name:Password. Like Jim:jim99 and the output would be Name: Jim Password: jim99 (in other words you don't need the pw box)

    EDIT: Hang on and I'll code it your way

    PHP Code:
    <?php  

    if(isset($_POST['submit'])){  

    if(@
    preg_match("/\r/",$_POST['names']))  
    {  
    $names preg_split("/\r/",$_POST['names']);  
    }  
    else if(@
    preg_match("/\n/",$_POST['names']))  
    {  
    $names preg_split("/\n/",$_POST['names']);  

    if(@
    preg_match("/\r/",$_POST['passwords']))  
    {  
    $passwords preg_split("/\r/",$_POST['passwords']);  
    }  
    else if(@
    preg_match("/\n/",$_POST['passwords']))  
    {  
    $passwords preg_split("/\n/",$_POST['passwords']);  


    for(
    $i=0$i<count($names) || $i<count($passwords);$i++){
    echo 
    "Name: ".$names[$i]." Password: ".$passwords[$i];
    }  
    }  
    else  
    {  
    echo 
    '<form method = "POST" action = "">';  
    echo 
    '<p>Names</p>';  
    echo 
    '<p><textarea rows="10" name="names" cols="37"></textarea></p>'
    echo 
    '<p>Passwords</p>';  
    echo 
    '<p><textarea rows="10" name="passwords" cols="37"></textarea></p>'
    echo 
    '<p><input type="submit" value="Submit" name="submit"></p>';  
    echo 
    '</form>';  
    }  
    ?>
    Try that. Your way had a loop within a loop. This is one loop that does both at the same time.
    Last edited by Jas; 12-14-2007 at 10:11 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  7. #27
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you Jas, getting there now!!

    Changed it slightly to output each one on a new line.
    PHP Code:
    for($i=0$i<count($names) || $i<count($passwords);$i++){ 
    echo 
    ''.$names[$i].':'.$passwords[$i].'<br>'

    Problem!
    The output...
    PHP Code:
    user1:pass1
    user2
    pass2
    user3
    pass3
    user4
    pass4 
    The phpcode under output is actually supposed to be a quote, but it puts a : and the p together to make emoticons!!!

    For some reason, the 1st 1 is correct as I want it. But the rest all have a space between the : and the password. Why is this?

  8. #28
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    EDIT: try
    PHP Code:
    echo "Name: ".preg_replace("/ /","",$names[$i])." Password: ".preg_replace("/ /","",$passwords[$i]); 
    EDIT 2: You might also try:
    PHP Code:
    echo "Name: ".preg_replace("/ /","",$names[$i],1)." Password: ".preg_replace("/ /","",$passwords[$i],1);
    //The 1 at the end makes sure only the first space is removed. Might me advantageous, may not be. 
    EDIT 3: Better idea! Try this:
    PHP Code:
    if(@preg_match("/\r/",$_POST['names']))   
    {   
    $names preg_split("/\r /",$_POST['names']);   
    }   
    else if(@
    preg_match("/\n /",$_POST['names']))   
    {   
    $names preg_split("/\n /",$_POST['names']);   
    }  
    if(@
    preg_match("/\r /",$_POST['passwords']))   
    {   
    $passwords preg_split("/\r /",$_POST['passwords']);   
    }   
    else if(@
    preg_match("/\n /",$_POST['passwords']))   
    {   
    $passwords preg_split("/\n /",$_POST['passwords']);   

    Last edited by Jas; 12-14-2007 at 10:37 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  9. #29
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Still exactly the same output.

    On both of them. 1st is perfect. Anything after that has a space before the password and there shouldn't be!!!

  10. #30
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Hmm. . . I am away from wamp right now, so it's hard to figure out lol. Try the last edit I made on my previous post. Probably won't work though. I might have to look at it later. It must be from the \n or \r because it doesn't effect the first. You could try:
    PHP Code:
    echo "Name: ".preg_replace("/\n/","",$names[$i])." Password: ".preg_replace("/\n/","",$passwords[$i]); 
    If that works I can give you a more effective solution later
    Last edited by Jas; 12-14-2007 at 10:56 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

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
  •