Jump to content

php in html


Pain

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/250774-php-in-html/
Share on other sites

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 />'; 		

Link to comment
https://forums.phpfreaks.com/topic/250774-php-in-html/#findComment-1286610
Share on other sites

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; ?>

Link to comment
https://forums.phpfreaks.com/topic/250774-php-in-html/#findComment-1286612
Share on other sites

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 />'; 		
...
?>

Link to comment
https://forums.phpfreaks.com/topic/250774-php-in-html/#findComment-1286614
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/250774-php-in-html/#findComment-1286615
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.