Php $服务器[“请求”方法]在应为true时返回false时出现未知问题
嘿,用户们,我遇到了一个非常令人困惑的问题,我似乎无法回避。我正在创建一个论坛类型的网页,目前正在处理评论部分。我有一个表单,它使用post方法发送您的评论,以及一个隐藏的输入来存储线程ID。我将在下面发布整个php文件,以确保没有遗漏任何内容Php $服务器[“请求”方法]在应为true时返回false时出现未知问题,php,forms,validation,post,Php,Forms,Validation,Post,嘿,用户们,我遇到了一个非常令人困惑的问题,我似乎无法回避。我正在创建一个论坛类型的网页,目前正在处理评论部分。我有一个表单,它使用post方法发送您的评论,以及一个隐藏的输入来存储线程ID。我将在下面发布整个php文件,以确保没有遗漏任何内容 <?php session_start(); parse_str($_SERVER['QUERY_STRING'], $link); $threadID = $link['ID']; require("config.php");
<?php
session_start();
parse_str($_SERVER['QUERY_STRING'], $link);
$threadID = $link['ID'];
require("config.php");
$connection = mysqli_connect($host, $user, $password, $database);
$error = mysqli_connect_error();
if($error != null) {
$output = "<p>Unable to connect to database!</p>";
exit($output);
} else {
//Get Thread Data
$query = "SELECT username, title, content FROM threads, users WHERE threads.ID = $threadID AND users.ID = threads.makerID;";
$results = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($results);
//Get Comment Data
$query = "SELECT username, comment FROM comments, users WHERE threadID = $threadID AND users.ID = comments.makerID;";
$results = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($results);
}
?>
<!DOCTYPE html>
<html>
<head lang="en">
<title>BodyweightMate</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/styling.css"/>
</head>
<body>
<!--Top masthead-->
<header class="masthead" id="top">
<h1 class="masthead-title"> Welcome To BodyweightMate </h1>
</header>
<!--Navigation bar-->
<nav class="navbar">
<table class="navbar-table">
<tr>
<!--Logo-->
<td>
<a class="navbar-brand" href="main.php">
<img src="../images/logo.jpg" alt="BodyweightMate" height="30" width="30">
</a>
</td>
<!--Login/Profile-->
<?php if(isset($_SESSION['login_user'])) {
echo"<td><a class=\"navbar-profile\" href=\"profile.php\"> Profile </a></td>";
echo"<td><a class=\"navbar-logout\" href=\"logout.php\"> Logout </a></td>";
} else {
echo"<td><a class=\"navbar-login\" href=\"login.php\"> Login </a></td>";
}?>
</tr>
</table>
</nav>
<!--Main portion-->
<section class="content-section">
<article>
<h3><?php echo $row['username']. ": " .$row['title']; ?></h3>
<p><?php echo $row['content']; ?></p>
<br>
<h3>Comments</h3>
<p>Some annoying user: Gr8 B8 M8</p>
<p>Annoying users friend: I R8 8/8</p>
</article>
<div>
<!--If logged in, ability to comment-->
<?php if(isset($_SESSION['login_user'])): ?>
<form role="comment-form" method="POST" action="processcomment.php" id="mainForm">
<input type="hidden" value="$threadID" name="threadID">
<div class="form-group">
<label for="comment">Comment </label> <br>
<textarea class="comment-text" name="comment" rows="2" maxlength="255"></textarea>
</div> <br>
<input type="Submit" class="btn-newcomment" value="Submit Comment" name="submit">
</form>
<?php endif ?>
</div>
</section>
<!--Right portion-->
<aside class="content-aside">
<div>
<!--If logged in, be able to create a thread-->
<?php
if(isset($_SESSION['login_user'])) {
echo"<form method=\"post\" action=\"makethread.php\">";
echo"<input type=\"submit\" class=\"btn-newthread\" value=\"Create New Thread\" name=\"submit\">";
echo"</form>";
}
?>
</div>
<!--Info-->
<div>
<p> GOING TO NEED A SEARCH FUNCTION HERE
This is the cool little aside section. It will always be there to provide you with some very nice little details, helpful links, maybe a list of moderators? who knows! The uses are endless when you have a beautiful little aside like this one! Here are a few very useful bodyweight fitness links to get us started :D </p>
</div>
<br>
<div>
<ul class="content-aside-links">
<li>
<a href="https://www.reddit.com/r/bodyweightfitness"> Reddit's Bodyweightfitness Forum </a>
</li>
<li>
<a href="https://www.reddit.com/r/bodyweightfitness/wiki/kb/recommended_routine"> Reddit's Bodyweightfitness RR </a>
</li>
<li>
<a href="http://antranik.org/bodyweight-training/"> Antranik's Bodyweightfitness Routine </a>
</li>
</ul>
</div>
<div></div>
</aside>
<!--Footer -->
<footer class="footer">
<div>
<p> Use of this site constitutes acceptance of our User Agreement © 2017 BodyweightMate inc. All rights reserved. </p>
</div>
</footer>
</body>
</html>
体重伙伴
欢迎来到BodyweightMate
使用本网站即表示接受我们的用户协议和副本;2017 BodyweightMate inc.版权所有
错误发生在主部分下,我检查用户是否登录,以及是否添加了由消息、文本区域和提交按钮组成的简短表单。此表单将信息发送到以下php文件
<?php
session_start();
if(!isset($_SESSION['login_user'])) { header("location: main.php"); }
?>
<!DOCTYPE html>
<html>
<body>
<?php
require("config.php");
$connection = mysqli_connect($host, $user, $password, $database);
$error = mysqli_connect_error();
if($error != null) {
$output = "<p>Unable to connect to database!</p>";
exit($output);
} else {
//Validation
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$comment = $_POST['comment'];
$threadID = $_POST['threadID'];
$user = $_SESSION['login_user'];
} else {
//Redirect back to register
echo"<p>Form must use post or input was bypassed.</p>";
echo"<a href=\"main.php\"> Return to home page. </a>";
mysqli_close($connection);
exit();
}
在控制台中检查表单方法是否为post did,控制台显示此消息哦,等等,对不起,你是说通过将该信息发送到控制台进行测试吗?@ZacGrafton,如v Sugumar所述,检查chrome开发工具的“网络”选项卡,检查请求是否为post请求。@ZacGrafton非常奇怪,您是否使用.htaccess
管理对服务器的请求?