0

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

1
  • 1
    What's the error? Can you post the HTML that comes from this? Commented Jan 14, 2012 at 17:18

7 Answers 7

1

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
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

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

Comments

0

try this

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

Comments

0

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

Comments

0

replace your code with this

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

Comments

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

simple!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.