我試圖在多個步驟中創建一個表格。我想要做的是在第一頁中,用戶將輸入兩個字段,即標題和描述,這些字段將被保存在數據庫中,然後他們被重定向到第二頁,在那裏他們需要更多的細節,但在這裏我想說這些值應添加在具有前一頁中保存的標題值的行的前面。在php中創建一個多步表格
這是我迄今所做
<?php
include('creator_session.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
//necessary data
</head>
<body>
<form class="form-horizontal" role="form" action="insert_page_one.php" enctype="multipart/form-data" method="post">
<div class="row">
<div class="col-md-4 col-md-offset-4"><input class="form-control" value="Project Name" type="text" name="title"></div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4"><input class="form-control" value="Project Name" type="text" name="title"></div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4"><input class="btn btn-primary" value="Get Started" type="submit" name="submit"></div>
</div>
</form>
<body>
</html>
insert_page_one.php
<?php
include('creator_session.php');
$con=mysqli_connect("xyz.com","xyz","xyz","xyz");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$title = mysqli_real_escape_string($con, $_POST['title']);
$category = mysqli_real_escape_string($con, $_POST['category']);
$sql="INSERT INTO creatorproject(title,category) VALUES ('$title','$category')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
header("Location: page_two.php");
mysqli_close($con);
?>
page_two.php
<?php
include('creator_session.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
//necessary data
</head>
<body>
<form class="form-horizontal" role="form" action="creator_page_two.php" enctype="multipart/form-data" method="post">
<div class="form-group">
<label class="col-md-3 control-label">Description</label>
<div class="col-md-8">
<input class="form-control" name="description" value="" type="">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Project Location:</label>
<div class="col-md-8">
<input class="form-control" name="projectlocation" value="" type="">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Funding Goal:</label>
<div class="col-md-8">
<input class="form-control" name="funding" value="" type="">
</div>
</div>
<div class="submit">
<input type="submit" value="SAVE">
</div>
</form>
</body>
</html>
creator_page_two.php
<?php
include('creator_session.php');
$con=mysqli_connect("xyz","xyz","xyz","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$description = mysqli_real_escape_string($con, $_POST['description']);
$projectlocation = mysqli_real_escape_string($con, $_POST['projectlocation']);
$funding = mysqli_real_escape_string($con, $_POST['funding']);
$sql = "UPDATE creatorproject SET description='".$description."', projectlocation='".$projectlocation."', funding='".$funding."' WHERE title ='".$title."'";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
header("Location: creator_add_project.php");
exit;
mysqli_close($con);
?>
當我運行這個代碼時,它並沒有從第二頁插入值..希望能得到一些幫助,並會很感激,如果有人可以解釋程序,因爲我是這個領域的新手,並希望瞭解它。
存儲用戶作爲用戶的登錄信息PS-我也用creator_session有登錄,因此整個登錄過程中已與會話
我將包括一個隱藏字段「兩頁'表單,其中包括以第一種形式創建的「項目詳情」的數據庫ID。這將使您能夠檢索項目信息並使其成爲'第二頁'上的顯示字段。 – 2014-10-07 12:15:36
@Ryan Vincent你可以告訴我怎麼做 – jane 2014-10-07 15:52:03