kwstephenchan Posted October 17, 2006 Share Posted October 17, 2006 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'> <input name=";echo "m_sq"; echo "type='text' id='m_sq' size='3'>";} else { echo "<td><div align='center'><font size='2' color=red> N/A";} echo "</font></div></td>"; ?> <?php if ($row_col['mq']>0) { echo "<td><div align='center'><font size='2'> <input name='m_mq' type='text' id='m_mq' size='3'>";} else { echo "<td><div align='center'><font size='2' color=red> 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 Quote Link to comment Share on other sites More sharing options...
dymon Posted October 17, 2006 Share Posted October 17, 2006 Hi,The result you get is:[code]<td><div align='center'><font size='2'> <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'> <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 Quote Link to comment Share on other sites More sharing options...
neoform Posted October 17, 2006 Share Posted October 17, 2006 nm Quote Link to comment Share on other sites More sharing options...
kwstephenchan Posted October 17, 2006 Author Share Posted October 17, 2006 Thanks! I tried that but it still said undefined index, wonder why?? Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 17, 2006 Share Posted October 17, 2006 try updating the method by which you are echoing your input fields:[code]<?php// change this:echo "<td><div align='center'><font size='2'> <input name=";echo "m_sq"; echo "type='text' id='m_sq' size='3'>";// to this:echo "<td><div align=\"center\"><font size=\"2\"> <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]<?phpecho "<td><div align=\"center\"><font size=\"2\"> <input type=\"$m_sq\" type=\"text\" id=\"m_sq\" size=\"3\" />";?>[/code] Quote Link to comment Share on other sites More sharing options...
kwstephenchan Posted October 17, 2006 Author Share Posted October 17, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.