two word variable

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
bakon
Forum Newbie
Posts: 3
Joined: Tue Mar 09, 2010 5:21 am

two word variable

Post by bakon »

Hello, I hope someone can help me with this...
I have a dynamic drop down menu where items ( addresses ) are pulled from sql table.
However,I have a problem to post value when address has two words, like "New Avenue".
What I`m getting on next page is only "New", which is not good for me. I would need both words. Code is below..
THANKS !

<!-------------begin form------------>
<form method="post" action="scoe_v.php">
<input type="Hidden" name="send" value="true">
<TABLE>
<TD> <font size="2" face="Verdana">Address:</font> </td><td>

<?php

$query="select address from contacts order by address";

$result = mysql_query ($query);

echo "<select name=t1 value=''>Select one</option>";

while($nt=mysql_fetch_array($result)){
echo "<form method=post action=scoe_v.php>

<option value=$nt[address]>$nt[address]</option>";

}
echo "</select>";// Closing of list box

?>


</TABLE> <br>
<TABLE>
<TR> &nbsp
<TD> <input type="submit" value="Search" name="Submit"></TD>
</TR>
</TABLE>
</FORM>
<!-------------end form------------>

scoe_v.php -->

$t1=mysql_real_escape_string ($_POST['t1']);

echo "Address: $t1<br>";

With this code, only "New" is showing, even though i would need "New Avenue"..
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: two word variable

Post by papa »

Might work:

Code: Select all

 
<option value={$nt['address']}>{$nt['address']}</option>";
 
 
Your HTML is invalid. You have a <form> element inside a <select> tag.
michaeru
Forum Commoner
Posts: 28
Joined: Sun Mar 07, 2010 5:22 pm

Re: two word variable

Post by michaeru »

Maybe you meant something like this on the form?

Code: Select all

 
<form method="post" action="scoe_v.php">
 
  <input type="Hidden" name="send" value="true">
 
  <table>
 
    <td>
 
      <font size="2" face="Verdana">Address:</font>
 
    </td>
 
    <td>
       
      <select name="t1">
        
        <?php
 
          $query="select address from contacts order by address";
 
          $result = mysql_query ($query);
 
          while($nt=mysql_fetch_array($result, MYSQL_ASSOC)) {
 
        ?>
 
          <option value="<?php echo $nt[address]; ?>"><?php echo $nt[address]; ?></option>
 
        <?php
 
          }
 
        ?>
 
      </select>
 
    </td>
 
    <td>
      
      <input type="submit" value="Search" name="Submit">
 
    </td>
 
  </table>
 
</form>
 
Post Reply