Jump to content

HELP! so confused on this one...


jbrill

Recommended Posts

hey guys, im new to php, but have been managing pretty well with it so far. however now i am completely confused.

Let me take a minute to explain what im doing. I am currently creating a job management program for a company, each employee can log in and add his/her hours and tick off the assigned jobs that are complete.

 

Im having a problem with the page where the hours are added, and then inserted into the database, it seems to temporarily erase all their "session" info such as their first name last name etc. when i log out, and the log back in, it all appears again. so i knwo it is not wiping it from the database, just the current session....

 

i know that might be a bit confusing what i just described so if you have any questions please ask me. I really need to figure this out as it is the last part of the project (i hope)

<?
include 'admin_header.php';

// this page loads new product information. Action at top, form at bottom
$jobid = $_GET['jobid'];
$stepid = $_GET['idr'];
$sessionid = $_SESSION['id'];


// this part validates whether the user is logged in as a administrator or not
if(isset($_SESSION['id']))
{

// execute the real stuff if the login is valid

include 'admin_jobmenu.php';


?>

<div align="center">

<!-- end header -->



<?php

// Query starts here
//query for adding time

$user = "SELECT * FROM users WHERE id=$sessionid";
$user = mysql_query($user);
$session = mysql_fetch_array($user);
$firstname =  $session['first_name'];
$lastname = $session['last_name'];


//query for the actual process
$sql = "SELECT * FROM guestbook WHERE id=$stepid";
$sql = mysql_query($sql);
$product = mysql_fetch_array($sql);
$cursubcat = $product['subcat'];


// for posting changes to the actual process
if($_POST['hours']!="")
{

$update = 'INSERT INTO workhours (jobid, stepid, date, name, hours, timenotes) VALUES ("'.$_POST['jobid'].'","'.$_POST['stepid'].'","'.$_POST['date'].'","'.$_POST['name'].'","'.$_POST['hours'].'","'.$_POST['timenotes'].'")';

echo $update."<br>";
mysql_query($update);

echo "<table align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\" class=\"tableoutline\">
<tr>
<td class=\"success\">";
echo 'Step Was Updated Successfuly!';
// code to update cost and actualhours

$sql2 = "SELECT * FROM guestbook WHERE id=$stepid";
$sql2 = mysql_query($sql2);
$product2 = mysql_fetch_array($sql2);



// for posting changes to the actual process
if($_POST['submit']!="")
{
$update = "UPDATE guestbook SET actual_time='".$_POST['actual_time']."', complete='".$_POST['complete']."', cost='".$_POST['cost']."' WHERE id=$stepid";
}

$sumsql = "SELECT SUM(hours) AS totalhours FROM workhours WHERE jobid=$jobid AND stepid=$stepid;";
$sums = mysql_query($sumsql);
$sum = mysql_fetch_array($sums);

$totalhours = $sum['totalhours']; 
?>

<form name="UpdateInfo" method="get" action="updateinfo.php">
<?
echo '<table border="1">';
	echo '<tr>';
		echo '<td>';
		?>	<input type="text" name="name" class="inputbox" size="40" value="<? echo $firstname;  echo ' '; echo $lastname; ?>">
			<input name="jobid" type="text" id="jobid" size="15"  value="<? echo $jobid; ?>"/><br>
			<input name="stepid" type="text" id="stepid" size="15"  value="<? echo $stepid; ?>"/><br>
			<input name="actual_time" type="text" id="actual_time" size="15"  value="<? echo $totalhours; ?>"/><br>
			What Is The Current Status for this step? &nbsp
<input type="Checkbox" name="complete" value="Incomplete" <? if($product['complete']==Incomplete){echo "checked";}?>> Incomplete  
<input type="Checkbox" name="complete" value="Complete" <? if($product['complete']==Complete){echo "checked";}?>> Complete
			<input type="submit" value="Finish">

		<?
		echo '</td>';
	echo '</tr>';
echo '</table>';
echo '</form>';

echo '</td></tr></table>';


}
else
{
?>
<center><a href="<? echo "admin_modprocess.php?idr=$jobid&table=jobs" ?>">Back to Job Process</a></center>
<br>
<form name="CreateProduct" method="post" enctype="multipart/form-data" action="<?php echo $_PHP_SELF; ?>">

<input name="quote_id" type="text" id="job_id" size="15"  value="<? echo $jobid; ?>"/>
<input name="quote_id" type="text" id="quote_id" size="15"  value="<? echo $stepid?>"/>
<?
$sumsql = "SELECT SUM(hours) AS totalhours FROM workhours WHERE jobid=$jobid AND stepid=$stepid;";
$sums = mysql_query($sumsql);
$sum = mysql_fetch_array($sums);

$totalhours = $sum['totalhours']; 

?>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">

<br>

<center><font class="section">Hours For This Step</font><br>
Once your time is added it cannot be modified or deleted, please make sure it is correct!</center>

<table border="0" bgcolor="#ffffff"  class="MainBody1"  align="center">

<tr>
<td>
<input type="hidden" name="jobid" value="<? echo $jobid; ?>" size=20>
<input type="hidden" name="stepid" value="<? echo $stepid; ?>" size=20>
<input type="hidden" name="date" value="<? echo $currentdate; ?>" size=20>

<? echo $firstname;  echo ' '; echo $lastname; echo "'s "; ?>

<input type="hidden" name="name" class="inputbox" size="40" value="<? echo $firstname;  echo ' '; echo $lastname; ?>">
Hours: <input type="text" name="hours" class="inputbox" size="3"> 
Notes: <input type="text" name="timenotes" class="inputbox" size="40">

<input type="submit" value="Add Time">

</td>
</tr>
</table>
</form>

<?
}

echo '<br>';
include 'display_hoursworked.php';

?>



</form>
<?
}



?>
</td>
</tr>

</table>	</td></tr>
</table>					<!-- begin footer --></div>
<?







?>
<br>
		</td>
	</tr>
</table>
<br>
<?
require 'admin_footer.php';

 

As you can see im my code, the main form with the hours imputed (its towards the bottom of the code) and then it submits the form and displays the next form, where the actual time, and a few other variables are inserted into another table ( this needs to be done in 2 steps to achieve the final effect i have in mind) but it seems as though the session info is being lost at the second form... any ideas?

Link to comment
Share on other sites

okay for me. I can include session_start(); from another file. BUT I have to REGISTER the session values when they are set.

 

Example:

register_session("id");

$_SESSION['id'] = 1;

 

Thus $_SESSION['id'] was just REGSITERED as 1 and will always be one unless re-registered.

Link to comment
Share on other sites

If I remember right from my experience, you can't include the session_start();, or at least it didn't work for me.

 

You can include session_start() without problem.

 

I'm sorry, but I find your code pretty hard to follow, there is no indentation and your very inconsistant with yourchoice of <? or <?php tags (stick to <?php).

 

The only error I can really see is.... <?php echo $_PHP_SELF; ?>. There is no such variable as $_PHP_SELF. If you just want to post to self the best way is to just leave the forms action attributer out all together. Othersie, the variable your looking for is $_SERVER['PHP_SELF'].

Link to comment
Share on other sites

okay for me. I can include session_start(); from another file. BUT I have to REGISTER the session values when they are set.

 

Example:

register_session("id");

$_SESSION['id'] = 1;

 

Thus $_SESSION['id'] was just REGSITERED as 1 and will always be one unless re-registered.

 

The function is session_register and has long been depricated and should no longer be used.

Link to comment
Share on other sites

tried both suggestions.... man this is just messed..

 

its honestly wiping all data from the session so for example, on the home page it says welcome back: firstname last name after i process the the page above, it only says welcome back:                        .... i just dont get what would cause it..

Link to comment
Share on other sites

register_session() is not needed.

 

after a session is started, you may do as many of $_SESSION['varname'] = 'varvalue'; as you want and they'll all get tossed in.

 

At leats that is the case with version 4.0 and up - you could have been on an older version, clanstyles.

 

cheers.

Link to comment
Share on other sites

double check all form methods - GET and POST to ensure the right ones are passing through. the stuff up there should be ideally handled all through POST anyhow to keep URL clean and prevent any tampering.

 

Also ensure all <form> tags are opened and closed properly withotu duplicate opens or runons or closes.

Link to comment
Share on other sites

all that is checked still no luck, it is loosing the session id when sending the info fromt he 2nd form to the file updateinfo.php. prior to updateinfo.php the session id is 16 on update info it is 1... thats the reason it isnt working, but why is it doing that is a nother question.

Link to comment
Share on other sites

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.