我正在创建一个用户需要创建帐户的网站。登录后,他们可以添加一个项目。为此,我将项目的细节分为3页,用户需要填写详细信息。这里是前两页的想法,其中"save and continue"
将是按钮
第一页看起来像这样
project by:
email:
project title:
goal
Save and continue
第二页看起来像这样
tagline:
category:
details:
Save and continue
数据库看起来像这样(表的名称是createproject)
id projectby email projecttitle goal tagline category details
1 name1 email1 title1 goal1
我用于第一页的PHP编码是
<?php
include('creator_session.php');
$con=mysqli_connect("asd","asd","asd","asd");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$projectby = mysqli_real_escape_string($con, $_POST['projectby']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$projecttitle = mysqli_real_escape_string($con, $_POST['projecttitle']);
$goal = mysqli_real_escape_string($con, $_POST['goal']);
$sql="INSERT INTO creatorproject (projectby,email,projecttitle,goal) VALUES ('$projectby', '$email','$projecttitle', '$goal')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
header("Location: add_creator_project_basic.php");
exit;
mysqli_close($con);
?>
我用于第二页的PHP编码是
<?php
include('creator_session.php');
$con=mysqli_connect("asd","asd","asd","asd");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$tagline = mysqli_real_escape_string($con, $_POST['tagline']);
$category = mysqli_real_escape_string($con, $_POST['category']);
$details = mysqli_real_escape_string($con, $_POST['details']);
$sql = "UPDATE creatorproject SET tagline='".$tagline."',category='".$category."',details='".$details."' WHERE id='".$id."'";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
header("Location: add_creator_project.php");
exit;
mysqli_close($con);
?>
基本上我想要保存在第二页上的数据应保存在保存第一页数据的同一行中,为此我使用了更新查询,因为id是唯一的,所以我放了它的条件。虽然没有显示错误,但该条目未保存在数据库中。也许我没有以正确的方式推进身份证明。任何人都可以告诉我如何保存数据
答案 0 :(得分:1)
将会话参数中第1页的插入行中的ID或第2页上的URL参数保存。 您可以通过执行以下操作从插入的行中获取ID:
$id = mysql_insert_id();
然后在将用户发送到第2页时设置类似?project_id='ID'
的参数,或者使用以下内容设置会话
session_start();
$_SESSION['project_id'] = $id;
现在,您可以将页面上的SQL查询更新为$_GET['project_id']
或$_SESSION['project_id']
,如下所示:
$sql = "UPDATE creatorproject SET tagline='".$tagline."',category='".$category."',details='".$details."' WHERE id='".$_SESSION['id']."'";