473,322 Members | 1,736 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,322 software developers and data experts.

how to store date and drop down values to database

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  5.   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  6.   <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
  7.  
  8.   <script>
  9.   $(document).ready(function() {
  10.     $(".datepicker").datepicker()
  11.   });
  12.   </script>
  13. </head>
  14. <body>
  15. <?php
  16. error_reporting(E_PARSE);
  17. $status = $_POST['status'];
  18. $driver_name= $_POST['driver_name'];
  19. $from=date('y-m-d',strtotime($_POST['date_from']));
  20. $to=date('y-m-d',strtotime($_POST['date_to']));
  21. $conn = mysqli_connect('localhost', 'root', '', 'punbus') or
  22.         die("Database not connected" . mysqli_error());
  23. if(isset($_POST['sub'])) {
  24.     foreach($status as $k=>$s){
  25.         $ins = "insert into driver_status(driver_name,status,date_from,date_to) VALUES                   
  26.             ('".$driver_name[$k]."','$s','$from','$to')";
  27.         if (mysqli_query($conn, $ins)) {
  28.             echo "added";
  29.         } else {
  30.             echo "NOT" . mysqli_error($conn);
  31.         }
  32.     }
  33. }
  34.  
  35. $sel = 'select Driver_name from driver_master';
  36. $query = mysqli_query($conn, $sel);
  37.  
  38. echo "<form action='driver_status.php' method='post'>";
  39. echo "<table cellpadding=5>";
  40. echo "<tr>";
  41. echo "<th>Driver Name</th>";
  42. echo "<th>Status</th>";
  43. echo "<th>From</th>";
  44. echo "<th>To</th>";
  45. echo "</tr>";
  46. while($row=mysqli_fetch_assoc($query)){    
  47.      echo "<tr><td>".$row['Driver_name']
  48.            ."<input type=\"hidden\" name=\"driver_name[]\" value=\"".$row['Driver_name']."\"/></td>";
  49.      $sel1='select d_status from status';
  50.      $query1=mysqli_query($conn,$sel1);
  51.      echo "<td><select name=\"status[]\">";
  52.      while($row1=mysqli_fetch_assoc($query1)){
  53.            echo "<option value=\"".$row1['d_status']."\">".$row1['d_status']."</option>";
  54.      }
  55.      echo "</select></td>";
  56.      echo "<td>".'<input type="text" name="date_from" class="datepicker">'."</td>";
  57.      echo "<td>".'<input type="text" name="date_to" class="datepicker">'."</td>";
  58.      echo "</tr>";
  59. }
  60. echo "</table>";
  61. echo '<input type="submit" name="sub" value="Update"/>';
  62. echo "</form>";
  63. ?>
  64. </body>
  65. </html>
in above code i can store values from drop down boxes to database by using foreach loop but cant store date from jquery datepicker. Only last selected date is getting stored in database.
Mar 5 '15 #1
3 1527
Dormilich
8,658 Expert Mod 8TB
Only last selected date is getting stored in database.
because you only get one entry per input name if you don’t use bracket notation. dump the $_POST array to see the data PHP receives.

Note: mysqli_connect() never returns false, even if the connection fails.
Mar 5 '15 #2
SO, Plz can u tell me? what do i do?
Mar 9 '15 #3
Dormilich
8,658 Expert Mod 8TB
I recommend to use the bracket notation for the form field names.
Mar 11 '15 #4

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

Similar topics

2
by: Tom Petersen | last post by:
I have a drop down box where the choices are populated from a database query, this part works fine: <option value><% = strEmail %></option> I was wondering if it is possible to keep the value as...
4
by: kvrdev1 | last post by:
What reference do I need to add in to be able to use a date drop-down control within my web application? Thank you! -Valerie
2
by: rishu banerjee | last post by:
hi all. I'm new to ASP. can anyone help me in getting values of a drop down to be displayed in a textarea.say if we have the drop down elements as color, flower,..etc. as we select color, it should...
5
by: Slickuser | last post by:
Hi, I would like to use date() function show in the drop down menu start from today to next 1 Month. So it will be something like this. 4/3/2008 4/4/2008 4/5/2008
1
selvasoft
by: selvasoft | last post by:
Hi Please any one help me i want list out the values in drop down box. But the values from my database. How can am select that value from my database using JSP.give me example code pleas.
0
by: jimgym1989 | last post by:
Hi there, I have 2 PHP files, memeber.php & view.php This is my member.php while($row = mysql_fetch_array($strSQL)){ $data .= "<tr>"; $data .= "<td>"; $data .= "<input type='checkbox'...
1
by: Jincythomas | last post by:
I want to load multiple images using drop down list it has to be from database.My project is going to have 3 drop down list on the basis of each selection I need to load the images from...
4
by: geethasakthi | last post by:
hi friends, i need some help for my project.when i select the country in drop down menu automatically display the state and city. give some idea Thanks
1
by: manjm48 | last post by:
Drop down values not populating while opening MS Access application in 2010 version which is developed in 2000 version. But the same file while accessing through 2007 version of MS Access, the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.