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