English 中文(简体)
为什么要赢得该《公约》的《任择议定书》的工作?
原标题:why wont this php code work?
  • 时间:2011-10-29 02:25:08
  •  标签:
  • php
  • mysql

我有一个包含一些信息的数据库。 (电子邮件地址和名称)

我有进入电子邮件的表格,我想打印本属于这一电子邮件的名称。

$test = $_POST[ mail ]; //the html code works, $test prints out the email given.

$question = mysql_query("SELECT name FROM mydb WHERE email =  ".$_POST[ mail ]." ")or die(mysql_error());

while($foo = mysql_fetch_assoc($question))
{
echo $test . " - ";
echo $foo;
}

为什么打上 print印的帽子? 迄今为止,由于某种原因,它印刷了<代码>Array。

感谢

最佳回答

http://php.net/manual/en/Function.mysql-fetch-assoc.php rel=“nofollow”>mysql_fetch_assoc

回归的关联性阵列,与左轮行相对应。

查阅您需要填写的<代码>$foo[名称];

问题回答

请被用来安置持有人以避免注射攻击。 mysql_fetch_assoc(mysqli:fetch_assoc对等,因为它们都返回了联系阵列;我刚刚找到了面向目标的更清洁版本。

<?php
$stmt = $dbh->prepare("SELECT name FROM mydb WHERE email = ?");
if ($stmt->execute(array($_POST[ mail ]))) {
    while ($row = $stmt->fetch_assoc()) {
      echo $test . " - " . echo $foo[ name ];
    }
}
?>

因为它是一个阵列(如我的sql_fetch_assoc()所示) (并可能避免另一种申请可转用于注射KQ)。 你们必须使用一个指数来获取一个电池的价值:

$foo[ name ]
$test = mysql_real_escape_string($_POST[ mail ]);

$question = mysql_query("SELECT name, foo FROM mydb WHERE email =  $test ")or die(mysql_error());

while($foo = mysql_fetch_assoc($question)) { 
echo $test =  $foo[ name ] ;
echo $foo = $foo[ foo ] ; 
}




相关问题
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 ...

热门标签