这是我在页面顶部的内容,从数据库中的表中收集信息:
include_once '../assets/database.php';
$a = $_GET['a'];
$username = $_SESSION['username'];
$user_q = $db->prepare("SELECT * FROM `users` WHERE `username` = '$username'");
$user_q->execute();
$user_i = $user_q->fetch();
$aboutQ = $db->prepare("SELECT * FROM `info` WHERE uid = :id");
$aboutQ->execute(array(':id' => $user_i['id']));
$about = $aboutQ->fetch();
$about_ex = $db->prepare("SELECT * FROM `info` WHERE uid = :uid");
$about_ex->execute(array(':uid' => $user_i['id']));
$aboutRow = $about_ex->rowCount();
和底层查询,创建新行或更新现有行,具体取决于用户是否已在表中有一行:
if($a === "post") {
$motto = $_POST['motto'];
$bio = stripslashes($_POST['bio']);
$grade = $_POST['grade'];
$sex = $_POST['sex'];
$phone = $_POST['phone'];
$aboutUid = $_POST['uid'];
if($aboutRow == 0) {
$q = $db->prepare("INSERT INTO `info` (motto, bio, grade, sex, favevent, position, phone, hours, uid) VALUES (:motto, :bio, :grade, :sex, null, null, :phone, null, :uid)");
$q->bindParam(':motto', $motto);
$q->bindParam(':bio', $bio);
$q->bindParam(':grade', $grade);
$q->bindParam(':sex', $sex);
$q->bindParam(':phone', $phone);
$q->bindParam(':uid', $aboutUid);
$q->execute();
}
else {
$q = $db->prepare("UPDATE `info` SET motto=?, bio=?, grade=?, sex=?, favevent=?, position=?, phone=? hours=? WHERE uid=?");
$q->execute(array($motto,$bio,$grade,$sex,null,null,$phone,null,$aboutUid));
}
header("Location: ../members");
exit;
}
它没有给我一个错误 - 但每次执行它都没有任何反应。
答案 0 :(得分:1)
是的,你有SQL语法错误:
$q = $db->prepare("UPDATE ... position=?, phone=? hours=? WHERE uid=?");
^-- missing comma
因为你说没有显示错误,你可能没有启用异常运行,所以你绝对必须检查来自DB调用的返回值并检查boolean false。