doudui5753 2013-03-19 17:27
浏览 53
已采纳

html文件中的php脚本错误

i'm relatively new to this trying to get a mysql database array of Username to be shown in a html drop down input for another form however the php script just keep being shown rather than the function. below is a screenshot of the error

http://s10.postimage.org/j4xuamkwp/untitled.png

the php script is sat within my html file

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'fid';

$conn = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$conn)
die('Could not connect: ' . mysql_error());

mysql_select_db($db);

echo '<label class="input" for="investigator" type="input">Importance:</label><select id="investigator" name="investigator">';
$resource = mysql_query("SELECT `Username` FROM `user`");
if($resource && mysql_num_rows($resource)) {
    while ($row = mysql_fetch_assoc($resource)){
        echo '<option value="'.$row['Username'].'">'.$row['Username'].'</option>';
    }
}
echo '</select>';
mysql_close($conn)
?>

I think its an issue within the while loop however cannot fix it and its getting very frustrating!

  • 写回答

3条回答 默认 最新

  • douwen5066 2013-03-19 17:29
    关注

    Your file needs to have a .php extension to work properly.

    .html will not be recognized as a php file.

    Name your file: myfile.php for files that have php code in them. NOT myfile.html

    EDIT: As others have pointed out, you can add html as a php type, but that's not typically how it's done, nor would I recommend it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器