Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2012, 09:59 AM   PM User | #1
nani_nisha06
Regular Coder

 
Join Date: Oct 2012
Location: mother land --india
Posts: 159
Thanks: 37
Thanked 2 Times in 2 Posts
nani_nisha06 is an unknown quantity at this point
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..
nani_nisha06 is offline   Reply With Quote
Old 12-03-2012, 03:19 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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>
__________________
Fumigator is offline   Reply With Quote
Old 12-04-2012, 06:37 AM   PM User | #3
nani_nisha06
Regular Coder

 
Join Date: Oct 2012
Location: mother land --india
Posts: 159
Thanks: 37
Thanked 2 Times in 2 Posts
nani_nisha06 is an unknown quantity at this point
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
nani_nisha06 is offline   Reply With Quote
Old 12-04-2012, 09:17 AM   PM User | #4
nani_nisha06
Regular Coder

 
Join Date: Oct 2012
Location: mother land --india
Posts: 159
Thanks: 37
Thanked 2 Times in 2 Posts
nani_nisha06 is an unknown quantity at this point
PHP Code:
<select name='proces_BAU<?php echo $info['id']; ?>'></select>
This really worked only mistake is i was not checking in my db .....
nani_nisha06 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:00 AM.


Advertisement
Log in to turn off these ads.