Jump to content

Selecting username from select box then pressing submit and gathering that data to use


Recommended Posts

I am looking for some help as I cannot understand the logic of how I do what I want. 

This is what I am trying to do:
- Use two select boxes, one to select a user name, another to select the date.
- After selecting that information, press submit button and then hold that information in two variables..
- After submit button is pressed, use the two variables to execute this task: 


Code:
SELECT * FROM timesheet_submission where user_id='$employee_id' and date between '$date_id' and date_add('$date_id', interval 6 day);

- Then use that information and select each piece from the generated table and store in variables. 
This is the bit I am struggling with: 
- I want to use the stored variables and then print that information in another .php page.

I am not sure how to actually do this?

I can pull the data correctly by doing the following, it pulls the data and generates a select box form from the correct table in the database and uses "selected" to select the correct variable so it will automatically select that particular on in the list.  


PHP Code:
  <?php  
                      
include_once('db_const.php'); 
               
                      
//SQL to set up Select Box 
                      
mysql_select_db('timesheet') or die(mysql_error()); 
                      
$sql =mysql_query("SELECT * FROM am_task") or die (mysql_error()); 
             
                      
$sql1 =mysql_query("SELECT * from timesheet_submission;") or die (mysql_error());  
                      
$result1 mysql_fetch_array$sql1 ); // Get array of All Monday Tasks 
                      
$test1 =$result1['monday_am_task']; // print the ID  
                           
                      
echo '<select name="monday combo" id="Moncombo1">  
                      <option value= " ">Please Select</option>'
;         
                           
                      
// Populate Select Box 
                      
while ($test mysql_fetch_array$sql))  
                      {               
                      if(
$test['am_id']==$test1
                      { 
                          echo 
'<option value="'.$test['am_id'].'" selected>'.$test['am_task'].'</option>'
                      } 
                      else 
                      { 
                          echo 
'<option value="'.$test['am_id'].'">'.$test['am_task'].'</option>'
                      } 
                      } 

                      echo 
'<select selected="'.$test1.'"></select>'
                      echo 
'</select>';            
                    
?>

This is done inside of the my main.php though, I want to execute this when I click the submit button. However I want to make this dynamic, so when the user is selected, and the date is select, get the values from the database and insert as shown above.  

This is my submit.php 


PHP Code:
<?php 
//§error_reporting(E_ALL); 

    
$date_id $_POST['datecombo']; // use POST to create variables 
    
$employee_id $_POST['employeecombo1'];  // use POST to create variables 
    //print $date_id; // make sure it is grabbing the right date that has been selected from the select box 
    //print $employeecombo1; // make sure it is grabbing the right employee that has been selected from the select box 

     
$link mysql_connect("127.0.0.1""root""") or die(mysql_error()); 
    
mysql_select_db("timesheet",$link) or die(mysql_error());         

// selects all the data  
    
$SQL mysql_query("SELECT * FROM timesheet_submission where user_id='$employee_id' and date between '$date_id' and date_add('$date_id', interval 6 day); "); 
    
$result mysql_fetch_array($SQL); 
    
$iam =$result['date'];// this prints '2015-04-10'  
    
$iam2 =$result['user_id']; // this prints '1' 
    
$iam3 =$result['monday_am_task']; // this prints '5'

Hopefully this will all make sense smile.gif

The code you have posted is so disjoint that it makes it difficult to see what you are doing. I think I know what you want to do, and that itself is very simple, but the code you posted makes it hard to provide answers.

 

Look at it from our point of view. Would you understand if you didn't already know what you are doing?

 

1 - build the page for the user using your db data.

2 - let the user see the page and click on stuff

3 - handle the submitted page by grabbing the POST elements

4 - use the grabbed elements to run a query

5 - use the query results to build the results page.

 

That's the basic scenario

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.