hi all,
i am not getting inserted the dropdown value to the back end except that everything is inserting. so can u please help me.

<?php
ob_start();
@session_start();
require_once ("check.php");
createsessions($username,$password,$userid,$projectid);
    $con=mysql_connect("10.70.1.50","invensis","invensis");
    if(!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("database_myproject",$con);
    $sql="SELECT projectname from projects where createdby='$_SESSION[username]'";
    mysql_error();
    $result=mysql_query($sql);
    $options=""; 
    while ($row=mysql_fetch_array($result)) 
    {
        $id=$row["projectid"];
        $projectname=$row["projectname"];
        $options.="<option value=\"$id\">".$projectname.'</option>';
    }
    $sql2="SELECT * FROM users where reportingto='$_SESSION[username]' and role='2'";
    mysql_error();
    $result2=mysql_query($sql2);
    $num=mysql_num_rows($result2);
    
    ?> 
<head>
<body>
<form action="projectassign.php" method="post">
<table width="100%">
<tr><td> <img src="Logofinalcopy.gif">
</td></tr>
    <tr>
        <td bgcolor="aqua"><h2>Project assign</h2></td>
    </tr></table>
    <br>
    <table align="center">
    <tr>
        <td>projectassign</td>
        <td><select name="id">
        <option value="<?echo '$projectassign';?>" >----select project----<?=$options?>
        </select>
        </td>
    </tr>
    </table>  
    <br><br><br>  
    <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
    <tr>
        <th></th>
        <th>userid</th>
        <th>username</th>
           
    </tr>
    <?php
    $sno=1;
    while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
    ?>
     <tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
<td><? echo $row['userid']; ?></td>
<td><? echo $row['username'];?></td>
</tr>
<?php
    $sno=$sno+1;
}
?>
    </table>
    
    <?php
if(isset($_POST['Submit']))
    
    {
        $checkbox=$_POST['checkbox'];
        for($i=0;$i<count($checkbox);$i++)
        {
        $del_id = $checkbox[$i];        
        $sql = "Insert into projectassign(projectassign,userid,assigneddate)values('$_POST[projectassign]','$del_id','')";
         mysql_error();
        $result = mysql_query($sql);
        
        }   
    }      
    ?>
    <input type="submit" name="Submit"  value="Submit">
    </form>
    </body>
    </head>

Recommended Answers

All 27 Replies

I received your pm and your code should be as follows.

<?php
ob_start();
@session_start();
require_once ("check.php");
createsessions($username,$password,$userid,$projectid);
    $con=mysql_connect("10.70.1.50","invensis","invensis");
    if(!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("database_myproject",$con);
    $sql="SELECT projectname from projects where createdby='$_SESSION[username]'";
    mysql_error();
    $result=mysql_query($sql);
    $options=""; 
    while ($row=mysql_fetch_array($result)) 
    {
        $id=$row["projectid"];
        $projectname=$row["projectname"];
        $options.="<option value=\"$id\">".$projectname.'</option>';
    }
    $sql2="SELECT * FROM users where reportingto='$_SESSION[username]' and role='2'";
    mysql_error();
    $result2=mysql_query($sql2);
    $num=mysql_num_rows($result2);
    
    ?> 
<head>
<body>
<form action="projectassign.php" method="post">
<table width="100%">
<tr><td> <img src="Logofinalcopy.gif">
</td></tr>
    <tr>
        <td bgcolor="aqua"><h2>Project assign</h2></td>
    </tr></table>
    <br>
    <table align="center">
    <tr>
        <td>projectassign</td>
        <td><select name="id">
        <option value="<?php echo '$projectassign';?>" >----select project----</option><?php echo $options ?>
        </select>
        </td>
    </tr>
    </table>  
    <br><br><br>  
    <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
    <tr>
        <th></th>
        <th>userid</th>
        <th>username</th>
           
    </tr>
    <?php
    $sno=1;
    while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
    ?>
     <tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
<td><? echo $row['userid']; ?></td>
<td><? echo $row['username'];?></td>
</tr>
<?php
    $sno=$sno+1;
}
?>
    </table>
    
    <?php
if(isset($_POST['Submit']))
    
    {
        $checkbox=$_POST['checkbox'];
        for($i=0;$i<count($checkbox);$i++)
        {
        $del_id = $checkbox[$i];        
        $sql = "Insert into projectassign(projectassign,userid,assigneddate)values('".$_POST['projectassign']."','$del_id','')";
         mysql_error();
        $result = mysql_query($sql);
        
        }   
    }      
    ?>
    <input type="submit" name="Submit"  value="Submit">
    </form>
    </body>
    </head>

I received your pm and your code should be as follows.

<?php
ob_start();
@session_start();
require_once ("check.php");
createsessions($username,$password,$userid,$projectid);
    $con=mysql_connect("10.70.1.50","invensis","invensis");
    if(!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("database_myproject",$con);
    $sql="SELECT projectname from projects where createdby='$_SESSION[username]'";
    mysql_error();
    $result=mysql_query($sql);
    $options=""; 
    while ($row=mysql_fetch_array($result)) 
    {
        $id=$row["projectid"];
        $projectname=$row["projectname"];
        $options.="<option value=\"$id\">".$projectname.'</option>';
    }
    $sql2="SELECT * FROM users where reportingto='$_SESSION[username]' and role='2'";
    mysql_error();
    $result2=mysql_query($sql2);
    $num=mysql_num_rows($result2);
    
    ?> 
<head>
<body>
<form action="projectassign.php" method="post">
<table width="100%">
<tr><td> <img src="Logofinalcopy.gif">
</td></tr>
    <tr>
        <td bgcolor="aqua"><h2>Project assign</h2></td>
    </tr></table>
    <br>
    <table align="center">
    <tr>
        <td>projectassign</td>
        <td><select name="id">
        <option value="<?php echo '$projectassign';?>" >----select project----</option><?php echo $options ?>
        </select>
        </td>
    </tr>
    </table>  
    <br><br><br>  
    <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
    <tr>
        <th></th>
        <th>userid</th>
        <th>username</th>
           
    </tr>
    <?php
    $sno=1;
    while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
    ?>
     <tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
<td><? echo $row['userid']; ?></td>
<td><? echo $row['username'];?></td>
</tr>
<?php
    $sno=$sno+1;
}
?>
    </table>
    
    <?php
if(isset($_POST['Submit']))
    
    {
        $checkbox=$_POST['checkbox'];
        for($i=0;$i<count($checkbox);$i++)
        {
        $del_id = $checkbox[$i];        
        $sql = "Insert into projectassign(projectassign,userid,assigneddate)values('".$_POST['projectassign']."','$del_id','')";
         mysql_error();
        $result = mysql_query($sql);
        
        }   
    }      
    ?>
    <input type="submit" name="Submit"  value="Submit">
    </form>
    </body>
    </head>

i am still not getting inserted the value selected in dropdown box, but the check box value it is inserting in data base.

Could you make your problem more clearer. I will try debugging again which is as follows but if that doesn't solve it you will need to be a bit more descriptive.

<?php
ob_start();
@session_start();
require_once ("check.php");
createsessions($username,$password,$userid,$projectid);
    $con=mysql_connect("10.70.1.50","invensis","invensis");
    if(!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("database_myproject",$con);
    $sql="SELECT projectname from projects where createdby='".mysql_real_escape_string($_SESSION['username'])."'";
    mysql_error();
    $result=mysql_query($sql);
    $options=""; 
    while ($row=mysql_fetch_array($result)) 
    {
        $id=$row["projectid"];
        $projectname=$row["projectname"];
        $options.="<option value=\"$id\">".$projectname.'</option>';
    }
    $sql2="SELECT * FROM users where reportingto='".mysql_real_escape_string($_SESSION['username'])."' and role='2'";
    mysql_error();
    $result2=mysql_query($sql2);
    $num=mysql_num_rows($result2);
    
    ?> 
<head>
<body>
<form action="projectassign.php" method="post">
<table width="100%">
<tr><td> <img src="Logofinalcopy.gif">
</td></tr>
    <tr>
        <td bgcolor="aqua"><h2>Project assign</h2></td>
    </tr></table>
    <br>
    <table align="center">
    <tr>
        <td>projectassign</td>
        <td><select name="id">
        <option value="<?php echo '$projectassign';?>" >----select project----</option><?php echo $options ?>
        </select>
        </td>
    </tr>
    </table>  
    <br><br><br>  
    <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
    <tr>
        <th></th>
        <th>userid</th>
        <th>username</th>
           
    </tr>
    <?php
    $sno=1;
    while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
    ?>
     <tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
<td><? echo $row['userid']; ?></td>
<td><? echo $row['username'];?></td>
</tr>
<?php
    $sno=$sno+1;
}
?>
    </table>
    
    <?php
if(isset($_POST['Submit']))
    
    {
        $checkbox=$_POST['checkbox'];
        for($i=0;$i<count($checkbox);$i++)
        {
        $del_id = mysql_real_escape_string($checkbox[$i]);        
        $sql = "INSERT INTO projectassign(projectassign,userid,assigneddate)values('".mysql_real_escape_string($_POST['projectassign'])."','$del_id','')";
         mysql_error();
        $result = mysql_query($sql);
        
        }   
    }      
    ?>
    <input type="submit" name="Submit"  value="Submit">
    </form>
    </body>
    </head>

Could you make your problem more clearer. I will try debugging again which is as follows but if that doesn't solve it you will need to be a bit more descriptive.

<?php
ob_start();
@session_start();
require_once ("check.php");
createsessions($username,$password,$userid,$projectid);
    $con=mysql_connect("10.70.1.50","invensis","invensis");
    if(!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("database_myproject",$con);
    $sql="SELECT projectname from projects where createdby='".mysql_real_escape_string($_SESSION['username'])."'";
    mysql_error();
    $result=mysql_query($sql);
    $options=""; 
    while ($row=mysql_fetch_array($result)) 
    {
        $id=$row["projectid"];
        $projectname=$row["projectname"];
        $options.="<option value=\"$id\">".$projectname.'</option>';
    }
    $sql2="SELECT * FROM users where reportingto='".mysql_real_escape_string($_SESSION['username'])."' and role='2'";
    mysql_error();
    $result2=mysql_query($sql2);
    $num=mysql_num_rows($result2);
    
    ?> 
<head>
<body>
<form action="projectassign.php" method="post">
<table width="100%">
<tr><td> <img src="Logofinalcopy.gif">
</td></tr>
    <tr>
        <td bgcolor="aqua"><h2>Project assign</h2></td>
    </tr></table>
    <br>
    <table align="center">
    <tr>
        <td>projectassign</td>
        <td><select name="id">
        <option value="<?php echo '$projectassign';?>" >----select project----</option><?php echo $options ?>
        </select>
        </td>
    </tr>
    </table>  
    <br><br><br>  
    <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
    <tr>
        <th></th>
        <th>userid</th>
        <th>username</th>
           
    </tr>
    <?php
    $sno=1;
    while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
    ?>
     <tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
<td><? echo $row['userid']; ?></td>
<td><? echo $row['username'];?></td>
</tr>
<?php
    $sno=$sno+1;
}
?>
    </table>
    
    <?php
if(isset($_POST['Submit']))
    
    {
        $checkbox=$_POST['checkbox'];
        for($i=0;$i<count($checkbox);$i++)
        {
        $del_id = mysql_real_escape_string($checkbox[$i]);        
        $sql = "INSERT INTO projectassign(projectassign,userid,assigneddate)values('".mysql_real_escape_string($_POST['projectassign'])."','$del_id','')";
         mysql_error();
        $result = mysql_query($sql);
        
        }   
    }      
    ?>
    <input type="submit" name="Submit"  value="Submit">
    </form>
    </body>
    </head>

i am doing project management in which an admin can asign a project to his user. so for that i need to have a dropdown of list of projects present under him and the users with checkbox userid,username are displaying. so now admin need to assign a project to his users. so he selected a project from dropdown and assigned that to one user by clicking on check box. in the data base i am having a table of project assign with fields assignid,projectname,userid,asigned date. so when i selected a user and a project and click submit button iam getting userid value and assigned date but in the projectname nothing is displaying. actually the selected value in the dropdown box should get displayed. so i think u understood my problem.

If you mean the mysql query on line 78 is not inserting one of the four columns then that is because you never specified the fourth column. Perhaps you should have a second look at the query on line 78.

If you mean the mysql query on line 78 is not inserting one of the four columns then that is because you never specified the fourth column. Perhaps you should have a second look at the query on line 78.

Actually assignid is nothing but sl.no. so it will increment. and project name(which is not assigning) and userid(getting inserted) and assigned date(get inserted)

Then on line 41 replace with the following.

<td><select name="projectassign">

Then on line 41 replace with the following.

<td><select name="projectassign">

i have made changes but it is not inserting

try adding print_r($_POST); at the bottom of the page and see what php displays. It should show the key used for your project assign value.

try adding print_r($_POST); at the bottom of the page and see what php displays. It should show the key used for your project assign value.

i am getting Array() at the end .

i am getting Array() at the end .

Did you post the form? if it only displays Array() then that means no $_POST data has been sent.

Did you post the form? if it only displays Array() then that means no $_POST data has been sent.

i think i posted it. please verify my code. where should i post it.

On line 83 just after the last bracket. That is if the filename is projectassign.php as it is being posted to projectassign.php

On line 83 just after the last bracket. That is if the filename is projectassign.php as it is being posted to projectassign.php

ok. But wat should i write code there. please tell me. i am already posting this in the form. again we need to post it??

To make things easier make the following file projectassign.php and in it is as below. Now what does the print_r at the bottom tell you in the webpage?

<?php
ob_start();
@session_start();
require_once ("check.php");
createsessions($username,$password,$userid,$projectid);
    $con=mysql_connect("10.70.1.50","invensis","invensis");
    if(!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("database_myproject",$con);
    $sql="SELECT projectname from projects where createdby='".mysql_real_escape_string($_SESSION['username'])."'";
    mysql_error();
    $result=mysql_query($sql);
    $options=""; 
    while ($row=mysql_fetch_array($result)) 
    {
        $id=$row["projectid"];
        $projectname=$row["projectname"];
        $options.="<option value=\"$id\">".$projectname.'</option>';
    }
    $sql2="SELECT * FROM users where reportingto='".mysql_real_escape_string($_SESSION['username'])."' and role='2'";
    mysql_error();
    $result2=mysql_query($sql2);
    $num=mysql_num_rows($result2);
    
    ?> 
<head>
<body>
<form action="projectassign.php" method="post">
<table width="100%">
<tr><td> <img src="Logofinalcopy.gif">
</td></tr>
    <tr>
        <td bgcolor="aqua"><h2>Project assign</h2></td>
    </tr></table>
    <br>
    <table align="center">
    <tr>
        <td>projectassign</td>
        <td><select name="projectassign">
        <option value="<?php echo '$projectassign';?>" >----select project----</option><?php echo $options ?>
        </select>
        </td>
    </tr>
    </table>  
    <br><br><br>  
    <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
    <tr>
        <th></th>
        <th>userid</th>
        <th>username</th>
           
    </tr>
    <?php
    $sno=1;
    while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
    ?>
     <tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
<td><? echo $row['userid']; ?></td>
<td><? echo $row['username'];?></td>
</tr>
<?php
    $sno=$sno+1;
}
?>
    </table>
    
    <?php
if(isset($_POST['Submit']))
    
    {
        $checkbox=$_POST['checkbox'];
        for($i=0;$i<count($checkbox);$i++)
        {
        $del_id = mysql_real_escape_string($checkbox[$i]);        
        $sql = "INSERT INTO projectassign(projectassign,userid,assigneddate)values('".mysql_real_escape_string($_POST['projectassign'])."','$del_id','')";
         mysql_error();
        $result = mysql_query($sql);
        
        }   
    }      print_r($_POST);
    ?>
    <input type="submit" name="Submit"  value="Submit">
    </form>
    </body>
    </head>

To make things easier make the following file projectassign.php and in it is as below. Now what does the print_r at the bottom tell you in the webpage?

<?php
ob_start();
@session_start();
require_once ("check.php");
createsessions($username,$password,$userid,$projectid);
    $con=mysql_connect("10.70.1.50","invensis","invensis");
    if(!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("database_myproject",$con);
    $sql="SELECT projectname from projects where createdby='".mysql_real_escape_string($_SESSION['username'])."'";
    mysql_error();
    $result=mysql_query($sql);
    $options=""; 
    while ($row=mysql_fetch_array($result)) 
    {
        $id=$row["projectid"];
        $projectname=$row["projectname"];
        $options.="<option value=\"$id\">".$projectname.'</option>';
    }
    $sql2="SELECT * FROM users where reportingto='".mysql_real_escape_string($_SESSION['username'])."' and role='2'";
    mysql_error();
    $result2=mysql_query($sql2);
    $num=mysql_num_rows($result2);
    
    ?> 
<head>
<body>
<form action="projectassign.php" method="post">
<table width="100%">
<tr><td> <img src="Logofinalcopy.gif">
</td></tr>
    <tr>
        <td bgcolor="aqua"><h2>Project assign</h2></td>
    </tr></table>
    <br>
    <table align="center">
    <tr>
        <td>projectassign</td>
        <td><select name="projectassign">
        <option value="<?php echo '$projectassign';?>" >----select project----</option><?php echo $options ?>
        </select>
        </td>
    </tr>
    </table>  
    <br><br><br>  
    <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
    <tr>
        <th></th>
        <th>userid</th>
        <th>username</th>
           
    </tr>
    <?php
    $sno=1;
    while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
    ?>
     <tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
<td><? echo $row['userid']; ?></td>
<td><? echo $row['username'];?></td>
</tr>
<?php
    $sno=$sno+1;
}
?>
    </table>
    
    <?php
if(isset($_POST['Submit']))
    
    {
        $checkbox=$_POST['checkbox'];
        for($i=0;$i<count($checkbox);$i++)
        {
        $del_id = mysql_real_escape_string($checkbox[$i]);        
        $sql = "INSERT INTO projectassign(projectassign,userid,assigneddate)values('".mysql_real_escape_string($_POST['projectassign'])."','$del_id','')";
         mysql_error();
        $result = mysql_query($sql);
        
        }   
    }      print_r($_POST);
    ?>
    <input type="submit" name="Submit"  value="Submit">
    </form>
    </body>
    </head>

i had inserted the code as it is. now in the web page beside submit button it is displaying
Array()

Then there are two things to consider. One is did you post the $_POST in the first place and the second is have you got globals disabled in your php.ini file as they should. So your problem currently is your post data is not being sent to $_POST. If you want to test your globals in the php.ini file use the following.

<?php
if (!ini_get('register_globals')) {
die('$_POST should work!');
} else {
die ('$_POST won't work due to the php.ini settings.');
}
?>

And let me know which message pops up.

Then there are two things to consider. One is did you post the $_POST in the first place and the second is have you got globals disabled in your php.ini file as they should. So your problem currently is your post data is not being sent to $_POST. If you want to test your globals in the php.ini file use the following.

<?php
if (!ini_get('register_globals')) {
die('$_POST should work!');
} else {
die ('$_POST won't work due to the php.ini settings.');
}
?>

And let me know which message pops up.

i am getting this in the browser
Array won't work due to the php.ini settings.

i am getting this in the browser
Array won't work due to the php.ini settings.

It means you will need to go into your php.ini settings and change the register globals to disabled. So if you like post your php.ini file in code tags and I will try and fix.

It means you will need to go into your php.ini settings and change the register globals to disabled. So if you like post your php.ini file in code tags and I will try and fix.

i had send u to ur private message

I received your pm and register_globals = Off appears in the php.ini file which is what it should have been. But could you add at the very end of your file the following to see if it displays anything after the post. <?php echo $projectassign.$id; ?> That should confirm weather globals is on or off as we are getting mixed results. So tell me if that displays anything.

I received your pm and register_globals = Off appears in the php.ini file which is what it should have been. But could you add at the very end of your file the following to see if it displays anything after the post. <?php echo $projectassign.$id; ?> That should confirm weather globals is on or off as we are getting mixed results. So tell me if that displays anything.

nothing it is displaying extra.

Then could you check your url bar after posting to see that the variables haven't gone to the url.

Then could you check your url bar after posting to see that the variables haven't gone to the url.

means where should i check

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.