我有一個簡單的頁面(下面)和一個表單。如果action ='ask.php',表單將提交。 (ask.php是當前頁面和下面的代碼)。當我將ask.php更改爲question.php(文件夾中的另一頁)時,表單不提交。爲什麼是這樣?數據放入數據庫之前表單是否重定向?表單在操作頁面發生變化時不會提交
ask.php code;
<?php session_start(); ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.min.js'></script>
<script type='text/javascript' src='http://twitter.github.com/bootstrap/1.4.0/bootstrap-modal.js'></script>
<link rel="stylesheet" href="../css/bootstrap.css" type="text/css" media="screen" />
</head>
<body>
<?php include '../css/bar.php'; ?>
<div id='content'>
<?php include '../nav.php';
?>
<?php
if (isset($_POST['submit'])){
include '../connect.php';
$question=mysql_real_escape_string($_POST['question']);
$detail=mysql_real_escape_string($_POST['detail']);
$date=date("d M Y");
$time=time();
$user=$_SESSION['id'];
$put=mysql_query("INSERT INTO questions VALUES ('','$question','$detail','$date','$time','$user','subject','0')");
$result=mysql_query("SELECT * FROM questions WHERE user='$user' AND time='$time'");
while ($row = mysql_fetch_assoc($result)){
$q=$row['id'];
}
}
?>
<form method='POST' action='question.php'> //won't submit because action is question.php?
<p>Question:</p>
<p><input type='text' name='question' id='question' maxlength='200'></p>
<p>Add some detail (optional):</p>
<p><textarea id='detail' name='detail' ></textarea></p>
<p><input type='submit' value='submit' name='submit'></p>
</form>
</div>
<?php include '../footer.php'; ?>
</body>
您可以張貼到任何現有的頁面,但如果該頁面不處理貼值,什麼都不會從其他頁面的加載除了發生。 – jeroen 2011-12-28 01:21:35
@jeroen我不介意question.php是否處理數據,但如果我將'ask.php'更改爲'question.php',它甚至不會被提交到數據庫中。如果數據被提交,爲什麼表單的操作很重要?在重定向之前不應該將它輸入到數據庫中嗎?如果我可以錯誤地發佈解決方案? – kirby 2011-12-28 01:40:50
@ jeroen是在數據插入數據庫之前頁面正在被重定向的問題? – kirby 2011-12-28 01:45:38