Help with a form output

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

Post Reply
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Help with a form output

Post by InnerShadow »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hey, i have an html form that is supposed to send information to the php script, and it seems like it does send the information, however, the php script always returns the same thing no matter what is sent.

here's the form that sends the information:

Code: Select all

<form action = tradetestArray.php>
<table border = 1>
<tr>
   <th>Goods</th>
   <th>Recipient</th>
<tr>
   <td>
      <select name = Goods>
	<option value = "A">coal</option>
	<option value = "B">iron</option>
      </select>
   </td>
   <td>
      <select name = Recipient>	
	<option value = "A">United States</option>
	<option value = "B">France</option>
      </select>
   </td>
<tr>
<tr>
   <td colspan = 2>
	<input type = "submit"
	 input value = "submit">
   </td>
</tr>

and here is the php program that recieves it

Code: Select all

<?php

$item = $_POST['Goods'];
$country = $_POST['Recipient'];

if ($item = "A"){
	if ($country = "A"){
		print "coal sent to the United States";
	} else if ($country = "B"){
		print "coal sent to France";
	} else {
		print "Error";
	}// end if
} else if ($item = "B"){
	if ($country = "A"){
		print "iron sent to the United States";
	} else if ($country = "B"){
		print "iron sent to France";
	} else {
		print "Error";
	}// end if
} else {
	print "ItemError";
}// end if

?>
im probably missing something that is real basic, but im just not seeing it
Any help would be appreciated.


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

you need the method attribute to your form tag

Code: Select all

<form action="yourpage.php" method="post">
on a side note, it's good practice to put at least some kind of quote around your html tag attributes

for example <select name="country"> instead of <select name = country>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post by sheila »

Your if statements are coded as assignments. Change all the single = to double ==

Code: Select all

if ($item = "A"){
    if ($country = "A"){
should be

Code: Select all

if ($item == "A"){
    if ($country == "A"){
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Post by InnerShadow »

Thanks, it works now. And ill keep the quotes for tags in mind next time
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Post by InnerShadow »

edit
Last edited by InnerShadow on Fri Nov 11, 2005 9:56 am, edited 1 time in total.
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Post by InnerShadow »

One another note, is there any limit to the number of If/else statements that you can have imbeded inside eachother?
it's getting the information, but it's not returning any values, and i was wondering if this was because of some limit on nested if/else statements.
Last edited by InnerShadow on Fri Nov 11, 2005 9:55 am, edited 3 times in total.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

nah. Only limit is whether or not you can follow your sick twisted logic. :-D Just kidding, I've gotten pretty deep before though.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

no ifs don't have a limit but humans have :P

and BTW close that PHP tag properly...

edit: feyd is too fast with it. does he make his computer do it for him automatically 8O
Last edited by n00b Saibot on Fri Nov 11, 2005 9:58 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd suggest reading about switches
InnerShadow
Forum Commoner
Posts: 37
Joined: Thu Nov 10, 2005 10:44 pm
Location: US

Post by InnerShadow »

yea, i noticed it right after i posted it, and was in the process of fixing it when you replied. sry about that
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I have psychiatric powers..
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

feyd wrote:I have psychiatric powers..
<whispered>how about giving me a lesson or two in private</whispered>
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

<-- praying sabiot payed careful attention to the wording feyd used...
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Charlie wrote:<-- praying saibot payed careful attention to the wording feyd used...
yeah! I know :lol: but maybe he'd teach me something useful just in case :wink:
Post Reply