Jump to content

accepting input from HTML embedded in PHP


kwstephenchan

Recommended Posts

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
Link to comment
Share on other sites

Hi,

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

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

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

The same for the other input. It should help.

Regards,
    Dymon
Link to comment
Share on other sites

try updating the method by which you are echoing your input fields:
[code]
<?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\" />";
?>
[/code]

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)???
[code]
<?php
echo "<td><div align=\"center\"><font size=\"2\">&nbsp;<input type=\"$m_sq\" type=\"text\" id=\"m_sq\" size=\"3\" />";
?>
[/code]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.