我有一个简单的问题,
我有一个登录和工作区。
用户登录后它显示工作场所登录用户的用户名,正如我想要的那样。现在我的问题是当用户完成填写工作区中可用的表格时,表格然后存储在数据库中,我还需要来自会话的用户名也存储到数据库中。
这是在登录后用户到达工作区后存储用户名和维护会话的代码:
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/MainProject/connect/auth.php');
session_start();
?>
更新插入文件的最终版本:
//This code is included to check session and store username
<?php
require_once('..\connect\auth.php');
// session_start();
$usern = $_SESSION['SESS_FIRST_NAME'];
?>
<?php
mysql_connect('localhost','root','');
mysql_select_db('main_project') or die (mysql_error());
if(isset($_POST['WID'])){
for ($ix=0; $ix<count($_POST['WID']); $ix++)
{
$WID = mysql_real_escape_string(@$_POST['WID'][$ix]);
$website = mysql_real_escape_string(@$_POST['website'][$ix]);
//var_dump("<pre>", $_POST['cat']); die(); // Debugger for checking cat counter.
// $cat = implode(",", mysql_real_escape_string($_POST['cat'][$ix]));
if(is_array(@$_POST['cat'][$ix]))
$cat = mysql_real_escape_string(implode(',', @$_POST['cat'][$ix]));
else
$cat = mysql_real_escape_string(@$_POST['cat'][$ix]);
$email = mysql_real_escape_string(@$_POST['email'][$ix]);
$cform = mysql_real_escape_string(@$_POST['cform'][$ix]);
$contactp = mysql_real_escape_string(@$_POST['contactp'][$ix]);
$contacts = mysql_real_escape_string(@$_POST['contacts'][$ix]);
$fax = mysql_real_escape_string(@$_POST['fax'][$ix]);
$Ctype = mysql_real_escape_string(@$_POST['Ctype'][$ix]);
$usern = mysql_real_escape_string(@$_POST['usern'][$ix]);
$sql_res = mysql_query("INSERT INTO website_01data (WID,website,cat,email,cform,contactp,contacts,fax,Ctype,TimeStamp,usern)
VALUES ('".$WID."', '".$website."', '".$cat."', '".$email."','".$cform."', '".$contactp."', '".$contacts."', '".$fax."', '".$Ctype."', Now(), '".$usern."' )");
$sql_res = mysql_error();
}//end for..
echo "<p><span style=\"color: red;\">Thank You; your records are sent to database. DO NOT REFRESH THE PAGE or data will be sent again.</span></p>";
}
?>