Jump to content

Preselecting from dropdowns while querying the database for timestamp.


Recommended Posts

Hi, I'm having trouble with an event booking script that I'm making. I'm trying to allow a admin user to update a event by selecting the event from the list and passing the event id across (which is ok). On the next page I'm trying to prefill the data in the form from the database which I have done apart from the time is stored in the database as a timestamp for each event. I have used the $day = date("d", $timestamp); function to convert the time into a human readable format now I want to pre-select the date and time from the 5 drop downs (Day Month Year, Hour Minute). The drop down options aren't stored in the database but in the php file. Before I used the following syntax, but it won't work for this as the dropdown options arent in the database.

 

$query = "SELECT * FROM courses";
$result = mysql_query($query);

while($row = mysql_fetch_array($result))
  {
$test = $row[0];
if ($faculty_id == $row[0]){
echo"<option style='background: yellow'  value='$row[0]' selected>$row[1]</option>";
}
else{
echo"<option style='background: yellow'  value='$row[0]'>$row[1]</option>";
}

 

 

I would really appreciate your help on this as I'm getting really confused as I'm fairly new to php. The update page code is pasted below.

 

 

Thanks Very much,

 

Ian

 

 

<html>
<head>
<title>Update User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form id="form2" name="form2" method="post" action="updateevent_pc.php"><table width="579" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> 
  <tr> 
    <td width="598"><div align="center"> 
        <table width="579" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
          <tr> 
            <td colspan="3"><center>
                <p><strong>Update Event</strong>                </p>
                <p>Please use the form below to update details for the event you selected, if you don't want to change a field please leave the current value in. </p>
            </center></td>
          </tr>
<?php

$event_id = substr($_POST['event'], 0, 65); 

//Database Connection Details
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="abc123"; // Mysql password
$db_name="colab_booking"; // Database name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$query = "SELECT * FROM events WHERE event_id='$event_id'";
$result = mysql_query($query);

while($row = mysql_fetch_array($result))
  {
$eventname=$row[1];
$eventdescription=$row[2];
$timestamp=$row[3];
$eventlocation=$row[4];
$eventlimit=$row[5];

}
?>

          <tr> 
            <td width="237"><div align="right">Event Name: </div></td>
            <td width="5"></td>
            <td width="372"> <div align="left"> 
                <?php echo"<input name='evname' type='text' id='evname' value='$eventname' size='60' maxlength='60' />"?>
              </div></td>
          </tr>
          <tr> 
            <td><div align="right">Event Description: </div></td>
            <td> </td>
            <td> <div align="left"> 
			<?php echo"<input name='evdesc' type='text' id='evdesc' value='$eventdescription' size='60' maxlength='60' />"?>
              </div></td>
          </tr>
	  
	  <td><div align="right">Event Date/Time: </div></td>
            <td> </td>
            <td> <div align="left"> 
			<?php 
                $day = date("d", $timestamp);
			$month = date("m", $timestamp);
			$year = date("Y", $timestamp);
			$hour = date("H", $timestamp);
			$minute = date("i", $timestamp);

			?>
			 Date:<br />
  <select name="day">
    <option value="01" selected="selected">01</option>
    <option value="02">02</option>
    <option value="03">03</option>
    <option value="04">04</option>
    <option value="05">05</option>
<option value="06">06</option>
    <option value="07">07</option>
    <option value="08">08</option>
    <option value="09">09</option>
    <option value="10">10</option>
<option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
<option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
<option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
<option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
<option value="31">31</option>
  </select>
  <select name="month">
    <option value="01" selected="selected">January</option>
    <option value="02">February</option>
    <option value="03">March</option>
    <option value="04">April</option>
    <option value="05">May</option>
<option value="06">June</option>
    <option value="07">July</option>
    <option value="08">August</option>
    <option value="09">September</option>
    <option value="10">October</option>
<option value="11">November</option>
    <option value="12">December</option>
  </select>
  <select name="year">
      <option value="2007" selected="selected">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
  </select>
  <br />
  <br />
  Time:<br />
  <select name="hour">
    <option value="00" selected="selected">00</option>
    <option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
  </select>
  <select name="minute" id="minute">
    <option value="00" selected="selected">00</option>
    <option value="15">15</option>
    <option value="30">30</option>
    <option value="45">45</option>
  </select>
  
              </div></td>
          </tr>
         
          <tr> 
            <td><div align="right">Event Location: </div></td>
            <td> </td>
            <td><div align="left"> 
<?php echo"<input name='evloc' type='text' id='evloc' value='$eventlocation' size='60' maxlength='60' />"?>

              </div></td>
          </tr>
          <tr> 
            <td><div align="right">Event limit (No. of people): </div></td>
            <td> </td>
            <td><div align="left"> 
        <?php echo"<input name='evlimit' type='text' id='evlimit' value='$eventlimit' size='60' maxlength='60' />"?>
              </div></td>
          </tr>
          <tr> 
            <td><div align="right"></div></td>
            <td><?php echo"<input type='hidden' id='user_id' name='user_id' value='$user_id'>"; ?></td>
            <td> <div align="left"> 
                <input name="Submit2" type="submit" id="Submit2" value="Submit" />
                <input name="reset2" type="reset" id="reset2" value="Reset" />
            </div></td>
          </tr>
        </table>
      </div></td>
  </tr>
</form>
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.