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




Catching Variables


I have a bunch of vars like tipo1, tipo2, tipo3, tipo4 sent via POST...
The number may vary depending on user choice. I would like to recover the vars in an array, but the way I'm trying is not working:

for($i=0;$i<$numberoftipos;$i++)
{
$tipo2=array($tipo[$i]);
echo $tipo2[$i]."<br>";}

It echoes nothing...Any hints?
Changing var names is not possible, I can't rename them like tipo[] because they come from multiple radio buttons, so they need differente names or only 1 will be able to be checked in a big list !!!




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Not Catching The Post Variables
For some reason my PHP script is not catching the post variables that should be being sent by this form. Code:

Catching Xml Response
i really dont know how to ask it right, but i have this code:
//-----------------//
$xml= '<xml ..
..
..
..
<enddoc>'

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://mydestination.com');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec ($ch);

// display the result
var_dump($response);
curl_close ($ch);
//---------------------//

this code is working well. upon running the code it will give an xml
reply, however on the page it looks somethng like this:

string(426) " xxxx.... .. Email already exist, 1 "

on the page if your going to right click and view source, you will see
a well structured xml:

string(426) "<?xml version="1.0" encoding="UTF-8"?>
<myxml>
..
..
..
</myxml>"

my issue is how to get the value of one of the element from this xml?
next, i want the response not to be displayed right away on the page
as raw string..i need to trap it and display that on a more fine
manner.

SimpleXML Catching 404
I'm building a script with the last.fm datafeeds. When a incorrect username is given to the script, the last fm site throws a 404, and results in this PHP error:

Warning: simplexml_load_file(http://ws.audioscrobbler.com/1.0/user/RichardJohn/tasteometer.xml?with=) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /home/richardm/public_html/lastfmcompatibility.php on line 12

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://ws.audioscrobbler.com/1.0/user/RichardJohn/tasteometer.xml?with=" in /home/richardm/public_html/lastfmcompatibility.php on line 12

There was a problem loading the data feed. Is there a way to catch this error and just present a friendly error?

Catching Errors?
I am having trouble wrapping my head around the general concept of catching errors. I have read the tutorials about exceptions on DevShed, as well as on Zend's website. It is still not clear to me. If I throw 5 exceptions, how come I need 5 catch phrases, and what does it mean when it travels up the stack?

Sorry I am just really confused with the catch phrases and how they work, although I am almost positive I completely understand the throwing of exception concept.

Catching Special Characters
I'm have trouble detecting and replacing special characters (specifically Czech-language characters ie &scaron; etc) in my php script. What I want the script to do is this:

take in a string (posted from a prior form) run through a switch statement that checks each character to see if they are a "special" character, and if so replace it with their html equivalent. So far I have most of them working (specifically AEIOUY with the "acute" accent, both upper case and lower case), but when it comes to the Czech-specific characters above it doesn't detect them.

I've tried every notation I can think of, including "x10D" and chr(268) (for the &ccaron; letter) and nothing seems to work. The string input is a copy/paste from a Word document that already has the special letters encoded (ie I can see them normally in the text box window in my form) into the text box and then posted to my script.

I've looked on the php.net manual and didn't find anything of help, and I did look at both the utf8_encode and utf8_decode pages. Though on the utf8_decode page it shows that the character "xc4xb0" is the character 0x130 and can be displayed as "&x#130;" but I don't understand the double "x" encoding ("xc4xb0").

Catching The 'Back' Button
I'm wondering if there's a way to catch when the user clicks the 'Back' button from a specific page.  When this happens, I need to run a system call that deletes everything in a session-specific directory.  The systems call would look something like this: system('rm -r /home/websites/genework/html/DATA/'.$Sess_ID.'/*');

So, the only thing left is the snag involving the catch of the 'Back' button.  Javascript has a way to catch this action (window.onbeforeunload), but the tap-dancing that would be required to get PHP to activate the system call is extremely ugly and I'm not even sure it'd work.

Shell_exec And Output Catching Problem
I have a problem with shell_exec. Following code works fine: PHP Code:

Catching NULL Values Returned To Mysql_fetch_array()
Does anyone know how I can catch a null value that is passed to a reference to mysql_fetch_array? For example, I have the following code (i use classes intensively, so forgive me if the code appears complicated):

print ( $this->_db->row[ "date" ] );

I get the following warning:

PHP Warning: Undefined index: date in c:inetpubincludephplibBulletinBoard.php on line 193

I KNOW that this is because the value in the date field is null. I want to be able to catch this and control the output if it's null. Does anyone know of a PHP specific function (or even a mySQL function) that will help me do this?

Improve String Catching Of Html Page
I scripted a prog that extract a string from an html page excluding
all the tags.
The problem is that it works quite slowly and I wanted to know if
somebody of us as an idea how to improve his performance.

CODE

$start="start_str"; //begin string
$end="end_str"; //end string
if($snoopy->fetch("http://www.informative.page.com";)) //get the html
code
{

$string=$snoopy->results; //assign to $string all the html string

- Hide quoted text -
$i=1;
$line = explode("
", $string); //trim the html in lines

while ($i<300)
{
//take only the middle
if ($i>230) {
//explode the line to control the content
$piece = explode(" ", $line[$i]);

$k=0;
while ($k<200) {

//if it content the string that i'm searching... :)
if ($piece[$k] == "interesting_part") {

$word=preg_split("/[s<>]+/", $line[$i]); //to eliminate html tags

$j=1;
$flag=0; //to say when print the word

//extract the string without html
while ($word[$j]) {

if ($word[$j] == $begin) $flag = 1;
if ($word[$j] == $stop) $flag = 0;
if ($flag) echo "$word[$j] ";
$j++;
}

}
$k++;
}
}
$i++;
}
}

Catching "File Name Too Long" Errors
Is there a way to redirect on "file name too long" errors?

I'm using mod_rewrite to handle all unknown urls with an error page.
That's not working for this error. Apparently the "file name too long"
error occurs before mod_rewrite is invoked.

Setting up an ErrorDocument is also ignored, even though it looks to the
user (and listed in access.log) as a 403 error, it's not a normal 403
error.

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. 

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?

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:


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