堆栈溢出调用堆栈#timememoryfunctionlocation10.0000143728


stack overflow call stack #timememoryfunctionlocation 10.0000143728

嗨,这是我第二次在这个网站上发帖。我查看了与这条消息有关的另一篇文章,但无法理解这一点。

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

我在DB(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>

如果您想以关联数组的形式访问结果,例如$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>