Jus*_*sti 9 html php forms xampp redirect
所以,在这里,我再次遇到另一个问题 - .-'
我编写了自己的php/html脚本来输入并将数据从表单传递到数据库.一开始它起作用了.不知何故,几天后它开始将我重定向到XAMPP localhost主页(http:// localhost/xampp /).我不明白为什么:/
这是我的网站的样子:
这是我的"addguestbook.php"的样子:
<?php
...database stuff...
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$comment = $_POST['comment'];
$datetime = date("l, jS M Y, g:i a"); //date time
// Connect to server and select database.
mysql_connect($host, $username, $password)or die("cannot connect server: ".mysql_error());
mysql_select_db($db_name)or die("cannot select DB: ".mysql_error());
$sql="INSERT INTO ".$tbl_name."(id, name, email, website, comment, datetime)VALUES('".$post_id."', '".$name."', '".$email."', '".$website."', '".$comment."', '".$datetime."')";
$result=mysql_query($sql);
mysql_close();
header('Location: http://'.$hostname.$path.'/index.php' . $get, true, 303);
}?>
<form action="index.php<? echo $get; ?>" method="post">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="guestbookFormCell" colspan='2'><input
class="guestbookInputFieldText" name="name" type="text"
value="Name *" size="40" maxlength="30" /></td>
</tr>
<tr>
<td class="guestbookFormCell" colspan='2'><input
class="guestbookInputFieldText" name="email" type="text"
value="E-Mail (won't become displayed)" size="40" maxlength="40" />
</td>
</tr>
<tr>
<td class="guestbookFormCell" colspan='2'><input
class="guestbookInputFieldText" name="website" type="text"
value="Website" size="40" maxlength="50" /></td>
</tr>
<tr>
<td class="guestbookFormCell" colspan='2'><textarea
class="guestbookInputFieldText" name="comment" cols="37" rows="5">Comment *</textarea>
</td>
</tr>
<!--
<tr>
<td>CAPTCHA</td>
</tr>
-->
<tr>
<td><button class="guestbookFormCell guestbookButton" type="submit"
name="submit">
<span class='guestbookButtonText'>Send</span>
</button></td>
<td><button class="guestbookFormCell guestbookButton" style="float:right;"type="reset"
name="reset">
<span class='guestbookButtonText'>Reset</span>
</button></td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
在index.php中:
$get = "?mod=home";
Run Code Online (Sandbox Code Playgroud)
这个脚本用于几个东西:页面的整体测量书和单个帖子和图片/专辑的评论.
PS:我不能在线程的开头写你好,出于某种原因:/如果那个粗鲁,我很抱歉!
PSS:得到了错误.
非常愚蠢 :)
我只是忘了论坛实际上是在根目录中重定向到(在本例中)index.php.这意味着Xampp/htdocs/index.php.
我只需要修复链接,我很好 - .-'
我很高兴你确实发现了问题所在,因为我实际上无法理解你的脚本是如何工作的,但是,在分配 $name、$email、$website 等时,你必须使用 mysql_espace_string()。否则,用户可能会注入恶意代码并有权访问整个 SQL 表。
$name = mysql_escape_string($_POST['name']);
$email = mysql_escape_string($_POST['email']);
$website = mysql_escape_string($_POST['website']);
$comment = mysql_escape_string($_POST['comment']);
$datetime = date("l, jS M Y, g:i a"); // Escaping the string is not necessary here.
Run Code Online (Sandbox Code Playgroud)
(抱歉有任何语言错误:我的母语不是英语。)
| 归档时间: |
|
| 查看次数: |
3294 次 |
| 最近记录: |