0

here am trying to fetch data from a mysql table and populate it in a html. Everything works fine But I want to echo a html button through a IF condition. I dont know if this could work..if it works...can anyone please tell me how to make it work ?. The error am getting is...INTERNAL SERVER ERROR :(

NOTE : I have commeted the exact place where i have problem

<?php
if(mysql_num_rows($sql)){
    while($rs = mysql_fetch_object($sql))
    {
    ?>  
        <tr>
            <td align="center"><?php echo $rs->cnf_name ;?></td>
            <td align="center"><?php echo $rs->address;?></td>
            <td align="center"><?php echo $rs->added_on;?></td>
            <td align="center"><input type="button" class="btn" value="Edit" onClick="window.parent.editCnf('<?php echo $rs->cnf_name;?>','<?php echo $rs->username ;?>','<?php echo $rs->password;?>','<?php $rs->type;?>','<?php echo $rs->person_name;?>','<?php echo $rs->address;?>','<?php echo $rs->mobile_no?>','<?php echo $rs->email;?>','<?php echo $rs->country;?>','<?php echo $rs->city;?>','<?php echo $rs->state;?>','<?php echo $rs->area;?>')" ></td>




//PROBLEM


            <td align="center">

            <?php
            if($rs->cnf_status == 0)
            {
            echo "<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf(<?php echo $rs->user_id;?>,<?php echo $rs->cnf_status; ?>);">";
            }
            else
            {
            echo "<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf(<?php echo $rs->user_id;?>,<?php echo $rs->cnf_status; ?>);">";

            }
?>          




            </td>
        </tr>
<?php
    }
}
else
{
?>      <tr>
            <td colspan="">No data to display</td>
        </tr>
<?php
}
?>      
    </tbody>
</table>

4 Answers 4

3

Problem comes from the quotes you use with echo; Either go for

echo 'htmlcode_with_doublequotes';

or

if($rs->cnf_status == 0)
{
?>
       <input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf("<?php echo $rs->user_id;?>","<?php echo $rs->cnf_status; ?>");">
<?php
}
else
{
?>
       <input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf("<?php echo $rs->user_id;?>","<?php echo $rs->cnf_status; ?>");">
<?php
}
Sign up to request clarification or add additional context in comments.

Comments

1

That just appears to be a problem with quotes in the echo of the button html.

if($rs->cnf_status == 0)
        {
        echo '<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf(<?php echo $rs->user_id;?>,<?php echo $rs->cnf_status; ?>);">';
        }
        else
        {
        echo '<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf(<?php echo $rs->user_id;?>,<?php echo $rs->cnf_status; ?>);">';

        }

Comments

0

Try this:

<?php
if($rs->cnf_status == 0)
{
echo '<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf('.$rs->user_id.','.$rs->cnf_status.');">';
}
else
{
echo '<input type="button" class="btn" id="status" value="Activate" onClick="window.parent.deleteCnf('.$rs->user_id.','.$rs->cnf_status.');">';

}
?> 

Comments

0

The problem is in your syntax. You have to escape " in your echos:

<?php
    if($rs->cnf_status == 0)
        {
        echo "<input type=\"button\" class=\"btn\" id=\"status\" value=\"Activate\" onClick=\"window.parent.deleteCnf({$rs->user_id}, {$rs->cnf_status});\">";
        }
    else
        {
        echo "<input type=\"button\" class=\"btn\" id=\"status\" value=\"Activate\" onClick=\"window.parent.deleteCnf({$rs->user_id}, {$rs->cnf_status});\">";
        }
?>          

OR

<?php
    if($rs->cnf_status == 0)
        {
        echo '<input type="button" class="btn" id="status" value="Activate" onclick="window.parent.deleteCnf(' . $rs->user_id . ', ' . $rs->cnf_status . ');">';
        }
    else
        {
        echo '<input type="button" class="btn" id="status" value="Activate" onclick="window.parent.deleteCnf(' . $rs->user_id . ', ' . $rs->cnf_status . ');">';
        }
?>          

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.