简体   繁体   English

PHP $ _SESSION可以在WAMP上运行,但不能在服务器上使用完全相同的代码,为什么?

[英]PHP $_SESSION works on WAMP but not on my Server with exact same code, why?

I have an HTML form that is Posting data to the following code. 我有一个HTML表单,该表单将数据发布到以下代码中。 It receives the data properly using $_SESSION when I use WAMP server. 当我使用WAMP服务器时,它将使用$_SESSION正确接收数据。 However, when I upload it to my sever, the $_SESSION is not receiving the data from the HTML form. 但是,当我将其上传到服务器时, $_SESSION不会从HTML表单接收数据。 Do I need to add something to the $_SESSION while its on the live sever, that is not needed on WAMP? 我需要在$_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();

?>

I am not sure if I can do this, but the form starts at http://landlordin.com/ll_login.php , and then has the following code 我不确定是否可以执行此操作,但是该表单始于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");
?>

I found out the problem. 我发现了问题。

I was using the same $username and $password variables to connect to the server that I was using in the form, so they conflicted with each other and caused an error on the server. 我使用相同的$username$password变量连接到表单中正在使用的服务器,因此它们彼此冲突并在服务器上引起错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的 php 代码在 wamp 服务器上不起作用 - why my php code does'nt work on wamp server 为什么php每次都在测试环境(WAMP)中生成相同的会话id? - why is php generating the same session ids everytime in test environment (WAMP)? curl php相同的代码在ubuntu上工作正常但在wamp windows 8上没有 - curl php same code works fine on ubuntu but not on wamp windows 8 使用WAMP Server的PHP会话 - PHP Session using WAMP Server 会话在Wamp上不起作用,但在实时服务器上起作用 - Session not working on wamp but works on live server 我的SQL代码似乎没有连接到我的服务器。 它曾经做到过,并且可以在我的Wamp服务器上使用 - My SQL code doesn't seem to be connecting to my server. It used to do it and it works on my Wamp server 为什么 PHP 脚本中没有执行 curl 代码? (WAMP 服务器) - Why is the curl code not executed in PHP script? (WAMP Server) 脚本可以在Wamp服务器上运行,但不能在我的VPS上运行 - script works on wamp server but not on my vps 为什么相同的PHP UnityWebRequest在plesk服务器上不起作用,但在我的本地主机上起作用? - Why does the same php UnityWebRequest does not work on plesk server but works on my localhost? Wamp Server:拒绝执行PHP代码 - Wamp Server: Refuses to execute PHP code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM