我有一个HTML表单,将数据发布到以下代码。当我使用WAMP服务器时,它使用$_SESSION
正确接收数据。但是,当我将其上传到我的服务器时,$_SESSION
没有从HTML表单接收数据。我是否需要在活动服务器上向$_SESSION
添加一些内容,这在WAMP上是不需要的?
<?php
session_start();
$servername = "landlordincom.ipagemysql.com";
$username = "tyrone";
$password = "blabla";
$dbname = "commission";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}else{
echo "Connected";
}
//HTML Form Data For SESSION
$username=$_SESSION['username'];
$password=$_SESSION['password'];
$fname=$_SESSION['fname'];
$lname=$_SESSION['lname'];
$dob=$_SESSION['dob'];
$cname=$_SESSION['cname'];
$taxid=$_SESSION['taxid'];
$country=$_SESSION['country'];
$address=$_SESSION['address'];
$city=$_SESSION['city'];
$state=$_SESSION['state'];
$zip=$_SESSION['zip'];
$primemail=$_SESSION['primemail'];
$altemail=$_SESSION['altemail'];
$cellnum=$_SESSION['cellnum'];
$homenum=$_SESSION['homenum'];
$busnum=$_SESSION['busnum'];
$faxnum=$_SESSION['faxnum'];
$sql5 = "INSERT INTO accounts (username,password,fname,lname,dob,cname,taxid,country,address,city,state,zip,primemail,altemail,cellnum,homenum,busnum,faxnum)VALUES('$username', '$password', '$fname','$lname','$dob','$cname','$taxid','$country','$address','$city','$state','$zip','$primemail','$altemail','$cellnum','$homenum','$busnum','$faxnum')";
$query2=mysqli_query($conn,$sql5)or die ("No Query2");
echo "Data INSERTED";
}else{
echo"not set";
}
$added=0;
foreach($_POST["property"] as $req)
{
$reqName = isset($req['name']) ? $req['name'] : '';
$reqType = isset($req['type']) ? $req['type'] : '';
$reqAddress = isset($req['address']) ? $req['address'] : '';
$reqSubType = isset($req['subtype']) ? $req['subtype'] : '';
$reqCity = isset($req['city']) ? $req['city'] : '';
$reqUnitNum = isset($req['unit_num']) ? $req['unit_num'] : '';
$reqState = isset($req['state']) ? $req['state'] : '';
$reqLandlord = isset($req['landlord']) ? $req['landlord'] : '';
$reqZip = isset($req['zip']) ? $req['zip'] : '';
$reqCountry = isset($req['country']) ? $req['country'] : '';
$reqBank = isset($req['bank']) ? $req['bank'] : '';
$reqReserves = isset($req['reserves']) ? $req['reserves'] : '';
$sql = "INSERT INTO properties (name,type,address,subtype,city,unit_num,state,landlord,zip,country,bank,reserves)
VALUES ('".$reqName."', '".$reqType."', '".$reqAddress."', '".$reqSubType."', '".$reqCity."', '".$reqUnitNum."', '".$reqState."', '".$reqLandlord."', '".$reqZip."', '".$reqCountry."', '".$reqBank."', '".$reqReserves."')";
$query3=mysqli_query($conn,$sql)or die ("No Query");
if (isset($query3)) {
$added++;
} else {
echo "Error: " . $sql . "<br>" . mysql_error($conn);
}
}
foreach($_POST["unit"] as $uni){
// Unit data
$uniName = isset($uni['unit_name']) ? $uni['unit_name'] : '';
$uniSize = isset($uni['unit_size']) ? $uni['unit_size'] : '';
$uniRent = isset($uni['unit_rent']) ? $uni['unit_rent'] : '';
$uniComment = isset($uni['unit_comment']) ? $uni['unit_comment'] : '';
$sql2 = "INSERT INTO unit (unit_name,unit_size,unit_rent,unit_comment)
VALUES ('".$uniName."', '".$uniSize."', '".$uniRent."', '".$uniComment."')";
$query4=mysqli_query($conn,$sql2)or die ("No Query");
if (isset($query4)) {
$added++;
} else {
echo "Error: " . $sql2 . "<br>" . mysql_error($conn);
}
}
echo "<br>".$added." "."Files added";
// Finally close mysql connection
$conn->close();
?>
我不确定我是否可以这样做,但表单从http://landlordin.com/ll_login.php
开始,然后有以下代码
<?php
session_start();
if(isset($_REQUEST['primemail'])){
$_SESSION['primemail']=$_REQUEST['primemail'];
}else{
$_REQUEST['primemail']=$_SESSION['primemail'];
}
if(isset($_REQUEST['altemail'])){
$_SESSION['altemail']=$_REQUEST['altemail'];
}else{
$_REQUEST['altemail']=$_SESSION['altemail'];
}
if(isset($_REQUEST['cellnum'])){
$_SESSION['cellnum']=$_REQUEST['cellnum'];
}else{
$_REQUEST['cellnum']=$_SESSION['cellnum'];
}
if(isset($_REQUEST['homenum'])){
$_SESSION['homenum']=$_REQUEST['homenum'];
}else{
$_REQUEST['homenum']=$_SESSION['homenum'];
}
if(isset($_REQUEST['busnum'])){
$_SESSION['busnum']=$_REQUEST['busnum'];
}else{
$_REQUEST['busnum']=$_SESSION['busnum'];
}
if(isset($_REQUEST['faxnum'])){
$_SESSION['faxnum']=$_REQUEST['faxnum'];
}else{
$_REQUEST['faxnum']=$_SESSION['faxnum'];
}
$text="
<div class='contWrapper'>
<form action='ty.php' method='post'>
<div class='rightSide'>
<div class='topRight'>
<span id='unit'></span>
</div>
<div class='bottomRight'>
<button type='button' onclick='newUnit()' style='margin-right:.5px;'>Add Unit</button>
<input type='submit' value='Submit' style='float:right;'/>
</div>
</div>
<div class='leftSide'>
<div class='topLeft'>
<span id='box'></span>
</div>
<div class='bottomLeft'>
<button type='button' onclick='newInput()' style='margin-right:.5px;'>Add Property</button>
</div>
</div>
</form>
</div>
";
$banner="
<div class='content2'>
<div class='properties'>$text</div>
</div>
";
include("template.php");
?>
答案 0 :(得分:0)
我发现了问题。
我使用相同的$username
和$password
变量连接到我在表单中使用的服务器,因此它们相互冲突并在服务器上导致错误。