English 中文(简体)
功能分布图
原标题:Function populates first listbox but not the second from a database table

Function popList() takes two parameters - name of the column and name of the table. Basically the popList() function connects to a mysql server and then a database and builds an sql query to retrieve data based on what you passed to the function to be used to populate a listbox on the page.

只有一个名单箱与这一功能相配,但如果在网页上有第二个名单箱,要求该功能再次使用不同的参数(颜色名称和表格名称),则该名单似乎空洞,以下文字在第一人口名单箱的源头上打印:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user ODBC @ localhost (using password: NO) in C:xampphtdocs est on line 7
Not connected : Access denied for user ODBC @ localhost (using password: NO)

我在两条电话中都使用同样的联系全权证书,这些电话是缺席的当地东道方,是根本的,没有密码(纯粹为了测试目的)。

Why is it behaving like this?

www.un.org/Depts/DGACM/index_spanish.htm

<?php
function popList($col, $tbl) {

    require_once "credentials.php";

    // Opens a connection to a MySQL server
    $connection=mysql_connect($host, $username, $password);
    if (!$connection) {
      die( Not connected :   . mysql_error());
    }

    // Set the active MySQL database
    $db_selected = mysql_select_db($database, $connection);
    if (!$db_selected) {
      die ( Can t use db :   . mysql_error());
    }

    $sql = "SELECT $field FROM $table";
    $query = mysql_query($sql);

    while ($row = mysql_fetch_array($query)) {
        echo  <option value="  . $row["$field"] .  ">  . $row["$field"] .  </option> ;
    }

    mysql_close($connection);
}
?>

<NEW>/em>: 见require_once include_once。 产生这一问题,但使用<代码>include或require< 这个问题实际上已经解决。

require_once "credentials.php> with the actual Code from credentials.php 如:

function popList(...) {

require "credentials.php"; // changed to require from require_once. same with include


...
}
最佳回答

require_once does what it says: it requires once. The first time popList is called, everything in credentials.php gets dumped into your function s scope. The second time popList is called, nothing happens because credentials.php was already required once during this run.

您在档案中应有一个组合,而不是一个变数的缩略语,你不应在类似职能范围内使用<代码>require或include,而您应拥有E_STRICT,因此请见关于<代码>的警告。 等等没有界定。

问题回答

代表你,

我在两条电话中都使用同样的联系全权证书,这些电话是缺席的当地东道方,是根本的,没有密码(纯粹为了测试目的)。

由于你重新提到根本用户,没有密码,因此,在错误中,它如下:<><<>条码>。 用户ODBC @ localhost(使用密码:NO),这意味着你实际上试图将用户代码与无密码连接起来,我认为这些密码有密码。

Hi

$query="SELECT * FROM bus_type order by bus_type_id Asc";
$result = mysqli_query($conn, $query);
echo "<select name=bustype size=sizes class=bus_txtbox value=  >Type of the Bus</option>";
    while($line=mysqli_fetch_array($result, MYSQLI_ASSOC)){
    echo "<option value=$line[bus_type_id]>$line[bus_type]</option>";
}
echo "</select>";




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签