会话和mysql的问题

时间:2014-03-03 21:39:43

标签: php mysql database

我正在为客户端创建一个站点,我收到一条错误消息“未定义的索引”。我正在尝试将数据从3个多表单页面上传到数据库,它们由cv.php处理。

表单详细信息存储在第2页

<?php 
session_start();
if(isset($_SESSION['FirstName'])){
$_SESSION['FirstName'] = $_POST['FirstName'];}
if(isset($_SESSION['LastName'])){
$_SESSION['LastName'] = $_POST['LastName'];}
if(isset($_SESSION['dob'])){
$_SESSION['dob'] = $_POST['dob'];}
if(isset($_SESSION['Age'])){
$_SESSION['Age'] = $_POST['Age'];}
if(isset($_SESSION['AddressLine1'])){
$_SESSION['AddressLine1'] = $_POST['AddressLine1'];}
if(isset($_SESSION['AddressLine2'])){
$_SESSION['AddressLine2'] = $_POST['AddressLine2'];}
if(isset($_SESSION['City'])){
$_SESSION['City'] = $_POST['City'];}
if(isset($_SESSION['County'])){
$_SESSION['County'] = $_POST['County'];}
if(isset($_SESSION['PostCode'])){
$_SESSION['PostCode'] = $_POST['PostCode'];}
if(isset($_SESSION['Country'])){
$_SESSION['Country'] = $_POST['Country'];}
if(isset($_SESSION['Telephone'])){
$_SESSION['Telephone'] = $_POST['Telephone'];}
if(isset($_SESSION['Mobile'])){
$_SESSION['Mobile'] = $_POST['Mobile'];}
if(isset($_SESSION['Email'])){
$_SESSION['Email'] = $_POST['Email'];}
?>

第3页

<?php 
session_start(); 
if(isset($_SESSION['Skills'])) {
$_SESSION['Skills'] = $_POST['Skills'];}
if(isset($_SESSION['ReasonApp'])){
$_SESSION['ReasonApp'] = $_POST['ReasonApp'];}
if(isset($_SESSION['WorkName'])){
$_SESSION['WorkName'] = $_POST['WorkName'];}
if(isset($_SESSION['WorkDesc'])){
$_SESSION['WorkDesc'] = $_POST['WorkDesc'];}
if(isset($_SESSION['W_AddressLine1'])){
$_SESSION['W_AddressLine1'] = $_POST['W_AddressLine1'];}
if(isset($_SESSION['W_AddressLine2'])){
$_SESSION['W_AddressLine2'] = $_POST['W_AddressLine2'];}
if(isset($_SESSION['W_City'])){
$_SESSION['W_City'] = $_POST['W_City'];}
if(isset($_SESSION['W_Telephone'])){
$_SESSION['W_Telephone'] = $_POST['W_Telephone'];}
?>

我的CV.php

<?
session_start();

ini_set('display_errors',1); 
 error_reporting(E_ALL);
//include connection profile
require_once("Sql/con.php");
include("config.php");

//declare variables with sessions
$FirstName = $_SESSION['FirstName'];
$LastName = $_SESSION['LastName'];
$dob = $_SESSION['dob'];
$Age = $_SESSION['Age'];
$AddressLine1 = $_SESSION['AddressLine1'];
$AddressLine2 = $_SESSION['AddressLine2'];
$PostCode = $_SESSION['PostCode'];
$City = $_SESSION['City'];
$County = $_SESSION['County'];
$Country = $_SESSION['Country'];
$Mobile = $_SESSION['Mobile'];
$Telephone = $_SESSION['Telephone'];
$Email = $_SESSION['Email'];
$Skills = $_SESSION['Skills'];
$ReasonApp = $_SESSION['ReasonApp'];
$SchoolName = $_SESSION['SchoolName'];
$Course = $_SESSION['Course'];
$Certificate = $_SESSION['Certificate'];
$DateFrom = $_SESSION['DateFrom'];
$DateTo = $_SESSION['DateTo'];
$CollName = $_SESSION['CollName'];
$CollQualification = $_SESSION['CollQualification'];
$CollYear = $_SESSION['CollYear'];
$WorkName = $_SESSION['WorkName'];
$WorkDesc = $_SESSION['WorkDesc'];
$W_AddressLine1 = $_SESSION['W_AddressLine1'];
$W_AddressLine2 = $_SESSION['W_AddressLine2'];
$W_PostCode = $_SESSION['PostCode'];
$W_City = $_SESSION['City'];
$W_Telephone = $_SESSION['Telephone'];




//database connection
$dblink = mysqli_connect($mysql_host,$mysql_user,$mysql_pw,$mysql_db) OR DIE ("Unable to 
            connect to database! Please try again later.");


//inserting information into tables 
$order = "INSERT INTO CV_personal

            (FirstName,LastName,dob,Age,AddressLine1,AddressLine2,PostCode,City,County,Country,Mobile,Telephone,Email,Skills,ReasonApp,SchoolName,Course,Certificate,DateFrom,DateTo,CollName,CollQualification,CollYear,WorkName,WorkDesc,W_AddressLine1,W_AddressLine2,W_City,W_Telephone)

            VALUES

            ('$FirstName',
            '$LastName',
            '$dob',
            '$Age',
            '$AddressLine1',
            '$AddressLine2',
            '$PostCode',
            '$City',
            '$County',
            '$Country',
            '$Mobile',
            '$Telephone',
            '$Email',
            '$Skills',
            '$ReasonApp',
            '$SchoolName',
            '$Course',
            '$Certificate',
            '$DateFrom',
            '$DateTo',
            '$CollName',
            '$$CollQualification',
            '$ColYear',
            '$WorkName',
            '$WorkDesc',
            '$W_AddressLine1',
            '$W_AddressLine2',
            '$W_PostCode',
            '$W_City',
            '$W_Telephone',)";

//declare in the order variable

$result = mysqli_query($dblink, $order);  //order executes
?>

在我的最后一页上,我需要将表单放入会话中,因为我在Cv.php上为它们声明了一个变量吗?

谢谢

1 个答案:

答案 0 :(得分:4)

在前两个代码块中,您应该检查$_POST[...]是否已设置,而不是$_SESSION[...],因为它是您要分配的内容,因此不会导致错误。< / p>

在CV.php上,您应该在将$_SESSION[...]分配给变量之前检查$_SESSION是否存在,否则会导致错误。

提示 如果您要将变量命名为extract($_SESSION); 数组中所有键的名称。您只需用这一行代替许多行:

{{1}}

有关提取的更多内容:http://www.php.net/extract