Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Session ID not persisting throughout script


[SOLVED] Session ID not persisting throughout script

Reply
  #1 (permalink)  
Old 11-13-08, 07:07 PM
arcuivie arcuivie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Session ID not persisting throughout script

I'm trying to call upon a session ID but it doesn't seem to persist into one of the else clauses. If I set the session id via $username = $_SESSION["username"]; before that specific else clause, I can echo it at the end of the entire script, but if I put it inside that else clause I cannot echo it outside the script. Also, if I put it outside or in the else clause, I can't call upon it inside the else clause.

Here's the entire script:

PHP Code:

<?php

include("dbconnect.php"); 
session_start(); 
if (
$_SESSION['logged'] != 1) { 
    
header("Location: login.php"); 
    exit(); 
    }else{
         if (!isset(
$_POST['submit'])) {
?>

html form for POST variables

<?php
    
} else {
        
$username $_SESSION["username"];
        
$tablename "_wo";
        
$table $username.$tablename;
        
$apt form($_POST['apt']);
        
$reqdate form($_POST['reqdate']);
        
$desc form($_POST['description']);        
        
$sql 'INSERT INTO `'.$table.'` (apt,reqdate,desc) VALUES (`'.$apt.'`,`'.$reqdate.'`,`'.$desc.'`)';
            if ((
$apt == "") || ($reqdate == "") || ($desc == "")) { 
                exit(
"There was a field missing, please correct the form.");
            }
        
$q mysql_query("SELECT * FROM `'.$tablename'` WHERE apt = '$apt'") or die (mysql_error()); 
        
$r mysql_num_rows($q); 
            if (
$r 0) { 
            exit(
"A work order has already been submitted for this apartment.  If you would like to amend this work order, please go to the work order page and select edit next to the work order.");
        } else {
            
mysql_query($sql) or die (mysql_error());     
            
mysql_close($db_connect); 
            }
        }
    }
?>
Reply With Quote
  #2 (permalink)  
Old 11-13-08, 10:14 PM
arcuivie arcuivie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Hah, found the solution. I separated the form page and the mysql insert page, and changed the code to:

PHP Code:

<?php
include("dbconnect.php"); 
session_start(); 
if (
$_SESSION['logged'] != 1) { 
    
header("Location: login.php"); 
    exit(); 
    }else{
         if (!isset(
$_POST['submit'])) {
         
header("Location: index.php");
    } else {
        
$username $_SESSION['username'];
        
$tablename "_wo";
        
$table $username.$tablename;
        
$apt form($_POST['apt']);
        
$reqdate form($_POST['reqdate']);
        
$description form($_POST['description']);  
            if ((
$apt == "") || ($reqdate == "") || ($description == "")) { 
                exit(
"There was a field missing, please correct the form.");
                }
        
$q mysql_query("SELECT * FROM `$table` WHERE apt = '$apt'") or die (mysql_error()); 
        
$r mysql_num_rows($q); 
        if (
$r 0) { 
        exit(
"Duplicate work order.");
        } else {
            
mysql_query("INSERT INTO `$table` (apt,description,reqdate) VALUES ('$apt','$description','$reqdate')") or die (mysql_error());
            
header ("Location: index.php");  
            
mysql_close($db_connect); 
            }
        }
    }
?>

Last edited by arcuivie; 11-13-08 at 10:28 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Gallery script good/bad idea? joshg678 PHP 2 12-22-08 08:41 AM
Great Script with lots of applications, but.. script_guy Script Requests 2 07-12-08 06:36 PM
How to run a php script residing on remote server? douffle PHP 11 05-09-08 12:44 AM
Help me with this script !!! phpfreek Job Offers & Assistance 0 04-12-06 05:19 PM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM


All times are GMT -5. The time now is 08:24 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.