我有一个数据库表 - 序列(自动增量主键)、版本和 turk_number。我正在使用以下代码插入新行。我通过 $_GET 接收这些变量并且我做了一个打印输出,所以我知道这些变量是可用的,所以我不确定出了什么问题。序列号和版本已加载,但未加载 turk_number。
$turk_number ='';
$serial='';
$version='';
if(isset($_GET['serial']))
{
$serial=$_GET['serial'];
$_SESSION['serial'] = $serial;
}
if(isset($_GET['version']))
{
$version = $_GET['version'];
$_SESSION['version'] = $version;
print "version=" . $version;
}
if(isset($_GET['turk_number']))
{
$turk_number= $_GET['turk_number'];
$_SESSION['turk_number'] = $turk_number;
print "turk number=".$turk_number;
}
//this assigns a participant a unique serial id at the beginning of the game
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "resolver";
try
{
print 'turk2=' . $turk_number;
$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query2 = "INSERT INTO participants (version, turk_number) VALUES (:version, :turk_number)";
$stmt = $dbh ->prepare($query2);
$stmt ->execute(array(':version' => $version,
':turk_number' => $turk_number));
}
catch(PDOException $e)
{
echo $e->getMessage();
}