当前位置: 动力学知识库 > 问答 > 编程问答 >

php while statement causing 500 error

问题描述:

I'm completely stumped here. I've written the code below and when I view the page I get a 500 error. Via process of commenting out select lines one by one I was able to find that the while statement is causing the error...could anyone tell me what could possible be wrong with my code?

<?php

$rQuery = "SELECT * FROM roles ORDER BY roleName ASC";

$rResult = mysql_query($rQuery);

if (!$rResult){

echo 'Query Error <br>' . $rQuery;

exit;

}

?>

<p>

<select name="roleaddid" id="roleaddid" >

<?php while ($roles = mysql_fetch_array($rResult)){ ?>

<option value="<?php echo $roles['roleId'] ?>"><?php echo $roles['roleName'] ?></option>

<? } // end while ?>

</select>

</p>

thanks for any insight...

网友答案:

You need to fix the <? ?> around your ending brace.

Change to <?php ?>

网友答案:

donutdan definately gets the answer, you need short tags enabled.... also if your using short tags like so: <? echo $blank ?> you should still end your echo with a semi colon, and even better yet, call the variable this way

<?=$variable?>

that way you don't have to echo every time like that....

网友答案:
<?php 

            //add your mysql connect
            $rQuery = "SELECT * FROM roles ORDER BY roleName ASC";
            $rResult = mysql_query($rQuery);

            if (!$rResult){
                echo 'Query Error <br>' . $rQuery;
                exit;
            }

        ?>
        <p>
            <select name="roleaddid" id="roleaddid" >

              <?php while ($roles = mysql_fetch_array($rResult)){ ?>

                <option value="<?php echo $roles['roleId'] ?>"><?php echo $roles['roleName'] ?></option>

                <?php } // end while ?>

            </select>

        </p>
分享给朋友:
您可能感兴趣的文章:
随机阅读: