Pain Posted November 9, 2011 Share Posted November 9, 2011 I have a form inside a php code. And inside this form i want to put some php code again. <?php ... echo '<form action="main.php?id=jams" method="POST"> Choose rating <input type="hidden" name="jamrate" /> <select name="jamrate"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> <input type="submit" name="submit" value="<?php echo $view_id; ?>"> </form><br /><br />'; ... ?> <?php echo $view_id; ?> How can i do that? Quote Link to comment https://forums.phpfreaks.com/topic/250774-php-in-html/ Share on other sites More sharing options...
AyKay47 Posted November 9, 2011 Share Posted November 9, 2011 you have only part of your form inside of the echo statement, but not the closing tags? this is the way that I would do it.. <form action="main.php?id=jams" method="POST"> Choose rating <input type="hidden" name="jamrate" /> <select name="jamrate"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> <input type="submit" name="submit" value="<?php echo $view_id; ?>"> </form><br /><br />'; Quote Link to comment https://forums.phpfreaks.com/topic/250774-php-in-html/#findComment-1286610 Share on other sites More sharing options...
Pain Posted November 9, 2011 Author Share Posted November 9, 2011 no, i have full form in the echo echo '<form action="main.php?id=jams" method="POST"> Choose rating <input type="hidden" name="jamrate" /> <select name="jamrate"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> <input type="submit" name="submit" value="<?php echo $view_id; ?>"> </form><br /><br />'; and this way it doesn't work. Instead of saying submit, it now says <?php echo $view_id; ?> Quote Link to comment https://forums.phpfreaks.com/topic/250774-php-in-html/#findComment-1286612 Share on other sites More sharing options...
btellez Posted November 9, 2011 Share Posted November 9, 2011 Concatenation. Paste the "String" together like this... <?php ... echo '<form action="main.php?id=jams" method="POST"> Choose rating <input type="hidden" name="jamrate" /> <select name="jamrate"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> <input type="submit" name="submit" value="'. $view_id .'"> </form><br /><br />'; ... ?> Quote Link to comment https://forums.phpfreaks.com/topic/250774-php-in-html/#findComment-1286614 Share on other sites More sharing options...
AyKay47 Posted November 9, 2011 Share Posted November 9, 2011 you cannot nest <?php tags, this will cause unexpected results and most of the time errors. If you insist on using the echo language construct here to output your form, then drop the nested php tags.. echo "<form action='main.php?id=jams' method='POST'> Choose rating <input type='hidden' name='jamrate' /> <select name='jamrate'> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> <input type='submit' name='submit' value='$view_id'> </form><br /><br />"; also, note that you will need to assign each option element a value in order to depict which one is selected Quote Link to comment https://forums.phpfreaks.com/topic/250774-php-in-html/#findComment-1286615 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.