Jump to content

Robinson

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by Robinson

  1. By "a (weird) mechanism ", I assume you mean these lines: function includeFile($file,$variable) { $var = $variable; include($file); } Could get rid of this line and the pidForApproval can get passed into the included file automatically? Is it advisable? Thanks.
  2. First let me explain my code. It comprises of three php files. inc_fn_header_and_menu.php, contains the HTML and CSS header details and it initializes the session via session_start(); This is later included in project_status.php] . In project_status.php] , I have included another file project_status_app.php which contains a HTML form. project_status.php: <?php include 'inc_fn_header_and_menu.php'; function includeFile($file,$variable) { $var = $variable; include($file); } if (isset($_GET['id']) && $_GET['id']!="") { $pid = $_GET['id']; $_SESSION['pidForApproval'] = $_GET['id']; $query = 'SELECT * FROM `profile` WHERE pid ='.'\''.$pid.'\''; $result=mysqli_query($db,$queryToRetrievePP) or die("There are no records to display ... \n" . mysqli_error()); foreach ($result as $row) { $status = $row['status']; } } ...........some PHP and HTML code....... <div id="customerPurchaseApprovalForm"> <?php echo '<p>APPROVAL FOR CUSTOMER PURCHASE</p>'; $discountApprovalStatus = "Granted"; if ($discountApprovalStatus == "Granted") { includeFile("project_status_app.php",$highestannualvalue); } else { //......... } In project_status_app.php I am attempting to retrieve pidForApproval from the $_SESSION array. <?php // put your code here UPDATE `pp` SET `customer_purchase_remarks` = 'hahaha' WHERE `pp`.`id` = 207; if ($_SERVER['REQUEST_METHOD'] == 'POST') { include '../../inc/fastlogin.php'; $sql = "UPDATE pp SET customer_purchase_remarks ='{$_POST['remarkstxt']}' WHERE pp.pid='{$_SESSION['pidForApproval']}'"; $result = mysqli_query ( $fastdb, $sql ) ; if (mysqli_affected_rows($fastdb) != 1) { $_SESSION['err_cpa_rmks'] = "<p>Error while updating WHERE id='{$_SESSION['pidForApproval']}'</p>"; //echo "<p>Error while updating WHERE id='{$_POST['pidForApproval']}'</p>".mysqli_error($fastdb); } else { $_SESSION['suc_cpa_rmks'] = "<p>Records was updated successfully.</p>"; //echo "Records was updated successfully."; } header ("location: project_status.php?id="$_SESSION['pidForApproval']); exit(); } ?> When I load project_status.php, project_status_app.php is supposed to display the form. Once the user fills in the form the and the submit button has been pressed, the UPDATE statement is supposed to run and then it is supposed to navigate back to project_status.php?id=FA142. But the update is failing and the when the project_status.php is loaded back, the url looks like this http://localhost/fast/project_status.php?id= . The id is empty. It is supposed to be something like this http://localhost/fast/project_status.php?id=FA142. With the id being populated at the header ("location: project_status.php?id=".$_SESSION['pidForApproval']); I suspected that my $_SESSION['pidForApproval'] is not being populated in project_status.php but I echoed back $_SESSION['pidForApproval'] in that file itself and I can see it is being populated. Hence, I suspect that the $_SESSION['pidForApproval'] is not being passed to project_status_app.php. I have already attempted to include session_start(); clause in project_status_app.php but that gives an error, stating that the session has already started, in inc_fn_header_and_menu.php. Can someone help me as to why the $_SESSION['pidForApproval'] is not being passed on to the project_status_app.php file. Thank you.
  3. Okay,But the issue is that the inc_fn_header_and_menu.php file is a shared file, it has been already included in all other files. To remove session_start(). I will have to include session_start() in all those files.
  4. I had set this value into the super global $_SESSION in the first file, file_1.php: <?php //there is some code here $_SESSION['salesorder'] = 'are---io'; //remaining code, includes a form. ?> When the submit button is clicked, the form is submitted to file_2.php <?php //some code over here if (isset($_POST['sales']) && $_POST['sales'] != ""){ $sales = sanitize_input(trim($_POST['sales'])); $_SESSION['salesorder'] = $sales; $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'processSO_helper_sd.php'; header("Location: http://$host$uri/$extra?so=".$sales); exit(); } //Begin display include 'inc_fn_header_and_menu.php'; //some code over here ?> which will redirect to processSO_helper_sd.php <?php // Initialize session session_start(); $SD_ID = $_SESSION['salesorder']; $result = $db->query($sql); $row = $result->fetch_assoc(); $rowcount =$row['row_count'];*/ //print_r($_SESSION);//* $result = $tmonedb->query("SELECT COUNT(*) FROM document WHERE SD_ID = $SD_ID")->fetch_array(); $rowcount = $result[0]; //remaining code ?> My problem is that I cannot access the $_SESSION['salesorder'] in the last file processSO_helper_sd.php although I have set it twice previously. I could not add session_start(); in the file_2.php because that was already added in 'inc_fn_header_and_menu.php'; Can someone help me with this? Thank you. Please tell me if you need any additional information.
  5. Thank you Barand, I have tried out your suggestion and it has worked. However, I have one question, it is about these lines: } else { print_r($years_arr); return $years_arr; How is it that it manages to print $years_arr but it doesn't return the $years_arr. Also, can you point me to some resources(books, websites) that teach about Recursion in PHP, they are hard to come by and most books, at least the ones I obtained, delve on the subject very briefly. And, no, this is not an entry into a competition :)), it is a small portion of a bigger program.
  6. Dear all, Kindly help with this code I have written, it is not returning the array I created. It is a very small script but I have been looking for a very long time but I couldn't see why it went wrong. $duration = 2; $start='01-01-2019'; $month =date('n', strtotime($start)); $year =date('Y', strtotime($start)); $mon = 12-$month+1; $remainingMonth = $duration*12; $years_arr = array("$year"); $residue_arr = array("$remainingMonth"); $years_arr = process($remainingMonth,$year,$mon,$years_arr,$residue_arr); print_r($years_arr); //<output function process($remainingMonth,$year,$mon,$years_arr,$residue_arr){ $residue = $remainingMonth - $mon;//$D$18-D20 if($residue != 0){ $new_year = $year+1; array_push($years_arr, $new_year); array_push($residue_arr, $residue); if($residue > 12 ){ $mon = 12; } else { $mon = $residue; } echo "<br>"; process($residue,$new_year,$mon,$years_arr,$residue_arr); } else { print_r($years_arr); return $years_arr; } }//end of process(..) The objective is to add a year to the $years_arr array and then print it put, yet I notice that nothing get's printed out. Please assist, if you need more info from my side, please do ask. Thank you very much in advance.
×
×
  • 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.