堆栈溢出调用堆栈#timememoryfunctionlocation 10.0000143728

时间:2014-04-11 18:31:59

标签: php mysql

嗨,这是我第二次在这个网站上发帖。我看了@关于这条消息的另一篇文章,我无法弄清楚这一点。

因此,我尝试使用数据库中的数据存储动态填充下拉框的内容。

我在数据库中的每个记录的下拉列表中显示以下错误消息(3次)

任何帮助将不胜感激。 感谢

<!DOCTYPE html>
<?php
$con=mysqli_connect("localhost","root","","project1");
// Check connection
        if (mysqli_connect_errno())
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }

// this block would be at the top of your file above the html
$query = "select * from countries";
$country_results = mysqli_query($con,$query);
$number_of_returns = mysqli_num_rows($country_results);
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="site.css">
</head>
<body>
<h1>Insert Site into DB</h1>
    <h2 class="button"><a href=/index.html>Home</a></h2>
    <h2 class="button"><a href=/insert.html>add site</a></h2>
    <h2 class="button"><a href=/delete.html>delete site</a></h2>
    <h2 class="button"><a href=/search.html>search site</a></h2>
        <form class="insert" action="insert.php" method="post">
                <p>Site Info</p>
                Site code:<input type="text" name="site_code"><br>
                Site name: <input type="text" name="site_name"><br>
                Address: <input type="text" name="site_address"><br>
                City:<br>
                Postal code: <input type="text" name="site_postalcode"><br>
                Province: <select name="province"></select><br>
                Country: <select name=”country”>
                <?php while (($row = mysqli_fetch_row($country_results)) != null){ ?>
                <option value=”<?php echo $row[‘country’];?></option>
            <?php } ?>
                </select><br>


            <p>Site Contact Info</p>
            Site contact name: <input type="text" name="site_contact_name"><br>
            Phone number 1: <input type="number" name="site_contact_number1"><br>
            Phone number 2: <input type="number" name="site_contact_number2"><br>
            Email address: <input type="email" name="site_contact_email"><br> 
            <input type="submit">
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

如果要将结果作为关联数组访问,例如$row['country']您必须使用mysqli_fetch_assoc。使用mysqli_fetch_row,您可以$row[0]访问结果。此外,您的代码中的一些奇怪的引号必须被替换以及您的html中的一些其他错误,例如选项中缺少值属性关闭引号。这将起作用:

<select name="country">

<?php while($row = mysqli_fetch_assoc($country_results)){ ?>

<option value="<?php echo $row['title'];?>"><?php echo $row['title'];?></option>

<?php } ?>

</select>