Jump to content

[SOLVED] Sessions Question??


twilitegxa

Recommended Posts

How do I save variables that are not posted from a form but are just being pulled from the database? I have the following page:

 

top part of the page:

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
    or die(mysql_error());
mysql_select_db("smrpg", $conn) or die(mysql_error());

//verify the topic exists
$verify_topic = "select identity from scouts where
    id = $_GET[id]";
$verify_topic_res = mysql_query($verify_topic, $conn)
    or die(mysql_error());

if (mysql_num_rows($verify_topic_res) < 1) {
    //this character does not exist
    $display_block = "<p><em>You have selected an invalid character.
    Please <a href=\"listcharacters.php\">try again</a></em></p>";
} else {
    //gather rest of profile
    $get_posts = "select *, date_format(create_time, '%b %e %Y at %r') as fmt_scout_create_time from scouts where id = $_GET[id]";
        
    $get_posts_res = mysql_query($get_posts, $conn) or die(mysql_error());
    
    //create the display string
    $display_block = "
    <table cellpadding=3 cellspacing=1 border=0 class=list_tables>";
    
    while ($posts_info = mysql_fetch_array($get_posts_res)) {
        $post_id = $posts_info['id'];
        $identity = ucwords($posts_info['identity']);
        $character_create_time = $posts_info['fmt_scout_create_time'];
        $username = $posts_info['username'];
        $name = ucwords(strtolower($posts_info['name']));
        $element_of_influence = $posts_info['element_of_influence'];
        $age = $posts_info['age'];
        $birth_month = $posts_info['birth_month'];
        $birth_date = $posts_info['birth_date'];
        $birth_year = $posts_info['birth_year'];
        $height_feet = $posts_info['height_feet'];
        $height_inches = $posts_info['height_inches'];
        $blood_type = strtoupper($posts_info['blood_type']);
        $hobbies = ucwords(strtolower($posts_info['hobbies']));
        $favorite_color = ucwords(strtolower($posts_info['favorite_color']));
        $favorite_gemstone = ucwords(strtolower($posts_info['favorite_gemstone']));
        $favorite_food = ucwords(strtolower($posts_info['favorite_food']));
        $least_favorite_food = ucwords(strtolower($posts_info['least_favorite_food']));
        $favorite_school_subject = ucwords(strtolower($posts_info['favorite_school_subject']));
        $least_favorite_school_subject = ucwords(strtolower($posts_info['least_favorite_school_subject']));
        $strengths = ucwords(strtolower($posts_info['strengths']));
        $weaknesses = ucwords(strtolower($posts_info['weaknesses']));
        $goal = ucfirst($posts_info['goal']);
        $mission = ucfirst($posts_info['mission']);
        $biography = nl2br($posts_info['biography']);
        $biography = str_replace("\n", "<p>", $biography );
        $getMonth = date('F', mktime(0, 0, 0, $birth_month));
        $character_attack_level = $posts_info['attack_level'];

 

And I want to save the sessions for $identity and $userName from the following script lower on the page:

 

<?php
if (isset($_SESSION['loggedIn']) == 1) {
?>
<p>Welcome, <?php echo $_SESSION['userName'] ?> (<a href="login.php?action=logoff" title="Log Out">Log Out</a>)</p>
<?php
} else {
?>
<p>Please <a href="login.php">log in</a></p>
<?php } ?>

 

I want to save those variables into sessions on this page:

 

<?php

session_start();

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
    or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

$accept_scout = mysql_query("UPDATE scouts SET username = '$_SESSION[userName]' AND available = '0' WHERE identity = '$_SESSION[identity]'");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

You have accepted the character.
</body>
</html>

 

So I can use them in the update statement. Can anyone help explain how I can do this?

Link to comment
https://forums.phpfreaks.com/topic/172519-solved-sessions-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.