Jump to content


Photo

accepting input from HTML embedded in PHP


  • Please log in to reply
5 replies to this topic

#1 kwstephenchan

kwstephenchan
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 17 October 2006 - 02:00 PM

Hi everyone! I got this problem where I embedded the <input> html in a PHP statement. I used the Post method for the form. I called the second program to retrieve the input from the first form, but I could not retrieve the input information from the first form. However, I can retrieve those input written without PHP. I got this undefined index for the variable "m_sq" and "m_mq" but the input "A" was successfully passed. Can anyone help, please??

My codes are:

<table width="800" border="0" align="center" cellspacing="0" cellpadding="0">
    <tr>
    <td height="100"><form action="addtocart.php" method="post" name="form1">
<?php if ($row_col['sq']>0) { 
                echo "<td><div align='center'><font size='2'>&nbsp;
                  <input name=";echo "m_sq"; echo "type='text' id='m_sq' size='3'>";}
      else { echo "<td><div align='center'><font size='2' color=red>&nbsp; N/A";}
              echo "</font></div></td>"; ?>
<?php if ($row_col['mq']>0) { 
                echo "<td><div align='center'><font size='2'>&nbsp;
                <input name='m_mq' type='text' id='m_mq' size='3'>";}
      else { echo "<td><div align='center'><font size='2' color=red>&nbsp; N/A";} ?>
              </font></div>
      </td>
        <input type="submit" name="Submit" value="Add to Cart">
        <input type="reset" name="Submit2" value="Reset">
        <input type="hidden" name="A" value="Add">
        <input type="hidden" name="MM_insert" value="form1">
    </td>
    </tr>
</table>

BTW. I found it tricky to embed HTML in PHP especially when dealing with those enclosing with single or double quote, can someone give me hints on doing this, thanks!

Stephen

#2 dymon

dymon
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 17 October 2006 - 02:06 PM

Hi,

The result you get is:
<td><div align='center'><font size='2'>&nbsp;
                  <input name=m_sqtype='text' id='m_sq' size='3'>

If you can see between name=m_sq and type='text' there is no  space, put one:

echo "<td><div align='center'><font size='2'>&nbsp;
                  <input name=";echo "m_sq"; echo " type='text' id='m_sq' size='3'>";

The same for the other input. It should help.

Regards,
    Dymon
Web is the future ... desktop will die ...

#3 neoform

neoform
  • Members
  • PipPipPip
  • Advanced Member
  • 241 posts
  • LocationMontreal

Posted 17 October 2006 - 02:08 PM

nm
Newsique.com Social News Network

#4 kwstephenchan

kwstephenchan
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 17 October 2006 - 02:22 PM

Thanks! I tried that but it still said undefined index, wonder why??

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 17 October 2006 - 02:24 PM

try updating the method by which you are echoing your input fields:
<?php
// change this:
echo "<td><div align='center'><font size='2'>&nbsp;<input name=";echo "m_sq"; echo "type='text' id='m_sq' size='3'>";

// to this:
echo "<td><div align=\"center\"><font size=\"2\">&nbsp;<input type=\"m_sq\" type=\"text\" id=\"m_sq\" size=\"3\" />";
?>

on that note, why are you jumping in and out of quotes to print values sometimes, but at other times you're not? just pick one practice, and stick with it. you'll be much happier in the long run! ;)

actually, it just hit me... is m_sq supposed to be a variable ($m_sq)???
<?php
echo "<td><div align=\"center\"><font size=\"2\">&nbsp;<input type=\"$m_sq\" type=\"text\" id=\"m_sq\" size=\"3\" />";
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#6 kwstephenchan

kwstephenchan
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 17 October 2006 - 02:56 PM

Thanks for all the help!  I finally figured out what happened! Because depending on the quantity, if the quantity is zero, I bar input for that field.  For this reason,Ishould first check (silly me!) isset ($_POST['m_sq'] before moving on. I added the isset checking and it works fine now!  Thanks,  you guys have been great help!

Stephen




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users