passing variables back to same original page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

but

Post by revocause »

but behavioral science would say that some people like to see new people squirm, makes them feel bigger about themselves. :)
j/k
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

My code as pseudo code. You need to substitute your field names and such to make it work. What I coded was only an example of what it might look like, not how to do it in your specific case.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

ok i edited that code snipet you gave on forum page 1 of this topic


when i used the name of my html file in here

Code: Select all

<form name="formx" method="post" action="<?php echo basename(test_calculator.html); ?>">
it gave= (HTTP 403 Forbidden) The website declined to show this webpage.

what is 'basename'? is there somethingIm missing there
any suggestions, since i never made any special security or access passwords etc to it?
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

Im thinking i need

$path

before the actual .HTML file name huh?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Again, I was using pseudo-code. Basically you would declare the value that you want displayed in the input as blank. Once the value is calculated, you reassign the calculated value into the previously declared variable. That way you can always be confident that echoing the variable will echo the right value.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

No, leave the code the way it was there. __FILE__ is a reserved constant in PHP. You will also need to change the name of the file from whatever it is now.html to .php.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

ok i tried that, switched .html to .php page.

it reloads the page, but doesnt keep the variables, the select menu defaults back to 'please select' state lol

I think all I'm doing is slaughtering my former coding that worked in javascript. l o l
this sucks.

oh boy, anyway , check this out

Code: Select all

<?php 
$input_value = ''; 

if (!empty($_POST['value'])) 
{ 
    e = (a*b) + (a*c) + (a*d) + (a*f) + g;  // Calculate.
    e = number_format ($total, 2);
    $input_value = $calculation; // This would have been handled by the math 
} 
?>


------------------------
it doesnt look right but if this helps you know what im 'trying' to do
desription:
a = name of select menu 1
b = name of select menu 2
c = name of select menu 3
d = name of select menu 4
e = name of subtotal <input> text box
f= name of select menu 5
g = name of select menu 6
Last edited by revocause on Tue May 29, 2007 1:12 pm, edited 2 times in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

No, this is where you have to use some equality checking to see if the value entered is the same as a particular value in the list (or something along those line).

Can you show your new code?
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

the above was the php script

heres the example select menu , there are 6 of them
with different values, and names a through g ( except 'e' is a subtotal <input>)

Code: Select all

<select name="a"  STYLE="width: 110 px">
		<option selected="selected" value="">Please Select</option>
		<option value="100">100</option>
		<option value="500">500</option>
		<option value="1,000">1,000</option>
		<option value="2000">2,000</option>
		<option value="3000">3,000</option>
		<option value="4000">4,000</option>
		<option value="5000">5,000</option>
		<option value="10000">10,000</option>
</select>
This is the last select menu that will trigger the process .

Code: Select all

<select name="g" STYLE="width: 110 px" onChange="submit(this.formx)">
 <option selected="selected" value="">Please Select</option>
                <option value="0">1</option>
                <option value="60">2</option>
              	</select>
and here is the input subtotal text box

Code: Select all

<input type="number" readonly value="" name="anssubtotal" size=5 value="<?php echo $input_value; ?>" />
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

what looks odd and confusing to me, is that in the php script
im using the names of the select menus

example
e = (a*b) + (a*c) + (a*d) + (a*f) + g; // Calculate.

but will i have to make them into $variables first?
like $a = a
$b = b
$c = c
etc
and then use that math function?


Right now that code of the top php script (a couple posts ago) isnt finished, as you can tell its a scattered mess in the works
of javascript being converted to php functions.

but I want to know what im doin compared to what i was doin , thats why it looks to FUBAR
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

If you could help me clean this problem up, I would be very happy and not bother like this again. Usually i dont ask for help
on things unless i absolutely cant figure it out.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You would need to assign variable with values based on the $_POST array. You might also be better off moving all of the select items into arrays themselves, then loop them and while you are looping them, check equality versus your calculation.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

Everah,
I'd pay you to write what Im tryin to do .
because farting around with it , is a waste of time, but seeing it done the right way once, and then I'd know and never forget it.

its like one of them things you need to see it, to read the code and understand = "ahhh ha"

otherwise this is all like cerebral oatmeal :)

(Vader = "you will tell me what you've done..with that code"
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Check out the PHP section at W3Schools and look at PHP Forms and PHP $_POST. It has some sample code and should somewhat clarify the way posted variables work.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

Post by revocause »

I thought this forum was about getting help?

I feel like Im bringing the stick back..and somebody tosses it away again for me to run after it again .

its a line of code, if somebody had asked me , I would see their code was screwed, and write it out once, then erase it off the board
but at least let me see what it should look like, this cat and mouse scenario of tutoring is kinda strange.

I know how to code basic php , i just cant get this thing. so this trial and error cat and mouse is ass chafing :)
Last edited by revocause on Tue May 29, 2007 1:54 pm, edited 1 time in total.
Post Reply