www.webdeveloper.com
Results 1 to 6 of 6

Thread: insert echo value into database

  1. #1
    Join Date
    Aug 2014
    Posts
    3

    insert echo value into database

    how to insert the echo value of staff id and leave type into database along with the date value when submit button is being clicked?

    HTML Code:
    <form id="status" name="status" method="post" action="process.php">
    	<label>Staff ID</label><input type="text" name="lstaffid" value="<?php echo $leavesid;?>" disabled><br/>
    	<label>Leave Type </label>
    	<select name="leavetype" disabled>
    	<option value="" selected="selected"  disabled>Select Leave Type</option>
    	<option value="AL" <?php if ($leavetype =="AL") echo "selected='selected'";?> disabled>AL</option>
    	<option value="MC" <?php if ($leavetype =="MC") echo "selected='selected'";?> disabled>MC</option>
    	<option value="MR" <?php if ($leavetype =="MR") echo "selected='selected'";?> disabled>MR</option>
    	<option value="MT" <?php if ($leavetype =="MT") echo "selected='selected'";?> disabled>ML</option>
    	<option value="RL" <?php if ($leavetype =="RL") echo "selected='selected'";?> disabled>RL</option>
    	</select>
    	<label>Date:-&nbsp;<b>FROM</b></label><input type="date" name="ldatefrom" value="<?php echo $leavedatefrom;?>" disabled>
    	<label><b>TO</b></label> <input type="date" name="ldateto" value="<?php echo $leavedateto;?>" disabled><br>
    	<?php
    	$startDate = strtotime($datefrom);  
    	$endDate = strtotime($dateto);  
    	$date = $startDate;  
    		while( $date <= $endDate) {	
    		echo  "<input type='hidden' name='nondate[]' value ='".date('Y-m-d', $date)."'>";
    		echo  "<input type='checkbox' name='date[]' value ='".date('Y-m-d', $date)."'>";
    		echo date('Y-m-d', $date) .'&nbsp;';  
    		$date = strtotime('+1 day', $date); 
    	}
    	?>
    	<br/><input id="submit_hod" type="submit" name="submit">
    	</form>
    PHP Code:
    <?php
        
    include('connect.php');
        
        
    $checked =  ($_POST['date']);
        
    $unchecked = ($_POST['nondate']);
        
    $diff array_diff($unchecked,$checked);

                if(isset(
    $_POST['date']))
                {
                    foreach (
    $_POST['date'] as $dateValue)
                    {
                                
    $insert="INSERT INTO approve_date($colm_ladate) VALUES ('$dateValue')";
                                
    mysql_query($insert);
                    }
                                echo 
    header("location:home.php");
                }
                if (isset(
    $_POST['nondate']))
                {
                    foreach (
    $diff as $dateValue2)
                    {
                        
    $insert2="INSERT INTO reject_date($colm_lrdate) VALUES ('$dateValue2')";
                        
    mysql_query($insert2);
                        
                    }
                    echo 
    header("location:home.php");
                }

    ?>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    728
    Not sure what the problem here is. Are you asking for help in writing an update query? I don't see one in your code, only inserts. Are you adding records with this input data or updating?
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  3. #3
    Join Date
    Aug 2014
    Posts
    3
    Hi, thanks for the reply.

    i have a form, and the form already displayed the STAFF_ID which get from sql SELECT.
    This STAFF_ID field is already disabled to update, only allowed user to READ.
    Howewer, in this form, the DATE checkbox is allow to do selection.

    So, i want to know,
    How to get the STAFF_ID to be inserted into database (another table) again, when i click at the submit button,
    so that it can be sending to database along with the DATE values being selected.

    Because, with the code now,
    i only able to insert the DATE values into database without the STAFF_ID...
    can u kindly assist me on this? thank you so much.....

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    728
    You simply add your fields to your query statement. Do you not know how to write a query? (Which BTW is not php)
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  5. #5
    Join Date
    Aug 2014
    Posts
    3
    Hi, there. i have done it just by removing the "disabled" and replace it by "readonly". thanks alot!

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    728
    Makes no sense... But if you're happy, I'm happy.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles