hi all,
i am having a page where i can select a projectname from the dropdown box(the project names will be cuming from database) and below that there is a list of users with checkbox. so i wil select a projectname and select one or more users for that project and then submit.Those users wil be assigned to that project. so now i need validation for that drop down and check box. so can any one please...
Note: By default in the dropdown box we can see '-----select project-----'
here is my code.see line no.48,66

<?php
ob_start();
@session_start();
require_once ("check.php");
createsessions($username,$password,$userid,$projectid,$projectname,$filename,$size,$allocatedmemory,$answer,$usedmemory,$Remainingmemory,$result,$data3);
    include 'connection.php';
    $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=\"$projectname\">".$projectname.'</option>';
    }
    $num=mysql_num_rows($result);
    $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); 
    ?> 
<body>
<form action="projectassign.php" method="post">
<table width="100%">
<tr><td> <img src="Logofinalcopy.gif">
</td></tr></table><br><hr style="color: red;">
<table align="right"> 
    <tr>
        <td align="right" style="width: 50px">   
            <td align="right" style="color: navy;"><strong><?php echo "Welcome ".$_SESSION[username];?>,</strong></td><td><a href="logout.php">Logout</a></td>
        </td>
        </tr></table>
        <table><tr>
        <td><a href="Admin.php">Home</a></td>
        <td>&nbsp&nbsp&nbsp&nbsp 
        <a href="Projectmgmt.php">Projects</a></td>
        <td>&nbsp&nbsp&nbsp&nbsp<a href="projectassign.php">Project Assign</a></td>
        </tr>
        </table>  

    <table align="center"><td style="color: navy;"><h2>Project assign</h2></td>
    </tr></table>
    <table align="center">
    <tr>
        <td style="color: navy;">Projectassign</td>
        <td><select name="projectassign">
        <option id="select" 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" bordercolor="red">
    <tr>
        <th></th>
        <th style="color: navy;">Userid</th>
        <th style="color: navy;">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]); 
        $query="select projectassign from projectassign where projectassign='$_POST[projectassign]' and userid='$del_id' ";
        mysql_error();  
        $result=mysql_query($query);
        $ans=mysql_num_rows($result);        
        if($ans==0)
        {        
            $sql3 = "INSERT INTO projectassign(projectassign,userid)values('".mysql_real_escape_string($_POST['projectassign'])."','$del_id')";
            mysql_error();
            $result = mysql_query($sql3);
            echo "<script language='javascript'>
            alert('Project assigned');
            </script>";
        }
        else{
            echo "<script language='javascript'>
            alert('Project already assigned');
            </script>";
        }
        
       }
        
    }
                           
    ?> 
    <br><table align="center"><tr><td><input type="submit" name="Submit"  value="Submit" onclick="return check()"></td></tr></table> 
    </form>
    </body>

line 48,66

It would help if you told us what you wanted to validate.

i had posted this thread a long back.Now i got the solution.Any way thanks for ur reply...

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.