Jump to content


Photo

POST Form not working - $_POST receiving variable name as the value


  • Please log in to reply
5 replies to this topic

#1 jfourman

jfourman
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 August 2006 - 01:56 AM

This is my first attempt to use the FORM POST method. My problem is that the receiving $_POST variable is getting the value equal to the POST'ed variable name (not the actual value of the variable).

form method="POST" page code:

<form action="orderupdate.php" enctype='multipart/form-data' method="POST">
<input type="hidden" name="order_id" value=$ordid>
  <input type="hidden" name="email_addr" value=$email>
  <input type="hidden" name="order_status" value=$statPublic>
<p align="center"><input name="Update Order" type="submit" value="Update Order" align="middle"></p>
</form>

orderupdate.php code:

<?$order_id = $_POST['order_id'];?>
<?$email_addr = $_POST['email_addr'];?>
<?$order_status = $_POST['order_status'];?>
<p><?printf ($order_id);?></p>
<p><?printf ($email_addr);?></p>
<p><?printf ($order_status);?></p>

The printf statements display the values: "$ordid $email $statPublic" rather than the actual values of the fields. If I add a printf statement to the "POSTing" form after the inputs, the value shows correctly (e.g. email_addr = dave@phpfreaks.com. If I change the input tag from type='hidden' to type='text' and enter a value, the value POSTs and displays correctly on the updateorder.php page. So I know the POST is working. It seems that the type='hidden' is my problem?

I did get the transfer of the variable values to work with the GET method, but I don't want the values to be part of the URL. I prefer to get the POST method to work.

???Thank you for your help.

#2 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 18 August 2006 - 03:10 AM

Change the input tags to this:

<input type="hidden" name="order_id" value="<? echo($ordid); ?>">

I think that's the problem.

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 18 August 2006 - 01:13 PM

The problem is that on the value, you are not putting quotes

value="something";
value='something';
value='".$something."' />
Tell me the problem, I will try tell you the solution

#4 jfourman

jfourman
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 August 2006 - 03:06 PM

;D Yipee! I am soooo grateful for your help. Jeremysr: you're solution was on the mark! I tried all 3 of onlyican's options; but they still just displayed what ever was in the quotes rather than the value of the variable.

I had fooled around with this problem for 6 hours reading and trying options before posting my question here. With your help, it was solved in a minute.

In reading my Programming PHP book to understand why the ?echo was required I now see that the echo() command puts the string from the PHP generated page into the HTML. I have a lot more learning to do.

Thank you for teaching me something!

#5 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 18 August 2006 - 03:24 PM

I though u were echoing the form

echo "<input type=...

Anything shown to the users machine needs to be in an echo (or print or simular functions)
if its not in an echo, its not read out
Tell me the problem, I will try tell you the solution

#6 jfourman

jfourman
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 August 2006 - 04:04 PM

Now I understand, thanks onlyican. In fact, the example I was using that did not echo the variable was echoing the form. Got it!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users