我已经试了好几个小时了。我可以连接到我的数据库并插入到其中,但似乎无法从中获得任何东西。
// Declarations
$connection = mysql_connect("xxxxxxx", "xxxxxxx", "xxxxxxxx");
mysql_select_db("kettle_test1", $connection);
if (!$connection)
{
die ('Cold not connect: ' . mysql_error());
}
else
{
echo "connected <br> <br>";
}
// INSERT
mysql_query("INSERT INTO bob2 (Danumber)
VALUES ('32234245')");
// QUERY AND DISPLAY
$result = mysql_query("SELECT * FROM bob2");
echo $result;
// if this is commented out I get the 'connected' message above. without it the page is blank,
while ($row = mysql_fetch_assoc($result)) {
echo $row["Danumber"];
}
*/
echo "<br> <br> <br>";发布于 2011-06-16 21:51:41
这里有很多可能性。例如,您可以尝试以下操作:
mysql_num_rows检查返回了多少行print_r打印整行。isset检查键"Danumber“是否确实存在<代码>H29<代码>F210总结:使用更多的检查来确保你检索到的东西确实在那里。
发布于 2011-06-16 21:53:33
我会先测试一下插入是否真的正常:
// INSERT
$result = mysql_query("INSERT INTO bob2 (Danumber)
VALUES ('32234245')");
if (!$result) {
die('Invalid insert query: ' . mysql_error());
}否则,您无法在以后进行选择。但这可能不是你问题的原因。
但是您也可以对SELECT查询执行相同的操作:
// QUERY AND DISPLAY
$result = mysql_query("SELECT * FROM bob2");
if (!$result) {
die('Invalid select query: ' . mysql_error());
}完成后,您可以验证查询是否至少通过了w/o错误。
然后,您应该确保可以获取和显示数据:
// if this is commented out I get the 'connected' message above. without it the page is blank,
while ($row = @mysql_fetch_assoc($result)) {
print_r(array_keys($row));
print_r($row["Danumber"]);
}https://stackoverflow.com/questions/6372887
复制相似问题