Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Building Variables From Variables


I am trying to build a variable, that will have a amount of that
variable, can someone describe/explain in detail the best method to do
this?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Building Queries With Session Variables
I'm quite new to PHP so apologies if this is a really simple problem.
I'm using a session variable to store a userID after login and trying
to build a query using this variable. I have session_start() at the top
of each page and have registered the variable like so ($username is an
e-mail address taken from some user input)...

$user=$username;
session_register("user");

By echoing it on each page I can see that the $user session variable is
correctly passed through several pages (where it doesn't get used), but
when I come to actually use it to build a query using the following
line of code...

$getmovlist="SELECT movTitle, movYear FROM movie WHERE movID=(SELECT
movID FROM fMovie WHERE uID='" .$user ."')";

.... the query which is constructed is...

SELECT movTitle, movYear FROM movie WHERE movID=(SELECT movID FROM
fMovie WHERE uID='cxi03u')

which returns nothing as the end of the email address (@cs.nott.ac.uk)
has been cut off. If I echo the variable before inserting it into the
query it outputs the variable correctly (cxi03u@cs.nott.ac.uk)
alongside the incorrect query, but then if I refresh the page the value
of the variable has changed to cxi03u.

Building An Array And Passing The Variables Through Pages
I have a form that inserts a variable and then shows the variable where needed. simple... i think. I have it working, but I can't seem to add elements to the array. Also anytime I go to another section I lose the information. from the variable. here is the basic bit of code used. Code:

Same Named Variables.. Or Addressing Variables In A Loop
I'm just starting to program in PHP.. fairly new to programming in general... and I've run across a (probably simple) programming problem I hope someone can help me with. I'm sending variable names through an HTTP get that are generated through a foreach loop. The names are along the lines of name1=, begin1=, end1=, name2=, begin2=, end2=.. etc. The number is the number of the current cycle through the loop. My problem is addressing the variables on the next page... namely how do I evaluate those variables in a loop? I want the value of name1.. but obviously

for (i=1; i<3; i++)
{
echo "$name$i";
};

is not working. Is there an easy way to do this?

Passing Variables & Dummy Variables
Hi! thanks for all the previous help - I've made some progress & have dropdowns and a checkbox; however I have 2 probs which I can't figure out: grateful for any further help. THANKS!

1. Not sure how to code so that user can query from just 1 or all of the dropdowns (at the moment unless they select the correct answers from each dropdown - no results!) = defeats the whole purpose of searching. By selecting from menu options user selects from 2 diff tables.

[the page allows user to search catalogue by selecting year of release, artist, music type - results from 2 tables need to be selected & sent to mysql.

I just don't know how to code it so that user must make an initial selection to get any results, and whichever menu options they choose "add them together" if you like to make a complete query.... sorry my coding just isnt deep enough!

A friend suggested using a dummy variable but as I'm a bit out of my depth; I need to get some help!

The coding I've done so far;

Passing Variables And Session Variables
I'm currently working on a shopping cart script that works just fine with register_globals turned on but when turned off i get all kind of errors. The following page displays a detail of the book with the "Add to cart" link at the bottom. PHP Code:

Passing My Variables With Forms Variables
how to carry variables onto the next page along with the forms variables. I need to carry my own over too, but when I press submit on the form page only the forms variables carry over, not my own ?? I have two drop down menues on my form that provide two values "start & end" which I require to go with my own variables.I have tried "a href=" link which carries my variables but not the forms variables.

<?php
echo"<form method=get action=somepage.php?one=$one&two=$two&three=$three&four=$four>";?>
also tried
<a href=somepage.php?one=$one&two=$two&three=$three&four=$four&start=$start&end=$end

Persistant Variables - Application Variables
In the books I have read about PHP I haven't been able to find any descriptions of how to set variables that persist in the servers memory, in the way that Application variables persist in Cold Fusion.

In CF, if I set an application variable then any of the application pages that are run will have access to those variables. And you can put complex arrays of data in the Application Variables and then access these variables at any time, without having to reload those variables for each page when it loads. I expect you can do this is PHP, but I can't find any info about how to do this.

Variables That Change Session Variables
I'm currently writing a mulit-page form app that uses a session to
retain data from each form element in order for the user to jump
between pages, then the final data is passed to a calculation script.

However, I've noticed that if I assign a session variable to another
variable, which then performs a mathematical calculation, the session
variable changes.

i.e. $_SESSION["inflation"] = 4;

$temp_inf = $_SESSION["inflation"];
if ($_SESSION["inflation"] =="RPI") {
$inflation = $rpi;}
else {$inflation = ($temp_inf/100.0);}

now it equals = 0.04

How can I take a value from a session and perform operations on it
without altering the original session value.

Form Variables To Session Variables
I am writing a small script that consists of two pages:  page one displays a bunch of values from a DB (ie. First Name, Last Name, Phone Number).  On this page you will find a form that follows this format:

<input type="text" name="edit_firstname" size="20" maxlength="35" value='Bob'>
<input type="text" name="edit_lastname" size="20" maxlength="35" value='Smith'>
<input type="text" name="edit_phone" size="20" maxlength="35" value='5552222'>

So when you see the page there will already be a 'default' value in each line (which is information extracted from a DB).  This works perfectly and has been tested thoroughly.

On the second page I have the following code:

$editfirstname = $_POST['edit_firstname'];
$editlastname = $_POST['edit_lastname'];
$editphone = $_POST['edit_phone'];

What I am trying to do is this:  the default value for edit_firstname from the form is 'Bob' by default, but the user can change this in the input field on the first page.  This value, whether changed or unchanged, should then be stored as edit_firstname and by calling up the function $_POST[''] on the second page I want to transfer the value to the variable $editfirstname. 

However, it seems that $_POST['edit_firstname'] and the other fields do not return a value at all, hence $editfirstname = '' or $editfirstname = 'NULL'.  I have never tried to do things this way before. 

Variables
I have a variable holding text which I want the text to have a $ in front of it to convert it to a variable.

Php Variables
I'm trying to assign a new value to a variable passed from an html form to a php3 script. I'm using an if statement to evaluate variable 3 to see if it is equal to a specific string, if it is I'm reassigning variable 2 to be variable2+variable 3.

if ($question3!="select days")
{
$question2=$question2+$question3;
}

This is the statement. It keeps giving me a parse error and I can't seem to find the right documentation to show me how to combine two string variables.

Variables
If i created an array that holds fields of a table, how could I call one of the fields ie $array[field] if i need the field part to be a variable?

What Does @ Do In Variables?
i've noticed that many scripts contain @ before a funciton is called as in the following:
$host = @gethostbyaddr($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]);

so what is the purpose of the @ ?

Variables In URL
I have tried the following to pass a variable queried from a database to another page through the URL (id is the database record):

$idnum = $row->id;
print "<a href="page.php?$idnum>";
print "Click Here";
print "</a>"

and then to print the results on the linked page:

print $idnum;

but it didn't work. What's the exact code to retrieve and print the variable $idnum?

Also, can I use $idnum as a variable in a database query string such as

$result = mysql_query( "select id from articles where id is like $idnum" );

JS Variables In Php
i've got a piece of javascript code which prints out the city + country of a visitor to a website. I want to print both, city & country to a file. JS doesn't have file I/O.

Would it be possible to somehow import the variables to php? here's the JS code:

<script language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesCountry,GeobytesCity">
</script>
<script language="Javascript">
document.write("<p>Welcome to visitors from "+sGeobytesCity+", "+sGeobytesCountry);
</script>

Variables Within Variables
The actual app I am building allows users to create an email which is then mailed out members from a db of email addresses. Although I am having a big problem reading a variable into the mail after the mail has been created. In a very simplified state all I am trying to do is this (the order of events has to be this way unfortunately):

$content = "This is an email and the variable $name needs to be viewed at this point";
$name = "buttie";
echo $content;

When $content is echoed the variable $name does not get read. What is the best way to let $content access the variable $name, using this order of events.

Variables By URL
Hi have a simple php script that gets the website URL from a form... puts it on a variable and calculates Link Popularity. How can I get this to work passing the site URL by the address instead of the form.

[php]
<?php
if(isset($_GET['getlp'])){
// Edit this to your website url:
$myWebSite = ($_POST['url']);
[/php]

I go to
http://localhost/novo2/material/linkpop.php
On the form I introduce my site and the address becomes
http://localhost/novo2/material/linkpop.php?getlp=1
How can I avoid introducing the address and make the script assume that the address it needs its the address where it's being host?

PHP Variables Put Into A PDF
I have been searching for at least 5 hours all over the web and can't find a single thing to help me with this problem... I have a form created in Adobe Designer 7.0 (editable form) and I want it to receive variables from PHP and display the filled in form to users so that they can print it off for their own records. The form HAS TO BE laid out in the format I created in Designer 7.0. Any tips, suggestions, refering stuff?

Variables Through URL
I am trying to pass a variable through a URL eg. index.php?page=Features. Sadly, I used to do this in the Global off environment of PHP Nuke, and now have to cope with Global on. I have tried PHP Code:

Get URL Variables
how to get a variable passed in the URL, like this: <a href="issue.php?ticket=2">2</a>

On the issue page how do I get the variable 'ticket'? There seems to be no HTTP_URL_VARS or something of that nature and nothing in the PHP manual that I could find.

Variables?
I simply want to print some text that has 2 variables in it. Here is the code i have now.
PHP Code:

Is There A Way To Do This With Variables?
I have for example $f1, $f2, $f3, $f4... $f22.

i want a

for ($i = 1; $i <= 22; $i++)
{
if ($f$i == 1) { } // The variable should turn into $f1, $f2, etc
}

Php URL And Variables
It's probably very easy, but I cannot find my mistake:

page1.php

<?php
echo "<a href=page2.php?vartrans=5342>Clic</a>";
?>

page2.php

<?php
echo "$vartrans";
?>

When I click on the link on page 1, page 2 appears on the screen but with
the following error message:

Notice: Undefined variable: vartrans in c:program
fileseasyphp1-7wwwpage2.php on line 2

What's my mistake?

I use php 4.3.3.

Variables
i have many pages (page1.php .. page100.php) and each of them include
some fixed subpages (top.php, bottom.php).
each subpage (top.php, bottom.php) uses a variable ("theme") defined
in its "parent" (one of the pageX.php).
this variable is also used (not only defined) in the parent page
itself. i would like to have the variable "theme" defined in a single
external file, instead of defyning it for every page. is it possible?

sorry for the probably stupid question, im new to php.

Variables
Let me explain what i want with an example.

I have 3 files :-
File-A
File-B
File-C

I am using a variable called $tdir in File-C.
Its default value is stored in File-B.

Now, there is a Form in File-A where i can input a certain value and when i click "Submit", the value will be stored as $tdir in File-B.
From then, this new value will be used in File-A.

Get Variables
I want to transfer a variable to the next page. Here is the code:
First Page:
$page="1";
<a href="fav.php?page=$page">I like it!</a>
Second Page, (retrieves the variable)
$page = $_GET['$page'];

Sum Of Two Variables.
Im creating a small stats counter (god knows why after all the trouble it ahs caused me!) for my site, and getting all of the relevant data from the server log files. Getting the data isnt a problem, and slicing it up is fine but..

Ive created a rule that is trying to emulate a google analytics feature (the feature will count a visitor twice if they return after a certain amount of minutes even if its the same ip), but the code doesnt work. There are loads of different ip's in the log so I just cant understand why the code is interpreting just one ip. Code:

Getting All Variables
anybody know a way of getting all variables? the php parser engine must remember what each variable is... i just want to be able to make a debug type function which retrieves all of them....

If Problem With Some Variables Containing The Same Value!?
Hi all,

I feel a bit dizzy. I have been sitting in front of this programm for 12 hours now or so and now I only wanted to add a little function which checks if the user is allowed to see edit and delete links.
pretty easy hmm?

ok here is the code:

Code:
function showsubmenu($userid, $dbName, $libid){
$lur="SELECT `ur_edit`,`ur_remove` FROM $dbName WHERE `user_id` = $userid";
$lurquery=mysql_query($lur);
$lurresult=mysql_fetch_array($lurquery);
$ur_edit=$lurresult[ur_edit];
$ur_remove=$lurresult[ur_remove];

// just for checking if the rights come correctly from the db
echo "uredit= $ur_edit<br>ur_remove=$ur_remove<br>";

// edit link
if($ur_edit == 1){
echo "<a href="edit.php?action=edit&libid=$libid class=head>edit</a> | ";
}

// delete link
if($ur_remove == 1){
echo "<a href="admin.php?action=delete&libid=$libid class=head>delete</a> | ";
}

// back link
echo "<a href="javascript:history.back();" class=head>back</a>";
}

The idea is pretty easy. I got one additional table where the system stores rights for every action.
The name for editing items is "ur_edit".
0 is not allowed
1 is allowed

so as Admin, the system returns 1 for $ur_edit and $ur_remove. the query is correct!

The problem:

Only links displayed are delete and back. if I remove the edit lines, delete also vanishes.

If I remove the delete lines, only the back link will be displayed.

it should be:

edit | delete | back

but if you use the code above you only get:

delete | back

The syntax really seems ok to me and $ur_edit and $ur_remove are both 1.

What am I doing wrong here??

Truncating Variables
I would like to truncate a variable to 0 decimals.. no rounding just choping the decimal places right off.

Dynamic Variables In Php?
Hi,
I have a mySQL table that contains two columns
column one is 'feature' and column two is 'feature_value' - some of the data is for example

'hair_color' - 'blue'
'hair_color' - 'blonde'
'hair_color' - 'black'
'hair_color' - 'gray'

'eye_color' - 'blue'
'eye_color' - 'hazel'
'eye_color' - 'brown'

Yeah I know... definitely NOT third normal form. OK here's where it gets even better

On one web page, I build select controls from this data. The name of the control would be the value of the feature column. So from the data above I would have a select control whose name would be name="hair_color" and another select name="eye_color"

NO problems so far.... ok.
Now after the user selects from the selects (get it, sorry).... i am processing the data.

Although I use javascript for some client side validation... I also want to validate in php. (ok, just because I want to ok)

NOW.. the web page form will post these two variables $hair_color' and '$eye_color' as described above. But I don't know ahead of time what these variables are because they're based on data from a table.......

I go the table described above and select distinct on the feature column - I will return two rows.... see below

while($row = mysql_fetch_row($result_set)) {
$feature =trim($row[0]);
}

the value of feature in the first row is 'hair_color' and in the second row 'eye_color'--


What I'd like to do.... is to take the values in the $feature variable and create a literal variable that I can test for that was posted from the form........

so for example in the first row where $feature = 'hair_color' - I want to create a $hair_color variable...... because this is a variable of the select control from the form. Then for the second row where $feature = 'eye_color' - I want to create an $eye_color variable because again... this is the variable of a select control on the form.

Variables W/ Space Gets Cut Off On GET
I'm not sure why my text spaces aren't getting changed to %20. When I click a link w/ variables in it, the next page only gets the first word contained in the variable.

Any idea why this is happening? I don't remember having to do anything when passing multiple worded values across pages.

Invisible Variables - How To
I have a tagged iframe and two variables ($loginuser and $password) in a script that I am trying to write. I want to include them as part of the URL href to a target program for rendering in the iframe without using javascript. The following works:

Code:
$src="http://www.host.tld/prog.php?
loginuser=$loginuser&password=$password";
echo "<iframe id='myIframe' href=$src>No Iframes</iframe>";

but is undesireable. The variables can be read in the browser with View/Source. Same thing if I use target="myIframe".

The only way I have been able to do this without javascript is to use the php script to write a temporary file (middle.php) that includes a redirection with the variables as in:

Code:
$src="http://www.host.tld/prog.php?
loginuser=$loginuser&password=$password";
header(Location: $src);
exit;

and then call it from the main program as:

Code:
echo "<iframe id='myIframe' href='middle.php'>No Iframes</iframe>";

and finally deleteing the temporary file.

This works ok and there is nothing in the browser to show the value of the variables nor is there anything in the frame doucment source. I don't like writing temporary files if I don't have to, however, and I think this approach won't work for a target program (http://www.host.tld/prog.php) that is expecting post variables. Anyone have an idea about a better way to do this, given the constraints stated?

Passing Variables
here is some of my code
why wont it work it works when i replace $hello with $smith


<input type="text" name="hello" value="smith">
<?php
$db = mysql_connect("", "", "");
mysql_select_db("",$db);

$result = mysql_query("SELECT first,last FROM employees where last='$hello'",$db);

Cannot See Variables Within Function
I am quite blocked now. I cannot echo the variables inside the function.

Passing Variables
here's some code that's at the top of my page, a form later in the page posts the variables back to the same document and then updates the database. How do I make the page so that when the form is submitted it posts the info to the same page and then passes the same variables that were just put into the database to a page named view.php? or another way that would work was if there was a preview button next to the submit button that passed the variables, but the form action is set to PHP_SELF, so how would I make a button that would pass the form variables to view.php and not to itself?


Here's the code PHP Code:
<?php

Result Using Two Variables
Probably a real simple solution but I can't for the life of me work it out.

I have:

$pollitem_1
$pollitem_2
$pollitem_3
$pollitem_4

if I do a for loop for the amount of items, is it posiible to have a variable for the number after the _ ?

e.g....

Passing Variables
I am new to this and learning slowly, but I was hoping someone could give me some quick advice on how to create a variable on one page and have it passed to another to be read as an ID for a mySQL database.

I want to pass the variable "varRevID" from one page and have it read as "reviews_id" on the other.

My database is pulling from just the first record and I would liek to designate from the pointing page which record to pull from.

Passing Variables
Could somebody please give me a hint on the following problem.
1. I need to pass variables from one php file to another.
2. I need some few different forms and want to pass every variable to another (same) page.

Session Variables
Can anyone please help, I am testing this code from a book that I am learning php from and it doesn't work.

The message comes up showing "you've been here 1 times" , but the counter does not increment as I refresh the page. this is the code:

Global Variables = Off
Regarding the new security settings in PHP 4.32 - if register globals = Off, does this also affect global variables that have been explicitly declared?

GET Variables Through Link
Maybe this is all just going right by me and I should probably understand this well by now, but it didn't work the first time, and I have yet to find the right answer.

I'm looking to have a list of names, like James, Bill, Sam...etc on a page. With these names there will be a work function say Accountant, Billing, Janitor, and there will be another variable like office, 1, 102, closet...etc.

Php Server Variables
I have to build a script that will track where users are coming from when they enter a site. The only thing that I can not seem to get to work is obtaining the referral URL. I tried to use this:

$strRefferal = $HTTP_REFERER;

but got the error message saying that $HTTP_REFERER was undefined. I don't know if that is even the best way to get what I need but it was the only option I found. I am pretty new to PHP so I am always open to any suggestions.

Variables And $PHP_SELF
Is there a way to change a variable without calling $PHP_SELF ? In another words if I have two links:

a href=$PHP_SELF?page=this
a href=$PHP_SELF?page=that

is it possible to change page back and forth without having to refresh the page? I'm not sure if this is possible (yet), but then again, anything is possible.

Variables Within Functions
I had a bit of script which passed a variable to itself using GET variables. I changed it so that the <FORM> tag of the page was inside a function. Since then, the $HTTP_SERVER_VARS['PHP_SELF'] variable returns nothing.

Is it commonly known that this variable doesn't work inside a function? And how can I get by this (apart from passing it into the function).

p.s. I realise you can use $_SERVER variables, but i have to use this older version of PHP cos my ISP wont upgrade it quite yet!

Variables In Include?
Is it possible, sort of like you have an include like this:

include ("$variable.php")

I know it doesn't work like that, cause I tried it

Anyone know if its possible to get that to work?

Can't Get Variables Under Windows!!
I used PHP alot under linux but that's my first time to programme PHP under windows. However, I'm experiencing the weird case here. My php scripts can't get any variables from HTML form. not even by http://blahblah.com/phpscript.php?var1=hello.

Combine Variables???
Alright, I have variables $service1, $service2, $service3, etc, up to $sub services (the number varies).

Here's what I have:
while ($sub > 0):
$aa = fopen("../subs/".$sn."-".$sub.".txt","w");
fwrite($aa, $service.$sub);
fclose($aa);
$sub = $sub - 1;
endwhile;

my problem is in the fwrite line-- I want to add $sub to the end of the $service variable, so, for example, when $sub = 3, it will process it as:

fwrite($aa, $service3);

Dynamic Variables
I am NEWBIE & trying to develop internal control system with PHP-MySql & have one problem.

I want to enter dynamic variable into MySql like :

"I have checked report of Mr. $userName from $previousDate to $currentDate…..”

Wherein - $username, $previousDate, $currentDate will be called from other table.

My codes :

PHP Code:

INSERT INTO `checkReport ` (`schID`, `schNo`, `noteNo`, `subschName`, `content`) VALUES (1, 1, 'a', '', ' I have checked report of Mr. ‘.$username.’ from ‘.$previousDate.’ to ‘.$currentDate.’ ….)

which is not working… Please guide me through.


Copyright © 2005-08 www.BigResource.com, All rights reserved