473,379 Members | 1,191 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

how to insert value selected in the dropdown to backend?

18
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.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ob_start();
  3. @session_start();
  4. require_once ("check.php");
  5. createsessions($username,$password,$userid,$projectid);
  6.     $con=mysql_connect("10.70.1.50","invensis","invensis");
  7.     if(!$con)
  8.         {
  9.             die('Could not connect: ' . mysql_error());
  10.         }
  11.     mysql_select_db("database_myproject",$con);
  12.     $sql="SELECT projectname from projects where createdby='".mysql_real_escape_string($_SESSION['username'])."'";
  13.     mysql_error();
  14.     $result=mysql_query($sql);
  15.     $options=""; 
  16.     while ($row=mysql_fetch_array($result)) 
  17.     {
  18.         $id=$row["projectid"];
  19.         $projectname=$row["projectname"];
  20.         $options.="<option value=\"$id\">".$projectname.'</option>';
  21.     }
  22.     $sql2="SELECT * FROM users where reportingto='".mysql_real_escape_string($_SESSION['username'])."' and role='2'";
  23.     mysql_error();
  24.     $result2=mysql_query($sql2);
  25.     $num=mysql_num_rows($result2);
  26.  
  27.     ?> 
  28. <head>
  29. <body>
  30. <script language="javascript" type="text/javascript">
  31.         function check()
  32.         {
  33.             if(document.getElementById('checkbox[]').value == "")
  34.             {
  35.                 alert('Please select checkbox');
  36.                 return false;
  37.  
  38.             }
  39.         }
  40.         </script>
  41.  
  42.  
  43. <form action="projectassign.php" method="post">
  44. <table width="100%">
  45. <tr><td> <img src="Logofinalcopy.gif">
  46. </td></tr>
  47.     <tr>
  48.         <td bgcolor="aqua"><h2>Project assign</h2></td>
  49.     </tr></table>
  50.     <br>
  51.     <table align="center">
  52.     <tr>
  53.         <td>projectassign</td>
  54.         <td><select name="projectassign">
  55.         <option value="<?php echo '$projectassign';?>" >----select project----</option><?php echo $options ?>
  56.         </select>
  57.         </td>
  58.     </tr>
  59.     </table>  
  60.     <br><br><br>  
  61.     <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
  62.     <tr>
  63.         <th></th>
  64.         <th>userid</th>
  65.         <th>username</th>
  66.  
  67.     </tr>
  68.     <?php
  69.     $sno=1;
  70.     while($row=mysql_fetch_array($result2, MYSQL_ASSOC)){
  71.     ?>
  72.      <tr>
  73. <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['userid']; ?>"></td>
  74. <td><? echo $row['userid']; ?></td>
  75. <td><? echo $row['username'];?></td>
  76. </tr>
  77. <?php
  78.     $sno=$sno+1;
  79. }
  80. ?>
  81.     </table>
  82.  
  83.     <?php
  84. if(isset($_POST['Submit']))
  85.  
  86.     {
  87.         $checkbox=$_POST['checkbox'];
  88.         for($i=0;$i<count($checkbox);$i++)
  89.         {
  90.         $del_id = mysql_real_escape_string($checkbox[$i]);        
  91.         $sql = "INSERT INTO projectassign(projectassign,userid)values('".mysql_real_escape_string($_POST['projectassign'])."','$del_id')";
  92.          echo $sql;
  93.          mysql_error();
  94.         $result = mysql_query($sql);
  95.  
  96.         }
  97.     }    
  98.  
  99.     ?>
  100.     <input type="submit" name="Submit"  value="Submit">
  101.     </form>
  102.     </body>
  103.     </head>
  104.  
Mar 31 '10 #1
3 3055
Atli
5,058 Expert 4TB
Hey.

When you select the projects for you <option> boxes, you specify that the value of each should be a "projectid", but you fail to fetch such a row from your database. Thus, the value attribute of all the projectassign options is empty, which is the value put into the projectassign table where the project id should go.

If you turn the error messages on, PHP should give you a warning that the "projectid" index doesn't exist.

P.S.
Putting mysql_error() by itself without printing it is pointless. It returns an error, it does not print it. You need to do that yourself with an echo or print. It's also quite popular to put it in a "or die()" clause following the mysql_query() call.
Mar 31 '10 #2
niths
18
i didnt understand wat u said. can u please do that in my code..so that i can come to know. thank u.
Apr 1 '10 #3
Atli
5,058 Expert 4TB
On line #18 you try to use a "projectid" from the query on line #12. But that column isn't in your query. - If you want to use a column from your table in your code, it needs to be included in the query.

Consider this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $sql = "SELECT `one`, `two`
  3.         FROM `my_table`";
  4. $result = mysql_query($sql);
  5. $row = mysql_fetch_assoc($result);
  6.  
  7. // These will print the values, as expected.
  8. echo $row['one'];
  9. echo $row['two'];
  10.  
  11. // But this will print nothing, because
  12. // this field was not retrieved in the query.
  13. echo $row['three'];
  14. ?>
Apr 1 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mamun | last post by:
Hi All, I have the following case. I am trying to update a table based on the value of dropdown box and checkbox. Here is what I have in page1.asp <table>
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: vishnu | last post by:
Hi, I have a fully editable datagrid which has dropdownlist in two columns. Now i have to bind the dropdown in the second column based on the value selected in the dropdown in the firstcolumn. so...
0
by: planetthoughtful | last post by:
Hi All, I have a c# web form that has two listviews on it. Both currently retrieve their list entries from two separate tables in an SQLServer backend. I've been asked to make the values in the...
1
Fary4u
by: Fary4u | last post by:
Hi is any body know where is actual problem is coz it's look me some problem ? to insert value into the MS ACCESS DATABASE after the value is true form html <input type="checkbox"...
6
by: itgaurav198 | last post by:
Hi, i have one jsp in which i select a value from drop down and on change of this a servlet is called that accesses some values and return to the same jsp where these values get populated in...
13
by: sindhu | last post by:
Hello acoder. I want to know another type of passing values between pages I have three frames frame1 for main horizontal menu frame 2 for vertical submenu frame 3 which is is loaded based on...
16
by: tarunkhatri | last post by:
Hi. I have a javascript function to change the value of the cell on chnage event of a dropdown list.My code is workin but the problem is that the value of the cell is chaning but not respective to...
1
by: visweswaran2830 | last post by:
Hi, I have four cascading dropdown control and now I want to load a gird data based on the value selected on that dropdown. This should be done by using ajax concepts..
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.