473,383 Members | 1,815 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,383 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 1530
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...
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: 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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.