无法使用session和INSERT QUERY在MYSQL中插入数据

时间:2014-01-27 13:39:58

标签: php mysql

我有两个表单user_details.php和proposal_details.php。我有两个表:各个表单的users和proposal_details。

用户表:

user_id: INT PRIMARY KEY AUTO_INCREMENT

name: varchar(50)

website: varchar(50)...etc..

proposal_details table:

proposal_id: INT PRIMARY KEY AUTO_INCREMENT

user_id: INT FOREIGN KEY...REFERENCE FROM user_details(user_id)...etc

我已按以下方式将user_id存储在会话变量中:

user_details.php

session_start();
$run = "SELECT user_id FROM Users WHERE user_id = '$_POST[user_id]'";
$result1 = mysqli_query($con,$run);
$row1= mysqli_fetch_array($result1);
$_SESSION['use_id']= $row1['user_id'];
header("location:proposal_details.php");
exit;

我试图通过以下方式将数据插入到proposal_details表中:

proposal_details.php

<?php
$proposal= $_POST['proposal'];
$proposal_type= $_POST['proposal_type'];
$proposal_template= $_POST['proposal_template'];
$deadline= $_POST['deadline'];
$currency= $_POST['currency'];
$client_name= $_POST['client_name'];
$client_email= $_POST['client_email'];
$comp_name= $_POST['comp_name'];
$website= $_POST['website'];
$txt= $_POST['txt'];
$Country= $_POST['Country'];
$state= $_POST['state'];
$city= $_POST['city'];
$zip= $_POST['zip'];

/*echo $proposal."<br>";
echo $proposal_type."<br>";
echo $proposal_template."<br>";
echo $deadline."<br>";
echo $currency."<br>";
echo $client_name."<br>";
echo $client_email."<br>";
echo $comp_name."<br>";
echo $website."<br>";
echo $txt."<br>";
echo $Country."<br>";
echo $state."<br>";
echo $city."<br>";
echo $zip."<br>";*/



if(!isset($_SESSION)){
    session_start();
}

$user_id = $_SESSION['use_id'];
    $con=mysqli_connect("localhost","root","","my_db"); 
    $sql = "INSERT INTO `proposal_details`(`user_id`, `proposal_name`, `proposal_type`, `proposal_template`, `deadline`, `currency`, `client_name`, `email`, `client_company`, `file_upload`, `website`, `address`, `country`, `state`, `city`, `zipcode`) VALUES

(`$user_id`,`$proposal`,`$proposal_type`,`$proposal_template`,`$deadline`,`$currency`,`$client_name`,`$client_email`,`$comp_name`,`$filePath`,`$website`,`$txt`,`$Country`,`$state`,`$city`,`$zip`)";
    mysqli_query($con,$sql);


}


/* if(isset($_POST['submit1']))
{
validatedata();
insert_data();
//header("location:sections.php");
//exit;
} */
?>


 <h1>WELCOME <?php if(!isset($_SESSION)){session_start();} echo $_SESSION['username']."!"; ?> </h1> 

当我回显值时,将打印值。但是INSERT查询没有在proposal_details.php中执行

我缺少任何想法。因为我现在被困了1个小时。

1 个答案:

答案 0 :(得分:2)

更改此

$sql = "INSERT INTO `proposal_details`(`user_id`, `proposal_name`, `proposal_type`, `proposal_template`, `deadline`, `currency`, `client_name`, `email`, `client_company`, `file_upload`, `website`, `address`, `country`, `state`, `city`, `zipcode`) VALUES

(`$user_id`,`$proposal`,`$proposal_type`,`$proposal_template`,`$deadline`,`$currency`,`$client_name`,`$client_email`,`$comp_name`,`$filePath`,`$website`,`$txt`,`$Country`,`$state`,`$city`,`$zip`)";

$sql = "INSERT INTO `proposal_details`(`user_id`, `proposal_name`, `proposal_type`, `proposal_template`, `deadline`, `currency`, `client_name`, `email`, `client_company`, `file_upload`, `website`, `address`, `country`, `state`, `city`, `zipcode`) VALUES

('$user_id','$proposal','$proposal_type','$proposal_template','$deadline','$currency','$client_name','$client_email','$comp_name','$filePath','$website','$txt','$Country','$state','$city','$zip')";

你有``for values should be''