我有一个不起作用的选择。
$person = mysql_query ("Select personID from persons order by personID desc Limit 0,1");
$query_string = 'INSERT INTO topics (topic,
description,
abstract,
personID)
VALUES (?, ?, ?, ?)';
$query = $db->prepare($query_string);
$query->execute(array($_POST['topic'],
$_POST['description'],
$_POST['abstract'],
$person));
我不明白问题出在哪里
答案 0 :(得分:1)
$person
是一个mysql结果,而不是任何值。
试试这个:
list($person) = mysql_fetch_row(mysql_query("select personID from ....."));
答案 1 :(得分:0)
这是问题......
$person = mysql_query ("Select personID from persons order by personID desc Limit 0,1");
这样做......
$result = mysql_query ("Select personID from persons order by personID desc Limit 0,1");
$row = mysql_fetch_array($result);
$person = $row['personID'];
答案 2 :(得分:0)
$dbh = new PDO('mysql:host='.$server.';dbname='.$db, $user, $pass);
$st=$dbh->prepare('Select personID from persons order by personID desc Limit 0,1');
$st->execute();
$result=$st->fetchAll();
//FOR TEST PURPOSE TO MAKE IT EASY.
echo "<pre>";
print_r($result);
echo "</pre>";
//END TEST
echo $result[0]['personID'];
尝试使用此PDO代码来选择和使用数据.PDO是一种优先方式。而且使用mysqli而不是mysql。 我们不清楚您的担忧。如果您复制粘贴错误消息或通过编辑您的帖子让我们清楚,说明您想要什么以及您无法做什么会更好。希望我的帮助有效!
答案 3 :(得分:0)
你正在混合来获取mysqli里面的mysql试试这个。
$person = $db->prepare("Select personID from persons order by personID desc Limit 0,1");
$person->execute();
$person->store_result();
$person->bind_result( $personID ) ; // to bind the result as variable to use it later
$person->fetch();
$query_string = 'INSERT INTO topics (topic,
description,
abstract,
personID)
VALUES (?, ?, ?, ?)';
$query = $db->prepare($query_string);
$query->execute(array($_POST['topic'],
$_POST['description'],
$_POST['abstract'],
$personID));