TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 468
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 458
  • Total: 458

passing values

Started by Thalov, August 16, 2007, 01:52:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Thalov

So I have 3 files:

mybio.php
ebio.php
ubio.php

In mybio.php I 'attempt' to set $user_id = $context[user][id] to get the user's id #
mybio.php also includes ebio.php

ebio.php should then pass that $user_id value to the ubio.php when the form is submitted.

And finally ubio.php should use that user's id to update their mysql table entry

Where I'm having problems is passing the arguement from mybio.php to ubio.php - I tried setting $user_id as a global (and not as one) either way that ends up giving me a value of Array[id]

How do I get around this - since I know there's only one value in there. Do I need to do some kind of mysql_fetch_array to solve this?

Ianedres

Have you echoed the $user_id variable to determine whether it is getting the value?

Thalov

In mybio.php it will get the correct value.

In ebio.php it will return Array[id]

Ianedres

Are you including ebio.php in a function, rather than in the normal flow of the script?

Thalov

As it says above, ebio.php is included in to mybio.php

Ianedres

Quote from: Thalov on August 16, 2007, 02:29:32 PM
As it says above, ebio.php is included in to mybio.php
As it was asked, is the include statement declared in a user-defined function?

See link for details that may explain missing values.

Thalov

#6
mybio.php
<?
include('../USS_Ethos/SSI.php');
include('../USS_Ethos/BioTools/account.php');
$user_id = $context[user][id];
$npc = "0";
$table_bio = "bio";

$connection = @mysql_connect($db_host, $db_name, $db_pw) or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());

$sql_bio = "SELECT * FROM $table_bio WHERE user = $user_id";
$result_bio = @mysql_query($sql_bio, $connection) or die(mysql_error());
$bio = mysql_fetch_array($result_bio);

global $user_id;
global $npc;
include('../USS_Ethos/BioTools/vbio.php');
include('../USS_Ethos/BioTools/ebio.php');
?>


I don't believe that's a user-defined function... but hey I've been wrong in the past.

IchBin

Sorry, but the way you're doing things has me really confused. If you wouldn't mind posting what you have in the other files I can get a better idea of what you're trying to do.

Thalov

Sorry about the confusion, it all seems to make sense to me because I've been staring at it for so long... so the codes are posted below.

And yes - I know I can put the css in the ebio.php in to it's own .css file, just doing it like this for easier manipulation and placement for the time being.

ebio.php
<head><style type="text/css">
#main {width:800px;}
#edit {width:800px; height:83px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/edit.jpg);}
#name2 {width:300px; float:left; position:relative; left:200px; top:28px; font-size:large;}
#tags {width:800px; height:77px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/tags.jpg);}
#vitals2 {width:240px; height:250px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/vitals2.jpg);}
#vcontent2 {width:147px; height:120px; float:left; position:relative; left:50px; top:90px; font-size:.78em;}
#service2 {width:560px; height:250px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/service2.jpg);}
#scontent2 {width:470px; height:120px; float:left; position:relative; left:50px; top:90px; font-size:.78em; }
#skills2 {width:240px; height:250px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/skills2.jpg);}
#skcontent2 {width:200px; height:120px; float:left; position:relative; left:50px; top:90px; font-size:.78em;}
#medhistory2 {width:560px; height:250px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/medhistory2.jpg);}
#mcontent2 {width:470px; height:120px; float:left; position:relative; left:50px; top:92px; font-size:.78em;}
#backstory2 {width:800px; height:250px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/backstory2.jpg);}
#bcontent2 {width:470px; height:120px; float:left; position:relative; left:288px; top:92px; font-size:.78em;}
#family2 {width:800px; height:250px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/family2.jpg);}
#fcontent2 {width:470px; height:120px; float:left; position:relative; left:288px; top:94px; font-size:.78em;}
#description {width:800px; height:77px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/description.jpg);}
#arc2 {width:800px; height:250px; float:left; background-image:url(http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/arc.jpg);}
#acontent2 {width:470px; height:120px; float:left; position:relative; left:288px; top:94px; font-size:.78em;}
#submit {width:180px; height:70px; float:left; position:relative; left:-425px; top:15px; background-color:#000000}
</style></head>
<?
//Initialize and connect to the DB

// Display the Form
echo "
<form name=\"form1\" method=\"post\" action=\"../USS_Ethos/BioTools/ubio.php\">

<div id=\"main\">
<div id=\"edit\">
<div id=\"name2\"><b>Name: <input type=\"text\" name=\"name\" value=\"$bio[name]\"></b></div>
</div>
<div id=\"tags\"></div>
<div id=\"vitals2\">
<div id=\"vcontent2\"><b>Gender: </b><br>
<input type=\"text\" name=\"gender\" size=\"16\" value=\"$bio[sex]\"><br>
<b>Species: </b><br>
<input type=\"text\" name=\"species\" size=\"16\" value=\"$bio[species]\"><br>
<b>Age: </b><input type=\"number\" name=\"age\" maxlength=\"3\" size=\"3\" value=\"$bio[age]\"> <b>years</b><br>
<b>Height: </b></br>
<input type=\"number\" name=\"height1\" maxlength=\"1\" size=\"3\" value=\"$bio[h_ft]\"> <b>ft</b> <input type=\"number\" name=\"height2\" maxlength=\"2\" size=\"3\" value=\"$bio[h_in]\"> <b>in</b><br>
<b>Weight: </b><input type=\"number\" name=\"weight\" maxlength=\"3\" size=\"3\" value=\"$bio[weight]\"> <b>lbs</b></div>
</div>
<div id=\"service2\">
<div id=\"scontent2\"><b>Years: Ship - Position, Rank - Notes<b><br><textarea name=\"service\" cols=86 rows=7>$bio[service]</textarea></div>
</div>
<div id=\"skills2\">
<div id=\"skcontent2\"><b>List Skills and Weaknesses<b><br><textarea name=\"skills\" cols=22 rows=7>$bio[skills]</textarea></div>
</div>
<div id=\"medhistory2\">
<div id=\"mcontent2\"><textarea name=\"medhistory\" cols=86 rows=8>$bio[medhistory]</textarea></div>
</div>
<div id=\"backstory2\">
<div id=\"bcontent2\"><textarea name=\"background\" cols=86 rows=8>$bio[background]</textarea></div>
</div>
<div id=\"family2\">
<div id=\"fcontent2\"><textarea name=\"family\" cols=86 rows=8 >$bio[arc]User ID: $context[user][id]</textarea></div>
</div>
<div id=\"description\"></div>
<div id=\"arc2\">
<div id=\"acontent2\"><textarea name=\"arc\" cols=86 rows=8>$bio[arc]</textarea><input name=\"user\" type=\"hidden\" value=\"$user_id\"></div>
<div id=\"submit\"><input type=\"image\" src=\"http://www.nflcoolertalk.com/USS_Ethos/BioTools/img/submit.gif\" value=\"Submit\" alt=\"Submit\"></div>
</div>
</div>
</form>";
//echo '<pre>', print_r($context['user'], true), '</pre>';
?>


ubio.php
<?
include('../SSI.php');
include('../BioTools/account.php');
$table_bio = "bio";
$user_id = $_POST[user];

if ($npc == '0'){
$personality = '';
$permission = '$user_id, 1';
}
else{
$personality = '$_POST[personality]';
$permission = '$_POST[permission]';
}

$connection = @mysql_connect($db_host, $db_name, $db_pw) or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());

$sql = "UPDATE $table_bio SET name = '$_POST[name]', species = '$_POST[species]', sex = '$_POST[gender]', age = '$_POST[age]', h_ft = '$_POST[height1]', h_in = '$_POST[height2]', weight = '$_POST[weight]', service = '$_POST[service]', medhistory = '$_POST[medhistory]', background = '$_POST[background]', skills = '$_POST[skills]', family = '$_POST[family]', arc = '$_POST[arc]', npc = '$npc' WHERE user = '$user_id'";
$sql2 = "SELECT * FROM $table_bio";
$sql3 = "INSERT INTO $table_bio (id, user, name, species, sex, age, h_ft, h_in, weight, service, medhistory, background, reveal_background, skills, reveal_skills, family, reveal_family, arc, rank, job1, job2, permission, personality, npc) VALUES (NULL, '$_POST[user]', '$_POST[name]', '$_POST[species]', '$_POST[gender]', '$_POST[age]', '$_POST[height1]', '$_POST[height2]', '$_POST[weight]', '$_POST[service]', '$_POST[medhistory]', '$_POST[background]', $reveal, '$_POST[skills]', '$_POST[family]', '$_POST[arc]', NULL, NULL, NULL, '$permission', '$personality', '$npc')";

$result2 = @mysql_query($sql2, $connection) or die(mysql_error());

while($row = mysql_fetch_array($result2))
{
$current = $row['user'];

if ($current == "$user_id")
{
$checker = 1;
}
}

if ($checker == "0"){
// Create the Bio Entry
$result3 = @mysql_query($sql3, $connection) or die(mysql_error());}
else {
// Modify Exisiting one
$result = @mysql_query($sql, $connection) or die(mysql_error());}
/**/
header("Location:../index.php?page=98");
?>

IchBin

Sorry, going to look at this closer in just a moment. Any reason you have left out the single quotes for this?
$user_id = $context[user][id];

This website is proudly hosted on Crocweb Cloud Website Hosting.