2014-04-11 155 views
0

嗨,这是我第二次在这个网站发布。我查看了另一篇关于此消息的文章,但无法弄清楚这一点。堆栈溢出调用堆栈#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> 
+0

你说:“我收到以下错误消息”,但你从来没有说明它实际是什么。 – patricksweeney

+0

堆栈溢出调用堆栈#timememoryfunctionlocation 10.0000143728 –

回答

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> 
+0

谢谢tliokos ...这就像一个魅力工作!你达人! :) –