Josephine Bautista
Josephine Bautista

Reputation: 605

html input type inside a php file

i have a table that display a record from the database. Using this php file i would like to display the table inside the php file. I know is something wrong with this line in my code but i don't know how to fix it. I am trying to use a checkbox here to delete a row in my database.

here is that line of code:

echo "<td>  <input name=\"need_delete[<? echo $rows['id']; ?>]\" type=\"checkbox\" id=\"checkbox[<? echo $rows['id']; ?>]\" value=\"<? echo $rows['id']; ?>\">  </td>";

Thanks in advance !!

Upvotes: 0

Views: 284

Answers (7)

joaner
joaner

Reputation: 716

    echo <<<html
    <td> 
         <input name="need_delete[{$rows['id']}]" 
         type="checkbox" id="checkbox[{$rows['id']}]" value="{$rows['id']}" />  
    </td>
html;

simple!

Upvotes: 0

Anjum
Anjum

Reputation: 277

replace your code with this

echo '<td><input name="need_delete[' .$rows['id'] .']" type="checkbox" id="checkbox[' .$rows['id'] .']" value="' .$rows['id'] .'"></td>';

Upvotes: 0

DangerPaws
DangerPaws

Reputation: 846

Try this. In addition if you use single quotes to wrap you html, you won't have to escape your double quotes.

echo '<td><input name="need_delete['.$rows['id'].']" type="checkbox" id="checkbox['.$rows['id'].']" value="'.$rows['id'].'"></td>";

Upvotes: 0

dku.rajkumar
dku.rajkumar

Reputation: 18568

try this

echo "<td><input name='need_delete[".$rows['id']."]' type='checkbox' 
         id='checkbox[".$rows['id']."]' value='".$rows['id']."'>  </td>";

Upvotes: 0

Ethan
Ethan

Reputation: 2784

You don't need to call the php processing directives each time you want to use a php variable within your code. If you are using 'echo', I assume you have already declared that this is php, so you can just write the variables as:

echo "<html attribute='".$var."'></html>";

Upvotes: 0

Jeff Wooden
Jeff Wooden

Reputation: 5479

echo '<td><input name="need_delete['.$rows['id'].']" type="checkbox" id="checkbox['.$rows['id'].']" value="'.$rows['id'].'"></td>';

Upvotes: 1

Patrickdev
Patrickdev

Reputation: 2381

The reason it's wrong is because you're attempting to use php code (the variables) in the middle of a string. You must first close the string and then display the variables:

echo "<td>  <input name=\"need_delete[".$rows['id']."]\" type=\"checkbox\" id=\"checkbox[".$rows['id']."]\" value=\"".$rows['id']."\">  </td>";

Alternatively you can close the PHP code and make it interpret as HTML (I prefer this way):

?><td>  <input name="need_delete[<?php echo $rows['id']; ?>]" type="checkbox" id="checkbox[<?php echo $rows['id']; ?>]" value="<?php echo $rows['id']; ?>">  </td>";<?php

Upvotes: 1

Related Questions