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 Link to comment https://forums.phpfreaks.com/topic/24209-accepting-input-from-html-embedded-in-php/ 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 Link to comment https://forums.phpfreaks.com/topic/24209-accepting-input-from-html-embedded-in-php/#findComment-110046 Share on other sites More sharing options...
neoform Posted October 17, 2006 Share Posted October 17, 2006 nm Link to comment https://forums.phpfreaks.com/topic/24209-accepting-input-from-html-embedded-in-php/#findComment-110049 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?? Link to comment https://forums.phpfreaks.com/topic/24209-accepting-input-from-html-embedded-in-php/#findComment-110053 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] Link to comment https://forums.phpfreaks.com/topic/24209-accepting-input-from-html-embedded-in-php/#findComment-110056 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 Link to comment https://forums.phpfreaks.com/topic/24209-accepting-input-from-html-embedded-in-php/#findComment-110070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.