Newbie working on a form and having problem w/$_SESSIONS()...

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 623 Views - Last Post: 19 February 2019 - 06:41 AM Rate Topic: -----

#16 vbtalent   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-February 19

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 13 February 2019 - 05:48 PM

So the print_r($_POST); doesn't seem to be generating anything for me but the form does appear to be posting data, see image.

I'm by far not even remotely acquainted with debugging php code but it looks like the browser has identified the information, why isn't the print_r() function doing the same???

VB,

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#17 vbtalent   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-February 19

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 13 February 2019 - 05:56 PM

a little more information... print_r($_SESSION) does contain the necessary item

Array ( [emplid] => 3 )
Was This Post Helpful? 0
  • +
  • -

#18 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6736
  • View blog
  • Posts: 27,734
  • Joined: 12-December 12

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 14 February 2019 - 01:54 AM

You only posted part of your logout form so it looks to be broken. It should have opening and closing <form> </form> tags.

For testing purposes I would add a dummy input to the form, in addition to just a submit button, with a simple name and value.
Was This Post Helpful? 0
  • +
  • -

#19 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2765
  • View blog
  • Posts: 10,958
  • Joined: 03-December 12

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 14 February 2019 - 08:42 AM

View Postvbtalent, on 13 February 2019 - 06:48 PM, said:

So the print_r($_POST); doesn't seem to be generating anything for me but the form does appear to be posting data, see image.


That makes me think you are not going where you think you are, or you are not putting the debug code in the correct place...

Remember, we are not over your should watching, we can only guess based on what you tell us.
Was This Post Helpful? 1
  • +
  • -

#20 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2239
  • View blog
  • Posts: 6,790
  • Joined: 15-January 14

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 14 February 2019 - 11:07 AM

The form you showed doesn't submit to login.php, so of course there's going to be no post data there.
Was This Post Helpful? 0
  • +
  • -

#21 vbtalent   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-February 19

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 14 February 2019 - 12:41 PM

Yes sorry, for not posting all of the code some of it is very specific and I'd like to avoid posting it on the web if at all possible.

I'm beginning to think that most of the issues I'm dealing with are from my lack of experience with passing values back and forth between pages and how to save a variable as it's passed. Also, my inexperience in PHP, which should be evident.

Ideally I'd like to set a variable that I could update from each page and then be able to reference it but I'm running into the problem of the page being sent to the interpreter and the variable getting wiped in the process.

In order to pass a variable between pages does it make sense to use a $_SESSION variable for that?

I appreciate the nudges and suggestions.

VB,
Was This Post Helpful? 0
  • +
  • -

#22 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2765
  • View blog
  • Posts: 10,958
  • Joined: 03-December 12

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 14 February 2019 - 12:48 PM

View Postvbtalent, on 14 February 2019 - 01:41 PM, said:

Ideally I'd like to set a variable that I could update from each page and then be able to reference it

That isn't the best solution, but with the experience level, it's to be expected.

View Postvbtalent, on 14 February 2019 - 01:41 PM, said:

but I'm running into the problem of the page being sent to the interpreter and the variable getting wiped in the process.

That isn't what happens. The interpreter doesn't wipe variables. Part of the issue is not understanding how web requests work from the sounds of it.

View Postvbtalent, on 14 February 2019 - 01:41 PM, said:

In order to pass a variable between pages does it make sense to use a $_SESSION variable for that?


It does, but it doesn't sound like you have a path to follow without creating god objects and that isn't something you should strive for.
Was This Post Helpful? 0
  • +
  • -

#23 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2239
  • View blog
  • Posts: 6,790
  • Joined: 15-January 14

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 14 February 2019 - 01:26 PM

When you're reading about requests and responses and how a server-side language fits in, keep in mind that every request is separate. Every request for a PHP page causes PHP to start up, execute whatever code is there, and shut down. Requests do not share anything that you haven't saved, via a session, a file, a cookie, a database, etc. You pass data to the server in a request using URL variables, post data, or cookies. Other than that, requests do not share anything or run at the same time or whatever else. Even if you have a PHP page that sends a location header to tell the browser to redirect, that redirection is a brand new request that does not share anything with the previous one.
Was This Post Helpful? 0
  • +
  • -

#24 vbtalent   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-February 19

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 14 February 2019 - 03:53 PM

Thank you for the link.

Since I'm struggling so mightily with this I've stripped this down a bit and hopefully seeing the source will help you help me. I've incorporated all the source in 3 pages now removing the process.php page while I was using trying to find what my problems are.

So, essentially I think I'm only having 1 problem which is storing/using the $GET() variables from the main.php page and the "UPDATE" functionality on the detail page for 2 fields (fm_ddstatusid,fm_jobnote), the recordset is not updating and the $_GET() variables are removed. I can't seem to get past the

Quote

if (isset($_POST['frmupdate'])){


All of the query's appear to working as expected on all 3 pages.

This is the main.php page

<?php require_once('/Connections/Shop.php'); ?>
<?php
session_start();

print_r($_POST);
print_r($_SESSION);
print_r($_GET);

//initialize the session and verify user is logged in and allowed to view site
if (!isset($_SESSION['emplid'])) {
		header("Location: login.php");
	}else{
		//user is valid, test for jobno and lineno or send them to the main.php page for selection
		if (isset($_GET['jobno'], $_GET['lineno'])) {
			//GET's from variables passed the JOB_NO and LINE_NO selected
			echo "jobpost";
			$job_no = $_GET['jobno'];
			$line_no = $_GET['lineno'];

			$result = $mysqli -> query("SELECT * FROM line_job WHERE JOB_NO=$job_no AND LINE_NO=$line_no") or die($mysqli->error);
		}else{
			header("Location: main.php");	
	}
}

//if user selected to go back to main page from detail page
if (isset($_POST['frmback'])){
		header("Location: main.php");
}

echo"before";
//if user selected to update the record update JOB_NOTES and STATID. The DETAIL page TABLE cell's don't POST so use a hidden text field instead
if (isset($_POST['frmupdate'])){
echo "after";
	$dd_statusid = $_POST['fm_ddstatusid']; 	//dropdown, if changed it needs to be written to DB. Curious about DEPARTMENT, how does it change?
	$job_note = $_POST['fm_jobnote'];			//JOB_NOTES in case its been updated
	$cust_no = $_POST['fm_custno'];				//needed for WHERE clause of update statement
	//$job_no = $_POST['fm_jobno'];				//needed for WHERE clause of update statement
	//$line_no = $_POST['fm_lineno'];			//needed for WHERE clause of update statement
	$of_total = $_POST['fm_oftotal'];			//needed for WHERE clause of update statement
	
	if (empty($oftotal)) {
		$oftotal = "NULL";
		//echo "NULL";
	}

	//$mysqli -> query("UPDATE line_job SET STATID='$dd_statusid', JOB_NOTES='$job_note' WHERE CUST_NO='$cust_no' AND JOB_NO=$job_no AND LINE_NO=$line_no AND OF_TOTAL=$of_total") or die($mysqli->error);
	
	$_SESSION['message'] = "Record updated!";
	
	header("Location: detail.php?jobno='$jobno'&lineno='$lineno'");
}

//detail page usage for JOB_LEVEL
function stoplight_detail($JL) {
	if ($JL == 1) {
		echo "QUICK";
	} elseif ($JL ==2) {
		echo "GOOD";
	} elseif ($JL ==3) {
		echo "PICKY";	
	} else  {
		echo "";						
	}
}
?>

<!doctype html>
<html lang="en">
<html>
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" src="/css/bootstrap.min.css">
    <link href="/css/bootstrap.css" rel="stylesheet" type="text/css">
  <title>ExcelShop-Detail</title>

</head>

<body>

<?php
	if (isset($_SESSION['message'])): ?>
	<div class="alert alert-success">
		<?php
			echo $_SESSION['message'];
			unset($_SESSION['message']);
		?>
	</div>
<?php endif ?>
	
<form  method="post" action=<?php echo $_SERVER['PHP_SELF'];?>>
	<table class="table table-responsive-*">
		<?php while($data = $result->fetch_assoc()): ?>
			  <tr>
				<td colspan="6" class="p-sm-0 pl-sm-5 font-weight-bold" align="center"><h2>Job Detail</h2>
			  </tr>
			  <tr>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>WIP</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Department</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body" colspan="4"><b>Responsible Party</b></td>
			  </tr>
			  <tr>
				<td width="123" class="pl-sm-5">
					<select name="fm_ddstatusid">
						<option value"complete" <?php if($data['STATID'] == 'C'){ echo ' selected="selected"'; } ?>>C</option>
						<option value"done" <?php if($data['STATID'] == 'D'){ echo ' selected="selected"'; } ?>>D</option>
						<option value"finish" <?php if($data['STATID'] == 'F'){ echo ' selected="selected"'; } ?>>F</option>
						<option value"material" <?php if($data['STATID'] == 'M'){ echo ' selected="selected"'; } ?>>M</option>
						<option value"stripping" <?php if($data['STATID'] == 'S'){ echo ' selected="selected"'; } ?>>S</option>
						<option value"upholstery" <?php if($data['STATID'] == 'U'){ echo ' selected="selected"'; } ?>>U</option>
						<option value"wood" <?php if($data['STATID'] == 'W'){ echo ' selected="selected"'; } ?>>W</option>
					</select>
				</td>
				<td width="123" class="pl-sm-5"><?php echo $data['STATUS'];?></td>
				<td colspan="4" class="pl-sm-5"><?php echo $data['RESP_PRTY'];?></td>
			  </tr>
			  <tr>
				<td class="p-sm-0 pl-sm-5 bg-light text-body" colspan="2"><b>Customer Name</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Cust. #</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Job #</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Pieces</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Total # Pieces</b></td>
			  </tr>
			  <tr>
				<td colspan="2" class="pl-sm-5"><?php echo $data['L_NAME'];?>, <?php echo $data['F_NAME'];?></td>
				<td width="107" class="pl-sm-5"><?php echo $data['CUST_NO'];?><input type="hidden" name="fm_custno" value=<?php echo $data['CUST_NO'];?>></td>
				<td width="85" class="pl-sm-5"><?php echo $data['JOB_NO'];?><input type="hidden" name="fm_jobno" value=<?php echo $data['JOB_NO'];?>></td>
				<td width="80" class="pl-sm-5"><?php echo $data['LINE_NO'];?><input type="hidden" name="fm_lineno" value=<?php echo $data['LINE_NO'];?>></td>
				<td width="185" class="pl-sm-5"><?php echo $data['OF_TOTAL'];?><input type="hidden" name="fm_oftotal" value=<?php echo $data['OF_TOTAL'];?>></td>
			  </tr>
			  <tr>
				<td colspan="2" rowspan="8"><?php echo $data['JOB_PHOTO1'];?></td>
				<td colspan="3" rowspan="8"><?php echo $data['JOB_PHOTO2'];?></td>
				<td class="pl-sm-5 bg-light text-body"><b>Start</td>
			  </tr>
			  <tr>
				<td class="pl-sm-5"><?php echo $data['START_DATE'];?></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5 bg-light text-body"><b>End</b></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5"><?php echo $data['END_DATE'];?></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5 bg-light text-body"><b>Quality</b></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5"><?php echo stoplight_detail($data['JOB_LEVEL']);?></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5 bg-light text-body"><b>Holiday Hot</b></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5 text-danger font-weight-bold"><?php echo $data['HOLIDAY_HOT'];?></td>
			  </tr>
			  <tr>
				<td class="p-sm-0 pl-sm-5 bg-light text-body" colspan="6"><b>Description</b></td>
			  </tr>
			  <tr>
				<td colspan="6" class="pl-sm-5"><?php echo $data['DESCRIPTIN'];?></td>
			  </tr>
			  <tr>
				<td class="p-sm-0 pl-sm-5 bg-light text-body" colspan="6"><b>Job Notes</b></td>
			  </tr>
			  <tr>
				<td colspan="6" class="pl-sm-5"><textarea class="scrollabletextbox bg-light" cols="100" name="fm_jobnote"><?php echo $data['JOB_NOTES'];?></textarea></td>
			  </tr>
			  <tr>
				<td colspan="6" align="center"><button type="submit" class="btn btn-secondary" name="frmback">BACK</button>
				&nbsp;&nbsp;&nbsp;<button type="submit" class="btn btn-primary" name="frmupdate">UPDATE</button></td>
			  </tr>
			<?php endwhile;?>
	</table>
</form>
</body>
</html>



and the detail.php page

<?php require_once('/Connections/Shop.php'); ?>
<?php
session_start();

print_r($_POST);
print_r($_SESSION);
print_r($_GET);

//initialize the session and verify user is logged in and allowed to view site
if (!isset($_SESSION['emplid'])) {
		header("Location: login.php");
	}else{
		//user is valid, test for jobno and lineno or send them to the main.php page for selection
		if (isset($_GET['jobno'], $_GET['lineno'])) {
			//GET's from variables passed the JOB_NO and LINE_NO selected
			echo "jobpost";
			$job_no = $_GET['jobno'];
			$line_no = $_GET['lineno'];

			$result = $mysqli -> query("SELECT * FROM line_job WHERE JOB_NO=$job_no AND LINE_NO=$line_no") or die($mysqli->error);
		}else{
			header("Location: main.php");	
	}
}

//if user selected to go back to main page from detail page
if (isset($_POST['frmback'])){
		header("Location: main.php");
}

echo"before";
//if user selected to update the record update JOB_NOTES and STATID. The DETAIL page TABLE cell's don't POST so use a hidden text field instead
if (isset($_POST['frmupdate'])){
echo "after";
	$dd_statusid = $_POST['fm_ddstatusid']; 	//dropdown, if changed it needs to be written to DB. Curious about DEPARTMENT, how does it change?
	$job_note = $_POST['fm_jobnote'];			//JOB_NOTES in case its been updated
	$cust_no = $_POST['fm_custno'];				//needed for WHERE clause of update statement
	//$job_no = $_POST['fm_jobno'];				//needed for WHERE clause of update statement
	//$line_no = $_POST['fm_lineno'];			//needed for WHERE clause of update statement
	$of_total = $_POST['fm_oftotal'];			//needed for WHERE clause of update statement
	
	if (empty($oftotal)) {
		$oftotal = "NULL";
		//echo "NULL";
	}

	//$mysqli -> query("UPDATE line_job SET STATID='$dd_statusid', JOB_NOTES='$job_note' WHERE CUST_NO='$cust_no' AND JOB_NO=$job_no AND LINE_NO=$line_no AND OF_TOTAL=$of_total") or die($mysqli->error);
	
	$_SESSION['message'] = "Record updated!";
	
	header("Location: detail.php?jobno='$jobno'&lineno='$lineno'");
}

//detail page usage for JOB_LEVEL
function stoplight_detail($JL) {
	if ($JL == 1) {
		echo "QUICK";
	} elseif ($JL ==2) {
		echo "GOOD";
	} elseif ($JL ==3) {
		echo "PICKY";	
	} else  {
		echo "";						
	}
}
?>

<!doctype html>
<html lang="en">
<html>
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" src="/css/bootstrap.min.css">
    <link href="/css/bootstrap.css" rel="stylesheet" type="text/css">
  <title>ExcelShop-Detail</title>

</head>

<body>

<?php
	if (isset($_SESSION['message'])): ?>
	<div class="alert alert-success">
		<?php
			echo $_SESSION['message'];
			unset($_SESSION['message']);
		?>
	</div>
<?php endif ?>
	
<form  method="post" action=<?php echo $_SERVER['PHP_SELF'];?>>
	<table class="table table-responsive-*">
		<?php while($data = $result->fetch_assoc()): ?>
			  <tr>
				<td colspan="6" class="p-sm-0 pl-sm-5 font-weight-bold" align="center"><h2>Job Detail</h2>
			  </tr>
			  <tr>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>WIP</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Department</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body" colspan="4"><b>Responsible Party</b></td>
			  </tr>
			  <tr>
				<td width="123" class="pl-sm-5">
					<select name="fm_ddstatusid">
						<option value"complete" <?php if($data['STATID'] == 'C'){ echo ' selected="selected"'; } ?>>C</option>
						<option value"done" <?php if($data['STATID'] == 'D'){ echo ' selected="selected"'; } ?>>D</option>
						<option value"finish" <?php if($data['STATID'] == 'F'){ echo ' selected="selected"'; } ?>>F</option>
						<option value"material" <?php if($data['STATID'] == 'M'){ echo ' selected="selected"'; } ?>>M</option>
						<option value"stripping" <?php if($data['STATID'] == 'S'){ echo ' selected="selected"'; } ?>>S</option>
						<option value"upholstery" <?php if($data['STATID'] == 'U'){ echo ' selected="selected"'; } ?>>U</option>
						<option value"wood" <?php if($data['STATID'] == 'W'){ echo ' selected="selected"'; } ?>>W</option>
					</select>
				</td>
				<td width="123" class="pl-sm-5"><?php echo $data['STATUS'];?></td>
				<td colspan="4" class="pl-sm-5"><?php echo $data['RESP_PRTY'];?></td>
			  </tr>
			  <tr>
				<td class="p-sm-0 pl-sm-5 bg-light text-body" colspan="2"><b>Customer Name</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Cust. #</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Job #</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Pieces</b></td>
				<td class="p-sm-0 pl-sm-5 bg-light text-body"><b>Total # Pieces</b></td>
			  </tr>
			  <tr>
				<td colspan="2" class="pl-sm-5"><?php echo $data['L_NAME'];?>, <?php echo $data['F_NAME'];?></td>
				<td width="107" class="pl-sm-5"><?php echo $data['CUST_NO'];?><input type="hidden" name="fm_custno" value=<?php echo $data['CUST_NO'];?>></td>
				<td width="85" class="pl-sm-5"><?php echo $data['JOB_NO'];?><input type="hidden" name="fm_jobno" value=<?php echo $data['JOB_NO'];?>></td>
				<td width="80" class="pl-sm-5"><?php echo $data['LINE_NO'];?><input type="hidden" name="fm_lineno" value=<?php echo $data['LINE_NO'];?>></td>
				<td width="185" class="pl-sm-5"><?php echo $data['OF_TOTAL'];?><input type="hidden" name="fm_oftotal" value=<?php echo $data['OF_TOTAL'];?>></td>
			  </tr>
			  <tr>
				<td colspan="2" rowspan="8"><?php echo $data['JOB_PHOTO1'];?></td>
				<td colspan="3" rowspan="8"><?php echo $data['JOB_PHOTO2'];?></td>
				<td class="pl-sm-5 bg-light text-body"><b>Start</td>
			  </tr>
			  <tr>
				<td class="pl-sm-5"><?php echo $data['START_DATE'];?></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5 bg-light text-body"><b>End</b></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5"><?php echo $data['END_DATE'];?></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5 bg-light text-body"><b>Quality</b></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5"><?php echo stoplight_detail($data['JOB_LEVEL']);?></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5 bg-light text-body"><b>Holiday Hot</b></td>
			  </tr>
			  <tr>
				<td class="pl-sm-5 text-danger font-weight-bold"><?php echo $data['HOLIDAY_HOT'];?></td>
			  </tr>
			  <tr>
				<td class="p-sm-0 pl-sm-5 bg-light text-body" colspan="6"><b>Description</b></td>
			  </tr>
			  <tr>
				<td colspan="6" class="pl-sm-5"><?php echo $data['DESCRIPTIN'];?></td>
			  </tr>
			  <tr>
				<td class="p-sm-0 pl-sm-5 bg-light text-body" colspan="6"><b>Job Notes</b></td>
			  </tr>
			  <tr>
				<td colspan="6" class="pl-sm-5"><textarea class="scrollabletextbox bg-light" cols="100" name="fm_jobnote"><?php echo $data['JOB_NOTES'];?></textarea></td>
			  </tr>
			  <tr>
				<td colspan="6" align="center"><button type="submit" class="btn btn-secondary" name="frmback">BACK</button>
				&nbsp;&nbsp;&nbsp;<button type="submit" class="btn btn-primary" name="frmupdate">UPDATE</button></td>
			  </tr>
			<?php endwhile;?>
	</table>
</form>
</body>
</html>

Was This Post Helpful? 0
  • +
  • -

#25 vbtalent   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-February 19

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 15 February 2019 - 08:38 AM

I believe I'm narrowing in on the problem and it has to do with the redirection to the detail page after the form submit.

header("Location: detail.php?jobno='$jobno'&lineno='$lineno'");

when I comment this item out, I see all the $_POST items in the array being passed.

Quote

Array ( [fm_ddstatusid] => C [fm_custno] => 4687163 [fm_jobno] => 59443 [fm_lineno] => 1 [fm_oftotal] => 1 [fm_jobnote] => [frmupdate] => ) Array ( [message] => Record updated! )

So, I think my real problem is how do I redirect the 'submit' to itself with the variables for '$jobno' and '$lineno'?

VB,
Was This Post Helpful? 0
  • +
  • -

#26 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6736
  • View blog
  • Posts: 27,734
  • Joined: 12-December 12

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 15 February 2019 - 08:43 AM

I would first test by removing those single quotes.
Was This Post Helpful? 0
  • +
  • -

#27 vbtalent   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-February 19

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 15 February 2019 - 09:06 AM

I went back to using a separate page for processing, dtlprocess.php. It was helpful in debugging the $_POST issues I thought I was having.

When I added the page I added the following to the body of the detail.php page:

<?php require_once('dtlprocess.php'); ?>
<form  method="post" action="dtlprocess.php">


and on the dtlprocess.php page I added

session_start();

but now I'm getting an error,

( ! ) Notice: session_start(): A session had already been started - ignoring in C:\wamp64\www\Shop\dtlprocess.php on line 3
Call Stack
# Time Memory Function Location
1 0.0001 403912 {main}( ) ...\detail.php:0
2 0.0032 454064 require_once( 'C:\wamp64\www\Shop\dtlprocess.php' ) ...\detail.php:48
3 0.0032 454064 session_start ( ) ...\dtlprocess.php:3


This confuses me, why doesn't it reference the open $_SESSION? and am I doing something wrong?

VB,
Was This Post Helpful? 0
  • +
  • -

#28 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6736
  • View blog
  • Posts: 27,734
  • Joined: 12-December 12

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 15 February 2019 - 09:27 AM

Isn't that just a warning? searching the error finds this and

<?php
    if(!isset($_SESSION)) 
    { 
        session_start(); 
    } 
?>


Quote

why doesn't it reference the open $_SESSION? and am I doing something wrong?

It is, that's why it gives a warning.



I wouldn't keep modifying your code so much; you'll lose sight of the errors/issues, as will we.

Concentrate on the parts - or part, in the first instance - that isn't working. Narrow it down as much as possible. Even comment out blocks that you are certain are working correctly to focus on the area(s) of concern. Even disable any database interaction to focus on the issues over receiving get/post data and reading session data.

Enable all error reporting.
Was This Post Helpful? 0
  • +
  • -

#29 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2239
  • View blog
  • Posts: 6,790
  • Joined: 15-January 14

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 15 February 2019 - 10:11 AM

Also, if you're ever going to redirect a user, you should use exit or die after that to stop execution. If you're redirecting I don't think you want to execute all of the code after you send the header.
Was This Post Helpful? 0
  • +
  • -

#30 vbtalent   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 13-February 19

Re: Newbie working on a form and having problem w/$_SESSIONS()...

Posted 15 February 2019 - 11:30 AM

Thanks, yeah I know I'm getting a little squirly with the code moving it around but I was trying to do a better job of isolating my problem, since I think I may have more than issue. I have disabled any update query's but need the rest of the data to be able to test with. With regard to error checking, is there a better tool than print_r() that I can incorporate into the code?

I've created a new page dtlprocess.php with the following code moved from detail.php.

<?php require_once('../XLShop/Connections/Shop.php'); ?>
<?php
	if(!isset($_SESSION))
	{
		session_start();
	}
	
print_r($_POST);

//if user selected to go back to main page from detail page
if (isset($_POST['frmback'])){
		header("Location: main.php");
}

//if user selected to update the record update JOB_NOTES and STATID. The DETAIL page TABLE cell's don't POST so use a hidden text field instead
if (isset($_POST['frmupdate'])){

	$dd_statusid = $_POST['fm_ddstatusid']; 	//dropdown, if changed it needs to be written to DB. Curious about DEPARTMENT, how does it change?
	$job_note = $_POST['fm_jobnote'];			//JOB_NOTES in case its been updated
	$cust_no = $_POST['fm_custno'];				//needed for WHERE clause of update statement
	$jobno = $_POST['fm_jobno'];				//needed for WHERE clause of update statement
	$lineno = $_POST['fm_lineno'];				//needed for WHERE clause of update statement
	$of_total = $_POST['fm_oftotal'];			//needed for WHERE clause of update statement
	
	if (empty($of_total)) {
		$of_total = "NULL";
	}

	//$mysqli -> query("UPDATE line_job SET STATID='$dd_statusid', JOB_NOTES='$job_note' WHERE CUST_NO='$cust_no' AND JOB_NO=$job_no AND LINE_NO=$line_no AND OF_TOTAL=$of_total") or die($mysqli->error);

	$_SESSION['message'] = "Record updated!";
	print_r($_SESSION);
	
	header("Location: detail.php?jobno=$jobno&lineno=$lineno");
	exit();
}

//detail page usage for JOB_LEVEL
function stoplight_detail($JL) {
	if ($JL == 1) {
		echo "QUICK";
	} elseif ($JL ==2) {
		echo "GOOD";
	} elseif ($JL ==3) {
		echo "PICKY";	
	} else  {
		echo "";						
	}
}	 
?>


and modified the detail page with the require_once and action""

<?php require_once('dtlprocess.php'); ?>
<form  method="post" action="dtlprocess.php">


andrewsw, I get the test for an open $_session but it seems odd to me that on the main.php page I have the same code and I don't get an error..

Quote

session_start();


ArtificialSoldier, I'll incorporate that after the redirect, thanks.


So shouldn't the $_SESSION['message'] = "Record updated!"; still be available to print_r($_SESSION); on the detail.php page after the redirect header("Location: detail.php?jobno=$jobno&lineno=$lineno");?

VB,
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3