0
$con = mysql_connect("localhost","root","");
if (!$con) die('Could not connect: ' . mysql_error());
mysql_select_db("pilot", $con);

$sql = "INSERT INTO logs (id, userid, date, plane, from, to, blocksoff, takeoff,
landing, blockson, flighttime, traveltime, tachobefore, tachoafter, tacho, 
hobbsbefore, hobbsafter, hobbs, landings) VALUES ('$nfid', '$nfuserid', 
'$nfdate', '$nfplane', '$nffrom', '$nfto', '$nfblocksoff', '$nftakeoff', 
'$nflanding', '$nfblockson', '$nfflighttime', '$nftraveltime', '$nftachobefore', 
'$nftachoafter', '$nftacho', '$nfhobbsbefore', '$nfhobbsafter', '$nfhobbs',
'$nflandings')";

mysql_query($sql);

$sql 没有任何问题,它似乎只是不会查询.. :(

id|userid=int(11)  
date=date  
plane|from|to=text  
blocksoff|takeoff|landing|blockson=time  
flighttime|traveltime|tachobefore|tachoafter|tacho|hobbsbefore|hobbsafter|hobbs|landings=double

所有的 $ 变量都来自一个文本框(如果重要的话)

4

3 回答 3

4

可能有些列名是MySql 的保留字(尤其是fromand to)。请逃离他们。

INSERT INTO logs (`id`, userid, date, plane, `from`, `to` ...)
于 2012-06-25T03:33:39.597 回答
0

您应该始终检查错误:

$result = mysql_query($sql);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
于 2012-06-25T03:32:47.663 回答
0

有点开放式的问题......

您的任何变量是否返回 NULL 值?如果您尝试将 NULL 插入数据库,并且数据库列未设置为接受 NULL 值,则可能会导致错误。

您需要查看查询实际在做什么。如果文本框中有任何单引号或其他无效字符,那可能会搞砸你。

此外,为了您自己的个人进步,请查找 PDO。它可以帮助您通过使用准备好的语句编写更安全的查询。 http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/

于 2012-06-25T03:33:36.660 回答