- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在关注 this在 windows7 上使用 XAMPP 的 php 教程。
这是一个留言簿教程,将用户条目保存到 mysql 中并显示来自 db 的条目。当我在表单中输入数据并提交时,浏览器显示此错误消息
禁止访问!您无权访问所请求的对象。它要么是读保护的,要么是服务器不可读的。如果您认为这是服务器错误,请联系网站管理员。错误 403本地主机Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
已更新
guestbok.php
Connect to DB Code
<?php
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
$dbDatabase = "myDB";
// Connect to DB
$li = new mysqli('localhost', 'root', '', 'myDB') or
die("Could not connect". mysqli_connect_error());
//mysql_select_db($dbDatabase, $li) or
die ("could not select DB". mysql_error());
?>
Variables initialisation
<?php
// initiate some vars
$gb_str = "";
// $gb_str is the string we'll append entries to
$pgeTitle = "View and Sign Guestbook";
Post request handling
// If form is submitted, then insert into DB
if (!empty($_POST["submit"])) {
$name = $_POST["frmName"];
$email = $_POST["frmEmail"];
$comment = $_POST["frmComment"];
$date = Date("Y-m-d h:i:s");
$gb_query = "insert into guestbook
values(0, '$name', '$email', '$comment', '$date')";
// Performs the $sql query on the server to insert the values
if ($li->query($gb_query) === TRUE) {
echo 'users entry saved successfully';
}
else {
echo 'Error: '. $li->error;
}
/*
$sql = mysql_query($gb_query);
$res = mysql_affected_rows($sql);
// See if insert was successful or not
if($res > 0) {
$ret_str="Your guestbook entry was successfully added.";
} else {
$ret_str = "Your guestbook entry was NOT successfully added.";
}
// Append success/failure message
$gb_str .= "<span class=\"ret\">$ret_str</span><BR>";
*/
}
?>
GuestBook list
<?php
$get_query = "select gbName, gbEmail, gbComment,
DATE_FORMAT(gbDateAdded, '%m-%d-%y %H:%i') gbDateAdded
from guestbook";
$result = $li->query($get_query);
$gb_str .= "<hr size=\"1\">";
if ($result->num_rows > 0) {
// output data of each row from $result
while($row = $result->fetch_assoc()) {
$name = $row["gbName"];
$email = $row["gbEmail"];
$comment = $row["gbComment"];
$date = $row["gbDateAdded"];
if(!empty($name)) {
// If name exists and email exists, link name to email
if(!empty($email)) {
$name="by <a href=\"mailto:$email\">$name</a>";
}
// If name does exist and email exists, link email to email
} else if (!empty($email)) {
$name = "by <a href=\"mailto:$email\">$email</a>";
} else {
$name = "";
}
// Append to string we'll print later on
$gb_str .= "<br>$comment<p class=\"small\">
posted on $date $name<hr size=\"1\">";
}}
?>
The HTML Page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Guestbook</TITLE>
<SCRIPT language="javascript">
<!--
/* This function is pulled from a generic validation file from
some other site (probably developer.netscape.com) and strips out
characters you don't want */
function stripCharsInBag (s, bag) {
var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}
// This function just makes sure the comment field is not empty
function valForm(frm) {
badChars = "<[]>{}";
if(frm.frmComment.value == "") {
alert("Please fill in your comments for the guestbook.");
return false;
} else {
frm.frmComment.value = stripCharsInBag(frm.frmComment.value, badChars);
// These values may be empty, but strip chars in case they're not
frm.frmName.value = stripCharsInBag(frm.frmName.value, badChars);
frm.frmEmail.value = stripCharsInBag(frm.frmEmail.value, badChars);
return true;
}
}
-->
</SCRIPT>
</HEAD>
<BODY bgcolor="#FFFFFF">
<?php echo $gb_str; ?>
<form name="gb" action="<? echo $PHP_SELF;?>" method="post">
<table cellpadding="3" cellspacing="0" border="0">
<tr>
<td class="tdhead" valign="top" align="right">Name</td>
<td valign="top">
<input type="text" name="frmName" value="" size="30"
maxlength="50">
</td>
</tr>
<tr>
<td class="tdhead" valign="top" align="right">Email</td>
<td valign="top">
<input type="text" name="frmEmail" value="" size="30"
maxlength="100">
</td>
</tr>
<tr>
<td class="tdhead" valign="top" align="right">Comment</td>
<td valign="top">
<textarea name="frmComment" rows="5" cols="30"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="submit"
onClick="return valForm(document.gb)">
<input type="reset" name="reset" value="reset">
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
<?php
// Close MySQL Connection
$li->close();
?>
最佳答案
第二个问题回答,你没有将查询结果分配给变量并且 mysql_affected_rows
也是空的。
$gb_query = "insert into guestbook
values(0, '$name', '$email', '$comment', '$date')";
$sql = mysql_query($gb_query);
$res = mysql_affected_rows($sql);
关于本地主机上的 php 错误 : Access forbidden! 错误 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12819362/
我一直收到这个“禁止您无权访问此服务器上的/。此外,在尝试使用 ErrorDocument 处理请求时遇到 403 禁止错误。”当尝试访问我的网站时,错误仍然存在,但没有安装 WordPress
我对Kibana创建的“新用户”有问题(使用用户“ flex ”)。这是我做的顺序。 我正在使用ELK for 7.5.1版本 首先,我通过添加elasticsearch.yml 来启用xpack.s
我只是在Elasticsearch 7.1.0中设置了xpack 如下在elasticsearch.yml中: xpack.security.enabled: true discovery.type:
我刚刚在新安装的 ES 堆栈上设置了身份验证。 我跟着: https://www.elastic.co/guide/en/elastic-stack-overview/current/get-star
我尝试在我的 Spring Boot 应用程序上配置 OpenFeign,我使用 pokeapi 进行测试。 我编写了这段代码: @FeignClient(value = "pokeapi", url
我正在使用strapi,我在调用api时收到错误403 Forbidden,例如http://localhost:1337/data 我已经调用了所有的 API,结果是相同的 403 错误 我也用 p
当我尝试将图片上传到“汽车”对象时,我被拒绝访问 S3。但是自从我添加了 S3 以来,assets 文件夹中的站点图像显示得很好。我得到的具体错误是这样的: 2015-02-17T14:40:48.4
当我尝试在管理员授权后添加新帖子时看到此响应。 我有基于 Spring Boot 安全性的基本授权: @Configuration @EnableWebSecurity public class Se
我有一个响应式(Reactive)(Spring WebFlux)Web 应用程序,其中很少有 protected 资源的 REST API。(Oauth2)。要手动访问它们,我需要获取具有客户端凭据
可以看到的错误是 client.GetKeyStats 函数返回的 403 Forbidden。 基于源代码无需认证。 源代码:https://github.com/timpalpant/go-iex
堆栈跟踪 Exception in thread "main" com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden (Servic
几天前,当我尝试将文件推送到我的 S3Bucket 时收到此异常。更早的一切似乎都能正常工作,我确信我这边没有代码更改。 com.amazonaws.services.s3.model.AmazonS
当用户尝试访问他们无权访问的资源时,我的服务器会返回 403 禁止错误。除了 header 之外,服务器还会写入一条描述错误的小消息。 在 Firefox 中,错误消息显示得很好,用户知道发生了什么。
我支持一个 java 应用程序,它有一个搜索栏,可以匹配关键字并从缓存中获取结果。 该应用程序在 Tomcat 中运行,并且还有一个 Apache Web 服务器。 搜索 aaa' 时出现问题,特殊字
我正在将网站从一台托管服务器移动到另一台托管服务器。我已经上传了文件。我正在使用表单例份验证。基本上,我要搬到 GoDaddy。 我可以直接访问登录表单:www.mysite.com/login.as
我创建了一个 Azure KeyVault,我希望我的应用服务能够访问它。据我所知,我的 App Service 的主体应该有权访问 KeyVault,但在尝试从中检索时,我总是收到以下错误。无论我是
我尝试通过应用上的 URLRequest 将 multipart/form-data 发送到 Cloud Functions for Firebase。为了测试我的云函数和应用程序是否已连接,我创建了
这是后端 SiteController.php 访问规则。当我浏览此 url site.com/backend/web/site/login 时。它显示禁止 (#403)。 return [
使用 java 访问 Google PubSub、Dataflow 和 BigQuery 的 Spring boot 应用程序。该应用程序是使用 maven 构建的,并将 jar 文件复制到 Goog
我在 Kubernetes* 的仪表板站点上到处都是“被禁止”(见图) 重现: 通过站点创建 Google Kubernetes 集群,而不是通过 shell。 选择 Kubernetes 版本 1.
我是一名优秀的程序员,十分优秀!