Variable problem
Moderator: General Moderators
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.
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???
Thanks for all of your help, things are much clearer now.
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'];
}
?>Code: Select all
<input type="hidden" name="new_sel_id">-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
Replace this
with this
and use the $new_sel_id instead of $HTTP_POST_VARS['new_sels_id']
Code: Select all
$HTTP_POST_VARS['new_sel_id'] = $HTTP_POST_VARS['sel_id'];Code: Select all
$new_sel_id = $HTTP_POST_VARS['sels_id'];That does not work either
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:
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'];
}
?>I get: new_sel_id: The value you have passed is: The value of the new_sel_id:
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
You didn't replace everything I told you to. This
should be this
Code: Select all
echo "The value of the new_sel_id: \n\n".$HTTP_POST_VARS['new_sel_id'];Code: Select all
echo "The value of the new_sel_id: \n\n".$new_sel_id;-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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.
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.
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'];
}
?>-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
Also, you are declaring the variable in the wrong place. Put
also after
Just make sure its before
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.
Code: Select all
$new_sel_id = $HTTP_POST_VARS['sel_id'];Code: Select all
} else {Code: Select all
echo "new_sel_id: ".$new_sel_id;-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
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.
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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:
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.
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ї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>";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.
Last edited by microthick on Wed Jan 21, 2004 7:08 pm, edited 1 time in total.
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
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:
See the line where you are defining the value for new_sel_id? Does your code list it like this:Code: Select all
$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>";
<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...