在第一部分我试图获取我刚创建的条目的表组的主键(group_id),如下所示:
try{
$create_group="INSERT INTO groups(group_name, group_text, dt, perm,
group_pw) VALUES (?, ?, ?, ?, ?)";
$query=$link->prepare($create_group);
$query->execute(array($group_name, $group_desc, $dt, $permission,
$password));
$create_group="SELECT * FROM groups WHERE group_name = ? , group_text = ?
, dt = ? , perm = ? , group_pw = ?";
$query=$link->prepare($create_group);
$query->execute(array($group_name, $group_desc, $dt, $permission, $password));
$gid=$query->fetchAll();
if(count($gid)==0){
$gid="error";
}else{
$gid=$gid['group_id'];
}
header("location: ../group.php?gid=".$gid);
} catch(PDOException $e) {
echo $e;
}
$create_group="INSERT INTO groups(group_name, group_text, dt, perm,
group_pw) VALUES (?, ?, ?, ?, ?)";
$query=$link->prepare($create_group);
$query->execute(array($group_name, $group_desc, $dt,
$permission, $password));
$create_group="SELECT * FROM groups WHERE group_name = ? ,
group_text = ? , dt = ? , perm = ? , group_pw = ?";
$query=$link->prepare($create_group);
$query->execute(array($group_name, $group_desc, $dt,
$permission, $password));
$gid=$query->fetchAll();
if(count($gid)==0){
$gid="error";
}else{
$gid=$gid['group_id'];
}
header("location: ../group.php?gid=".$gid);
} catch(PDOException $e) {
echo $e;
}
然后我想像这样得到整行:
<?php
if(isset($_POST['gb'])){
include ("./inc/woall.inc.php");
}elseif(isset($_POST['gi'])){
$create_group="SELECT * FROM groups WHERE group_id = ?";
$query=$link->prepare($create_group);
$query->execute(array($_GET['gid']));
$group_info=$query->fetchAll();
if(count($group_info)==0){
echo "<h2>group dosn't exist</h2>";
}else{
?>
<div>
<?php echo $group_info['group_text']; ?>
<?php echo $gr<?php
if(isset($_POST['gb'])){
include ("./inc/woall.inc.php");
}elseif(isset($_POST['gi'])){
$create_group="SELECT * FROM groups WHERE group_id = ?";
$query=$link->prepare($create_group);
$query->execute(array($_GET['gid']));
$group_info=$query->fetchAll();
if(count($group_info)==0){
echo "<h2>group dosn't exist</h2>";
}else{
?>
<div>
<?php echo $group_info['group_text']; ?>
<?php echo $group_info['dt']; ?>
<?php echo $group_info['perm']; ?>
</div>
<?php
}oup_info['dt']; ?>
<?php echo $group_info['perm']; ?>
</div>
<?php
}
但是我没有在第一个选择查询中获得主键(group_id)我总是得到$ gid =“错误;而在第二部分我得到的结果因为我最终在其他地方我总是最终得到通知:未定义的索引。 可能只是表或列名称的问题?
提前致谢
答案 0 :(得分:0)
未定义的索引表示未设置您的变量。这可能与你的if条件说明的事实有关:
}elseif(isset($_POST['gi'])){
但您的数据库查询说:
$query->execute(array($_GET['gid']));
是gi
还是gid
?我想你可以同时使用两者。这是一个不同的故事,它是POST
还是GET
虽然...