开发者社区> 问答> 正文

无法保存到数据库

能帮我看看吗?数据无法保存在数据库中并且没有任何功能,我已经定义了数据库

$conn = mysqli_connect(HOST,USER,PASSWORD,DATABASE); if (isset($_POST['posts'])) {

$type = mysqli_real_escape_string($conn,$_POST['ServiceType']); $status = mysqli_real_escape_string($conn,$_POST['Status']); $skill = mysqli_real_escape_string($conn,$_POST['Skill']); $location = mysqli_real_escape_string($conn,$_POST['Location']); $credit = mysqli_real_escape_string($conn,$_POST['Credit']);

//Make sure the User fill up the form correctly. if (empty($type)){ array_push($errors, "Please fill up the service type"); } if (empty($status)){ array_push($errors, "Please fill up your status"); } if (empty($skill)){ array_push($errors, "Please fill up your skill"); } if (empty($location)){ array_push($errors, "Please fill up your location"); } if (empty($credit)){ array_push($errors, "Please put your credit"); } 如果将$ _SESSION ['Login']放在if语句外,则会显示出来,但是在将if语句放到里面后,将无法显示,并且在我将外键添加为UserId后也无法保存数据库的整个功能。

if(count($errors) == 0) { //Foreign Key as UserId $LogIn = $_SESSION['Login']; echo $LogIn; $sql = "INSERT INTO post(ServiceType, status, skill, location, credit, UserId) VALUES ('$type','$status','$skill','$location','$credit', '$LogIn')"; mysqli_query($conn, $sql); $_SESSION['type'] = $type; header('location: http://localhost/Post.php'); } else { echo "Failed"; } } 有任何错误吗?因为它无法保存到数据库并且没有显示任何错误

展开
收起
保持可爱mmm 2019-11-15 14:05:48 421 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
数据库2025 V3 立即下载
阿里云数据库案例集下载 立即下载
数据库异地备份及不还原快速查询备份集最佳实践 立即下载