hello everybody,
i had created a dropdown in which project names will be appeared. and i am getting those project name from backend. Below that dropdown i am having a table of users with a check box.so whenever i select a projectname and click on the checkbox of one user, that projectname and username should store in project assign table. The problem is username is storing but the projectname is not storing in the database. it is displaying that column empty.
so please do the needful.
Thank u.
i had created a dropdown in which project names will be appeared. and i am getting those project name from backend. Below that dropdown i am having a table of users with a check box.so whenever i select a projectname and click on the checkbox of one user, that projectname and username should store in project assign table. The problem is username is storing but the projectname is not storing in the database. it is displaying that column empty.
so please do the needful.
Thank u.
Code:
<?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>
<script language="javascript" type="text/javascript">
function check()
{
if(document.getElementById('checkbox[]').value == "")
{
alert('Please select checkbox');
return false;
}
}
</script>
<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)values('".mysql_real_escape_string($_POST['projectassign'])."','$del_id')";
echo $sql;
mysql_error();
$result = mysql_query($sql);
}
}
?>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</head>
Comment