Page 1 of 1

Help with a form output

Posted: Thu Nov 10, 2005 11:01 pm
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]

Posted: Fri Nov 11, 2005 12:06 am
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>

Posted: Fri Nov 11, 2005 7:05 am
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"){

Posted: Fri Nov 11, 2005 9:23 am
by InnerShadow
Thanks, it works now. And ill keep the quotes for tags in mind next time

Posted: Fri Nov 11, 2005 9:52 am
by InnerShadow
edit

Posted: Fri Nov 11, 2005 9:53 am
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.

Posted: Fri Nov 11, 2005 9:54 am
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.

Posted: Fri Nov 11, 2005 9:55 am
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

Posted: Fri Nov 11, 2005 9:57 am
by feyd
I'd suggest reading about switches

Posted: Fri Nov 11, 2005 9:58 am
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

Posted: Fri Nov 11, 2005 11:04 am
by feyd
I have psychiatric powers..

Posted: Fri Nov 11, 2005 11:15 am
by n00b Saibot
feyd wrote:I have psychiatric powers..
<whispered>how about giving me a lesson or two in private</whispered>

Posted: Fri Nov 11, 2005 11:16 am
by Charles256
<-- praying sabiot payed careful attention to the wording feyd used...

Posted: Fri Nov 11, 2005 11:48 am
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: