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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts

    PHP form issue.....

    Hi All,

    I need your help on below.

    I have form which takes a input as LIST or SELECT and should get updated in the DB...

    Now my problem is, I have 35 fields which has unique ID. so, As I can not $_post for each feild by it name I have create a while loop by fetching as array & defined input type using if condition on the form....but while post method for getting valuses from DB I want to carry 35 field ID so that i can identify its value for controlling.... But while $_Post I am not able to take all values at one time and make foreach condition.....any help is appreciated...


    My code go as below.

    PHP Code:
    <?php 
     
    while($info mysql_fetch_array$data ))
     { 
     
    $input_type=$info['type'];
     
    $proces_type=$info['PROCESS_BAU'];
     
    $id_type=$info['id'];
    ?>    
                <tr>
                    <td><?=$info['id']?></td>
                    <td><?=$info['PROCESS_BAU']?></td>
                    <?if ($input_type=='TEXT'){?>
                    <td>Volumes:<input type='TEXT' name='proces_BAU' size='2'/></td>
                    <?}else{?>
                    <td>Task:<select name='proces_BAU'><option>--</option><option>Yes</option><option>No</option></select></td>
                    <?}
                    
    ?>
                </tr>
                <?php ?>
    <tr><td><input type="submit" value="Save"/></td></tr>            
    </form>        
     </table>
    </div>
      <?php 
    }
    ?>
    PHP Code:
    <?php
    session_start
    ();
    $myusername=$_SESSION['myusername'];
    ?>
    <?
    include_once "C:/xampp/htdocs/SAM/include/database.php";
    //$process="";
    echo $process $_POST['proces_BAU'];

    //foreach($process as $key=>$value)
        
    if(!empty($value)){
            
    $qry "INSERT INTO daily_tasks_done (`Member_Id`,`Task_Id`,`Value`) VALUES ('".$_SESSION['memberid']."','".$key."','".$value."')";
            
    $result1=mysql_query($qry)or die(mysql_error()); 
        }
        
    //$_SESSION['Notify']['type'] = 'Sucess Message:';
        //$_SESSION['Notify']['msg'] = 'shift roaster updated!!!';
        //header("location: index.php") or die("record not inserted");
                        
    mysql_close();
    ?>

    Regards,
    Nani
    Last edited by nani_nisha06; 12-04-2012 at 09:16 AM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You need to assign unique "name" values for each select element. You can do this using this syntax, which will create an array:

    Code:
    <select name='proces_BAU[]'></select>
    Or you can be more explicit, using an iterator:
    PHP Code:
    <?php
    $i 
    0;
    while(
    $info mysql_fetch_array$data ))
     { 
    //...etc...
    ?>
    <select name='proces_BAU<?php echo $i?>'></select>
    <?php
    $i
    ++;
    }
    But it's usually best to associate the select element's name with something from the database. I noticed you have a column "id", which I will assume is unique? Just append id to the name value.

    PHP Code:
    <select name='proces_BAU<?php echo $info['id']; ?>'></select>

  • #3
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fumigator View Post
    You need to assign unique "name" values for each select element. You can do this using this syntax, which will create an array:

    Code:
    <select name='proces_BAU[]'></select>
    Or you can be more explicit, using an iterator:
    PHP Code:
    <?php
    $i 
    0;
    while(
    $info mysql_fetch_array$data ))
     { 
    //...etc...
    ?>
    <select name='proces_BAU<?php echo $i?>'></select>
    <?php
    $i
    ++;
    }
    But it's usually best to associate the select element's name with something from the database. I noticed you have a column "id", which I will assume is unique? Just append id to the name value.

    PHP Code:
    <select name='proces_BAU<?php echo $info['id']; ?>'></select>
    Dear Fumigator,

    When I am trying to associated in the bove I am getting below error

    PHP Code:
    Parse errorsyntax errorunexpected T_ENCAPSED_AND_WHITESPACEexpecting T_STRING or T_VARIABLE or T_NUM_STRING in C:xampphtdocsSAMBAUindex.php on line 82 
    later when I have changed my code to

    PHP Code:
    <? switch ($input_type){
                    case 
    "LIST":
                            echo 
    "<td>Task:<select name='proces_BAU <?php echo ".$info['id']."; ?>'><option>--</option><option>Yes</option><option>No</option></select></td>";
                                        break;
                    case 
    "TEXT":
                            echo 
    "<td>Volumes:<input type='TEXT' name='proces_BAU <?php echo ".$info['id']."; ?>' size='2'/></td>";
                                        break;    
                    }
    ?>
    it is giving error in the second code as

    PHP Code:
    NoticeUndefined indexproces_BAU in C:xampphtdocsSAMBAUsavetasks.php on line 8 
    any help

  • #4
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts
    PHP Code:
    <select name='proces_BAU<?php echo $info['id']; ?>'></select>
    This really worked only mistake is i was not checking in my db .....


  •  

    Posting Permissions

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