PHP - $_session Passed By Reference, Not Being Updated
I think I've gotten as far as I can with my troubleshooting so hopefully someone can help me here.
I have a constructor for a controller class that receives the $_SESSION array from index.php by reference. An instance variable is then created when references this references so that any changes made to this instance variable update the real $_SESSION variable. This was working until it mysteriously stopped after not touching it for a few hours. The local $this->session variable is working because it completes some tasks using it. I've also hardcoded values into the session from the index.php file and when they are hard coded the session works as you would expect so it seems to just not be connecting this local variable to the $_SESSION array anymore for some reason. index.php snippet: Code: [Select] session_start(); $action = 'login'; $controller = new UserController($_POST,$_SESSION); call_user_func(array($controller,$action)); constructor and login action from UserController (constructor is actually from a base controller but that shouldn't matter). Also the activeSession() function that checks if a session is valid and kicks the user if its not (which is what happens when anything is tried after logging in): Code: [Select] function __construct($post,&$session){ $this->post = $post; $this->session = &$session; $this->view = 'views/login.php'; $this->title = ''; $this->error = ''; } function login(){ try{ $user = $this->validateString($this->post['username'],'Username'); $pass = $this->validateString($this->post['password'],'Password'); $dao = new UserData(); $this->session['userid'] = $dao->login($user, $pass); $this->session['username']=$user; $dao = new PostData(); $this->posts = $dao->getFeedPosts($this->session['userid']); $this->view = 'views/posts.php'; $this->title = 'Post Feed'; } catch(Exception $e){ $this->handleException($e); } } function activeSession(){ if(!empty($this->session['userid'])) return true; else return false; } Any help would be amazing. I really don't know how this stopped working. Thanks in advance. Similar TutorialsHello, I have a "working" upload script but i do get an error: Strict Standards: Only variables should be passed by reference in C:\Users\UHN\Desktop\xampp-win32-1.7.4-VC6\xampp\htdocs\upload.php on line 99 Line 99: $file_ext = strtolower(end(explode('.', $file_name))); thanks.. Hello guys, not sure why I keep getting this error, can anyone help me? Here is the code:
$ext=end(explode('.',$thum));
First let me explain my code. 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.
<?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']);
Missing some information. Hello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> Is there something wrong with this query? elseif($_POST["titlee"] && $_POST["contente"]) { $titlee = $_POST['titlee']; $contente = $_POST['contente']; $to = $_POST['edit']; mysql_query("UPDATE custom_pages SET title='$titlee' AND content='$contente' WHERE id='$to'"); echo '<div class="post"> <div class="postheader"><h1>Updated</h1></div> <div class="postcontent"> <p>Your custom page has been updated.</p> </div> <div class="postfooter"></div> </div> '; } What's the best way to display when a page was last edited/modified? this is the script for viewing the data in edit mode <tr> <td width="67" height="24"><select name="qualifi"> <option selected="selected">None</option> <?php $qry=mysql_query("select * from qualification"); while($obj=mysql_fetch_array($qry)) { ?> <option value="<?php echo $obj[0]; ?>"<?php if($obj[0]==$qualifi) echo("selected"); ?>><?php echo $obj[1]; ?></option> <?php } ?> </select> </td> <?php echo"<td width='301'><input name='board' type='text' size='50' value='$board'/></td>"; echo"<td width='60'><input name='start' type='text' size='10' value='$start'/></td>"; echo"<td width='60'><input name='end' type='text' size='10' value='$end'/></td>"; echo"<td width='60'><input name='percentage' type='text' size='10' value='$percentage'/></td> </tr>"; } ?> </table> and the update query is like //qualification if($_SESSION[empcode]!="") { if($_SESSION[qualifi]!="None") { mysql_query("update HRMEMPQUAL set EMPCODE='$_SESSION[empcode]',QUALCODE='$_SESSION[qualifi]',BOARD='$_SESSION[board]',FROMYEAR='$_SESSION[start]',TOYEAR='$_SESSION[end]',MARK_PERCENT='$_SESSION[percentage]' where EMPCODE='$_SESSION[empcode]'"); } } how can i save all the data correctly while any change is take place...their are 3 rows of data.only the last fled data is updated all the 3 rows Hi. I am trying to figure out the best approach to pull THE most recent record for display, and ONLY the most recent one. I am really not sure how to go about doing this. Ive just started into stored procedure programming and php, but havent found anything yet on this one. Thanks. i am a beginerr in php.. and here is my code..which shows error in the querry line.. erro goes like this Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\restafinal\process_edit_page.php on line 56 and code goes like this.. echo part works well...that query line is the error line..please tell me whats the problem... Code: [Select] <?php //$id=$_GET["id"]; $id= $_GET['id']; $menu_name= $_POST['menu_name']; $position= $_POST['position']; $visible= $_POST['visible']; $note= $_POST['note']; $content= $_POST['content']; //echo part works well.. echo "menu_name"; echo $menu_name; echo "<br/>"; echo "position"; echo $position; echo "<br/>"; echo "visible"; echo $visible; echo "<br/>"; echo "note"; echo $note; echo "<br/>"; echo "id"; echo $id; echo $content; [b]$result = mysql_query(UPDATE page SET note =$note, nevigation = $menu_name WHERE id = $id,$connection)[/b] // test to see if the update occurred if (mysql_affected_rows() == 1) { // Success! } else { $message = "The page could not be updated."; $message .= "<br />" . mysql_error(); } ?> I have a script to update certain rows that contain certain data in them. Here is the code: if ($_POST['newstype'] == "1") { $query = mysql_query("SELECT * from `news` WHERE type='1'"); if (mysql_num_rows($query) == 1) { mysql_query("UPDATE `news` SET type = '2' WHERE type = '1' ORDER BY `news`.`dtime` ASC LIMIT 1") or die(mysql_error()); } else { echo "did not edit main news"; } } elseif ($_POST['newstype'] == "2") { $query = mysql_query("SELECT * from `news` WHERE type='2'"); if (mysql_num_rows($query) == 3) { mysql_query("UPDATE `news` SET type = '3' WHERE type= '2' ORDER BY `news`.`dtime` ASC LIMIT 1") or die(mysql_error()); } else { echo "did not edit recent news"; } } elseif ($_POST['newstype'] == "3") { $query = mysql_query("SELECT * from `news` WHERE type='3'"); if (mysql_num_rows($query) == 3) { mysql_query("UPDATE `news` SET type = '4' WHERE type= '3' ORDER BY `news`.`dtime` ASC LIMIT 1") or die(mysql_error()); } else { echo "did not edit old news"; } } else { echo "didnt update anything!"; } Here is my database structure. Why is it not updating it and always saying Did not edit main/recent/old news. Hi all, i want delete old updated images with considering its index in array. <?php global $oldimg; $oldimg = array(); //action: edit news if (isset($_GET['id'])) { $NewsID = (int)$_GET['id']; if ($NewsID == 0) { $rdir = '<META HTTP-EQUIV="Refresh" CONTENT="1.4;URL=panel-news.php">'; die($rdir);} //get user from the database and put data into $_POST variables. //Include database connection details require_once('../config.php'); //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $rs = mysql_query("SELECT newsimg1, newsimg2, ". " newsimg3 FROM news WHERE id = $NewsID"); if (mysql_num_rows($rs) == 0) die('no such a newsID!'); $row = mysql_fetch_assoc($rs); $oldimg[0] = $row['newsimg1']; $oldimg[1] = $row['newsimg2']; $oldimg[2] = $row['newsimg3']; } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data"> <input type=file name="file[]" size=20 accept="image/jpg,image/jpeg,image/png"> <input type=file name="file[]" size=20 accept="image/jpg,image/jpeg,image/png"> <input type=file name="file[]" size=20 accept="image/jpg,image/jpeg,image/png"> <input type="hidden" name="MAX_FILE_SIZE" value="2097152" /> <input type="hidden" name="NewsID" value='<?php echo (isset($NewsID))?$NewsID:"0";?>'> <input type="submit" value="edit" id="save" name="save"/> </form> <?php if (isset($_POST['save']) && isset($_POST['NewsID'])){ $NewsID = (int)$_POST['NewsID']; //Include database connection details require_once('../config.php'); //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //max fle size value $max_file_size = 2097152; //Global newsimg global $newsimg;global $ctr; $ctr = 0; //timestamp to make files unique names $timestamp = time(); //destination folder path $destpath = "../Dir/Newsimg/"; //looping each file or image from the form while(list($key,$value) = @each($_FILES["file"]["name"])) { //check if any empty or errors if(!empty($value)){ if ($_FILES["file"]["error"][$key] > 0) { $edir ='<div id="fail" class="info_div">'; $edir .='<span class="ico_cancel"><strong>'; $edir .="err : ". $_FILES["file"]["error"][$key] .'</strong></span></div>'; echo($edir); } else { //add the timestamp to filename $file_name = $timestamp.$_FILES['file']['name']; //temp name from upload form, key of each is set $source = $_FILES["file"]["tmp_name"][$key] ; //getting the file type $file_type = $_FILES["file"]["type"][$key]; //placing each file name into a variable $filename1 = $_FILES["file"]["name"][$key]; //lowering the file names $filename = strtolower($filename1); //adding timestamp to front of file name $filename = "$timestamp$filename"; ++$timestamp; if ($file_type != "image/jpeg" && $file_type != "image/png" && $file_type != "image/jpg") { die(" <div id='fail' class='info_div'> <span class='ico_cancel'><strong> Invalid Format!</strong></span><br /> <a href=\"javascript: history.go(-1)\">Retry</a> </div>"); } //moving the file to be saved from the temp location to the destination path move_uploaded_file($source, $destpath . $filename); //the actual final location with timestamped name $final_file_location = "$destpath$filename"; if (file_exists($final_file_location)) { if (isset($oldimg[$ctr])) { chdir('../Dir/Newsimg/'); echo $oldimg[$ctr]; unlink($oldimg[$ctr]);} $newsimg[$ctr] = $filename; $ctr++; ?>TNX. Hi guys, I need your help. I am checking on a database as I want to see if the records have been updated or not. Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $test = clean($_GET['test']); $public = clean($_GET['public']); if (isset($_GET['user']) && (isset($_GET['pass']))) { if($username == '' || $password == '') { $errmsg_arr[] = 'username or password are missing'; $errflag = true; } } elseif (isset($_GET['user']) || (isset($_GET['test'])) || (isset($_GET['public']))) { if($username == '' || $test == '' || $public == '') { $errmsg_arr[] = 'user or others are missing'; $errflag = true; } } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if ($username && $password) { if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, test, links, Public FROM user_channel_list WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<p id='test'>"; echo $row['test'] . "</p>"; echo '<p id="images"> <a href="images.php?test=test&id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?test=test&id='.$row['id'].'">Delete</a> </td> | <span id="test">'.$row['Public'].'</td>'; } } else { echo "user not found"; } } elseif($username && $test && $public) { $qry="SELECT * FROM members WHERE username='$username'"; $result1=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result1) > 0) { $qrytable1="SELECT Public FROM user_channel_list WHERE username='$username' && test='$test'"; $result2=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result2) > 0) { $row = mysql_fetch_row($result2); mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'"); echo "update!"; } else { echo "already updated!"; } } else { echo "user not found"; } } } ?> When I run debug the code on my php, if i input the data in a url bar while the records are the same as the data that I enter in the url, i should get the print out on my php "already updated", but I keep getting "update!". Do you know how i can check on mysql database to see if the records have been updated or not?? I'm creating a game where 2 people, on separate computers can battle each other. I'm doing it turn-based, like Final Fantasy but I came across a problem, how do I check if the other person has ended their turn? I was thinking that I would have an area in my database that would be true/false if it was their turn. So if the first person ends their turn, their 'turn' becomes false in the database, but how, on the other users computer, do I constantly check if the 'turn' has become false so that they may now play without having to keep updating the browser. Or is their a better way to do something like this? I have been using an inventory application built on PHP/MySQL. Since this morning I could submit the data and they were perfectly reflected on the MySQL Table. However, for a few hours I cannot save the submitted data to the table and it doesn't show any error message. Please note no change have been made since it was successfully running. The developer of this application is not available right now.
PLEASR HELP I AM A NOVICE IN PHP/MYSQL.
I am creating a stream page that updates automatically without the page reloading by reloading a div on the page using a timer. However, I only want it to run the update and fade in/fade out when there is a new status in the table. I tried doing it through PHP getting the number of rows in the table on the page itself and then checking the number of rows on an action page, however, the number of rows didnt update when the div was reloaded. I then tried doing it using jquery/javscript but had the same problem. How can I acheive this? Thanks in advance I'm trying to get a simple javascript popup script going anytime the database is updated in real-time. I'm not sure as to what to do next, because I'm still a newbie with jQuery and ajax, but the following code is what I have right now:
PHP MySQL query page:
<?php $con = mysqli_connect('localhost','root','root','mydb'); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } mysqli_select_db($con,"mydb"); $sql="SELECT * FROM incoming_calls"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { $callArray[] = array('phonenumber' => $row['phone_number'], 'id' => $row['phone_login_id']); } if (!empty($callArray)) { //echo json_encode($callArray); for ($i = 0; $i < count($callArray); ++$i) { print $callArray[$i]['id'] . ": " . $callArray[$i]['phonenumber'] . "<br>"; } } mysqli_close($con); ?>MySQL "incoming_calls" db table (I have a node.js script, that draws SMDR data from a phone system and posts it to this table): id phone_number phone_login_id date_created 3 000-000-0000 1225 12/15/2014 14:53 6 000-000-0000 1222 12/15/2014 14:53 9 000-000-0000 1202 12/15/2014 14:53 12 000-000-0000 1201 12/15/2014 14:55 18 000-000-0000 1232 12/15/2014 14:55 21 000-000-0000 1222 12/15/2014 14:57 24 000-000-0000 1222 12/15/2014 14:57 27 000-000-0000 1201 12/15/2014 14:58 30 000-000-0000 1207 12/15/2014 14:58 33 000-000-0000 1212 12/15/2014 14:59HTML ajax call page: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Phone calls</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <script language="javascript" type="text/javascript"> function getCall(){ $.get("phonecall.php", function(data){ $("#call").html(data); }); } setInterval(getCall,5000); </script> <div id="call"></div> </body> </html>Any help with this is greatly appreciated! Thanks ahead of time! Edited by Juan1989, 16 December 2014 - 11:07 AM. I am trying to set the hidden input in the javascript but it doesn't set it in the php. This is the form with the hidden input. It corresponds to a field in the database table with the name of draggables. <form method="post" accept-charset="utf-8" id="myForm2" action="/mealplans/add"> <input type="hidden" name="draggables" id="drag12"/> <button id="myId" type="submit">Submit Form</button> </form> This is where I change the value in the javascript: if(data == "draggable3"){ alert("data " + data); var x = document.getElementById("drag12").value; x = "draggable3"; alert(x); } //end if
I've also tried getElementsByName but that didn't work either. var y = document.getElementsByName("draggables").value; //only changes it on the client This is actually a cakephp site but this problem is with the PHP so I am publishing it here. Hello! I want to be able to make a code that tells me how many saturdays have passed till today. I've tried a couple of things but nothing. Any help?! Thanks! In my main script I set $errorArray with values when required survey questions go unanswered. The ne code that checks for missing required values is working perfectly, and right before I pass $errorArray to a function which rebuilds the survey questions - this time with the error messages - I do a var_dump($errorArray) and that array has errors in it as expected. But while my function that re-builds the survey questions gets called and does indeed re-build the survey questions, the $errorArray isn't getting pased for some strange reason? (I'm not sure if i have ever passed an array to a function before.) In my function I have... function generateSurveyItem($dbc, $questionNo, $questionID, $surveyResponseArray=NULL, $errorArray=NULL){ }
When I var_dump($errorArray) at the top of the function, and submit a blank form, I end up with a blank page and a file path to my PHP script ending with... /public_html/utilities/function.php:3010:null
Questions: 1.) What is happening?
2.) I thought =NULL in the parameter list just meant that the argument is "optional"?
3.) I am able to successfully pass $surveyResponseArray to this function, so what is up with $errorArray?
P.S. When I run things, and submit an empty form - thus no "required" fields get completed - the survey gets re-displays, and any values chosen are "sticky", but my error messages should also be displayed to let the user know what is mising, and that is the part that isn't working? This has to be something silly stupid to fix... Edited February 16 by SaranacLake Hi I use Dreamweaver to do a lot of my work on a php/mysql database. I have two tables - applications and contacts and they are linked by the id appid. When I view a page with all of the application and contact details the url contains the appid as a number at the end (eg .../Summary.php?appid=639) When I want to edit one of the contacts I go to the edit page but this is identified by a contact id so that url looks like: ../EditContact.php?contactid=32 When I update the contact's details I would like to return to the summary page but can't as the url gets muddled between the two different ids so I end up at a page with no info on it. How can I get round this? I'm sorry my explanation isn't very clear but any help is much appreciated. |