Page 2 of 3

Posted: Wed Jan 21, 2004 5:52 pm
by Straterra
Yeah, that makes sence. But from what I think ( I could be wrong ), He got a PHP book that has one of those CD's with PHP on it, and stuff. Ya know what I mean?

Posted: Wed Jan 21, 2004 6:01 pm
by birkel
I got my version of PHP from PHP Triad, and haven't gotten around to updating it yet, but I will do that tonight. One last thing, I am now trying to pass sel_id, so I created a new_sel_id and tried to assign the "old" sel_id to it, but still nothing.

Code: Select all

<?php
if ( isset($HTTP_POST_VARS['op2']) == false ) { 

echo "The value you have passed is: ".$HTTP_POST_VARS['sel_id']; 
echo "The value of op: ".$HTTP_POST_VARS['op'];	

	$display_block = "
	<form method="post" action="$_SERVER[PHP_SELF]">
	<input type="hidden" name="op2" value="add">
	<input type="hidden" name="new_sel_id">
	<p><input type="submit" name="submit" value="Save"></p>
   </FORM>";
   
   $HTTP_POST_VARS['new_sel_id'] = $HTTP_POST_VARS['sel_id'];
 //  $sel_id = 
} else {
echo "The value of op: ".$HTTP_POST_VARS['op'];	
echo "The value you have passed is: ".$HTTP_POST_VARS['sel_id']; 
echo "The value of the new op2: ".$HTTP_POST_VARS['op2'];	
echo "The value of the new_sel_id: ".$HTTP_POST_VARS['new_sel_id'];	
}
?>
Should, and how would I assign the value potion in the form statement of new_sel_id to sel_id which should be MY Value???

Code: Select all

&lt;input type="hidden" name="new_sel_id"&gt;
Thanks for all of your help, things are much clearer now.

Posted: Wed Jan 21, 2004 6:12 pm
by Straterra
Replace this

Code: Select all

$HTTP_POST_VARS['new_sel_id'] = $HTTP_POST_VARS['sel_id'];
with this

Code: Select all

$new_sel_id = $HTTP_POST_VARS['sels_id'];
and use the $new_sel_id instead of $HTTP_POST_VARS['new_sels_id']

Posted: Wed Jan 21, 2004 6:23 pm
by birkel
That does not work either

Code: Select all

<?php
if ( isset($HTTP_POST_VARS['op2']) == false ) { 

echo "The value you have passed is: ".$HTTP_POST_VARS['sel_id']; 
echo "The value of op: ".$HTTP_POST_VARS['op'];	

	$display_block = "
	<form method="post" action="$_SERVER[PHP_SELF]">
	<input type="hidden" name="op2" value="add">
	<input type="hidden" name="new_sel_id">
	<p><input type="submit" name="submit" value="Save"></p>
   </FORM>";
   $new_sel_id = $HTTP_POST_VARS['sel_id']; 
	echo "new_sel_id: ".$new_sel_id;
   //$HTTP_POST_VARS['new_sel_id'] = $HTTP_POST_VARS['sel_id'];
 
} else {
echo "new_sel_id: ".$new_sel_id;

echo "The value you have passed is:\n\n ".$HTTP_POST_VARS['sel_id']; 
echo "The value of the new_sel_id: \n\n".$HTTP_POST_VARS['new_sel_id'];	
}
?>
One more dumb question, why don't the newlines print out in my browser?

I get: new_sel_id: The value you have passed is: The value of the new_sel_id:

Posted: Wed Jan 21, 2004 6:31 pm
by Straterra
You didn't replace everything I told you to. This

Code: Select all

echo "The value of the new_sel_id: \n\n".$HTTP_POST_VARS['new_sel_id'];
should be this

Code: Select all

echo "The value of the new_sel_id: \n\n".$new_sel_id;

Posted: Wed Jan 21, 2004 6:33 pm
by microthick
Hi birkel,

Try this:

I'm assigning the value of the original sel_id to the new_sel_id that you've just created in the form.

Code: Select all

<?php
if ( isset($HTTP_POST_VARS['op2']) == false ) { 

echo "The value you have passed is: ".$HTTP_POST_VARS['sel_id']; 
echo "The value of op: ".$HTTP_POST_VARS['op'];    

   $display_block = " 
   <form method="post" action="$_SERVER[PHP_SELF]"> 
   <input type="hidden" name="op2" value="add"> 
   <input type="hidden" name="new_sel_id" value=".$HTTP_POST_VARS["sel_id"]."> 
   <p><input type="submit" name="submit" value="Save"></p> 
   </FORM>"; 
   $new_sel_id = $HTTP_POST_VARS['sel_id']; 
   echo "new_sel_id: ".$new_sel_id; 
   //$HTTP_POST_VARS['new_sel_id'] = $HTTP_POST_VARS['sel_id']; 

} else { 
echo "new_sel_id: ".$new_sel_id; 

echo "The value you have passed is:\n\n ".$HTTP_POST_VARS['sel_id']; 
echo "The value of the new_sel_id: \n\n".$HTTP_POST_VARS['new_sel_id'];    
} 
?>
The new lines aren't working because HTML doesn't listen to \n for new lines. If you were to view your source code that was generated, you'll see the new lines. But if you want the new lines to appear on the screen (in HTML) you need to use <br> instead.

Posted: Wed Jan 21, 2004 6:35 pm
by Straterra
Also, you are declaring the variable in the wrong place. Put

Code: Select all

$new_sel_id = $HTTP_POST_VARS['sel_id'];
also after

Code: Select all

} else {
Just make sure its before

Code: Select all

echo "new_sel_id: ".$new_sel_id;
The reason for this is because you are only defining the variable if the post thing doesn't exist. When the page reloads, it skips right down to the else statements since the post thing does exist. It doesn't even execute the code before the else and after the initial if. Because of this, you must declare the variable AFTER the if.

Posted: Wed Jan 21, 2004 6:41 pm
by birkel
Gotcha... Thank you...

One last thing I promise...

After I hit save
$new_sel_id = MY and
$HTTP_POST_VARS['new_sel_id'] = MY

They should both be "My Value"

for some reason the "Value" is getting lopped off.
Any ideas why?

Posted: Wed Jan 21, 2004 6:45 pm
by Straterra
The whole reason to be putting stuff into a variable is because you can't just insert stuff into $HTTP_POST_VARS['whateverisinherebutitdoesntreallymatter'] . You have to put the data from the other post into a variable, then you can do whatever you want to the data in the variable. Think as $HTTP_POST_VARS as a 1 way road. You can only get data from it, not add data to it.

Posted: Wed Jan 21, 2004 6:50 pm
by birkel
I gothca, but it is originally set to "My Value"

The value you have passed is: MY Value
The value of op: view
new_sel_id: MY Value

Then I hit save and get

The value you have passed is: MY
new_sel_id: MY

kinda weird..

Posted: Wed Jan 21, 2004 6:53 pm
by Straterra
That's weird..I would wait for Micro or some of the more experienced PHP'ers to come flying by. I'm not that knowledgable about the older versions of PHP...Sorry. :(

Posted: Wed Jan 21, 2004 7:00 pm
by birkel
I tried it on my website server that has version 4.3.2 and "My Value" is still truncated???

Posted: Wed Jan 21, 2004 7:04 pm
by Straterra
Sorry bud, I can't help you.....

Posted: Wed Jan 21, 2004 7:05 pm
by microthick
Hi birkel,

The value is probably truncated because it is not wrapped with quotes.

From my most recent post, this is what I expect your code to look similar to:

Code: Select all

$display_block = " 
   <form method="post" action="$_SERVER&#1111;PHP_SELF]"> 
   <input type="hidden" name="op2" value="add"> 
   <input type="hidden" name="new_sel_id" value=".$HTTP_POST_VARS&#1111;"sel_id"]."> 
   <p><input type="submit" name="submit" value="Save"></p> 
   </FORM>";
See the line where you are defining the value for new_sel_id? I gave you incorrect code.

It should look like this:

<input type=\"hidden\" name=\"new_sel_id\" value=\"".$HTTP_POST_VARS["sel_id"]."\">

Without the quotes around the value, the HTML that it would generate would look like

<input type="hidden" name="new_sel_id" value=MY Value>

And only MY would be considered the value.

Posted: Wed Jan 21, 2004 7:08 pm
by Straterra
microthick wrote:Hi birkel,

The value is probably truncated because it is not wrapped with quotes.

From my most recent post, this is what I expect your code to look similar to:

Code: Select all

$display_block = " 
   &lt;form method="post" action="$_SERVER&#1111;PHP_SELF]"&gt; 
   &lt;input type="hidden" name="op2" value="add"&gt; 
   &lt;input type="hidden" name="new_sel_id" value=".$HTTP_POST_VARS&#1111;"sel_id"]."&gt; 
   &lt;p&gt;&lt;input type="submit" name="submit" value="Save"&gt;&lt;/p&gt; 
   &lt;/FORM&gt;";
See the line where you are defining the value for new_sel_id? Does your code list it like this:

<input type="hidden" name="new_sel_id" value=".$HTTP_POST_VARS["sel_id"].">

or like this:

<input type="hidden" name="new_sel_id" value=$HTTP_POST_VARS["sel_id"]>

A comment concerning line two of the code you posted. Should the $_SERVER[PHP_SELF] not be in the quotations? I thought you have to concatinate the variable...