2015-02-05 55 views
0

在我的代碼中,我試圖從一個php獲取變量的值。在這個PHP文件中,我通過url從其他一些PHP文件中獲取值。如果語句使用GET,PHP沒有獲取值

我得到了其他部分裏面所有的值,但內部沒有如果,變量MEETING_ID和pemail不存儲任何東西在數據庫中的所有其他領域的完美存儲的值。我錯在哪裏?

<?php 
if (isset($_POST['send'])) { 

    $pemail = $_POST['e']; 
    $meeting_id = $_POST['mid']; 
    $date = $_POST["dat"]; 
    if ($date=="val1") { 
     $d1 = 'Yes'; 
    } 
    else { 
     $d1='No'; 
    } 
    if ($date=="val2") { 
     $d2 = 'Yes'; 
    } 
    else { 
     $d2='No'; 
    } 
    $location = $_POST["location"]; 
    if ($location=="val1") { 
     $l1 = 'Yes'; 
    } 
    else { 
     $l1='No'; 
    } 
    if ($location=="val2") { 
     $l2 = 'Yes'; 
    } 
    else { 
     $l2='No'; 
    } 
    $check_list1 = $_POST['check_list1']; 
    if ($check_list1 != 'yes') { 
     $check_list1 = 'No'; 
    } 
    $check_list2 = $_POST['check_list2']; 
    if ($check_list2 != 'yes') { 
     $check_list2 = 'No'; 
    } 
    $host='mysql5.000webhost.com'; 
    $uname='admin'; 
    $pwd='*****'; 

    $db="meeting"; 
    $con = mysql_connect($host,$uname,$pwd) or die("connection failed"); 
    mysql_select_db($db,$con) or die("db selection failed"); 
    $flag['code']=0; 
    if($r=mysql_query("insert into meeting.response (meeting_id, Email, 
    DAT1, DAT2, Location1, Location2, Travel, Hotel) 
    values('$meeting_id','$pemail','$d1','$d2','$l1','$l2','$check_list1', 
    '$check_list2') ",$con)) 

     { 

      $flag['code']=1; 
      echo"hi"; 
     } 
    print(json_encode($flag)); 
    mysql_close($con); 

    ?> 
    Your response was sent 
     <?php 
     } else { 
    $top=$_GET['t']; 
    $dat1=$_GET['d1']; 
    $tim1=$_GET['t1']; 
    $dat2=$_GET['d2']; 
    $tim2=$_GET['t2']; 
    $loc1=$_GET['l1']; 
    $loc2=$_GET['l2']; 
    $mid=$_GET['id']; 
    $e=$_GET['pemail']; 
    ?> 
    <h1><center>Meeting Invitation</center></h1> 
    <form action="my.php" method="post"> 
    You are invited for the meeting on <?php echo $top; ?> 
    proposed dates are :<br><br> 
    Date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time<br> 
    <?php echo $dat1; ?> &nbsp; &nbsp; &nbsp; <?php echo $tim1; ?><input 
    type = "radio" name = "dat" <?php if (isset($dat) && $dat=="val1") echo 
                      "checked";?> value = "val1" checked="true" ><br> 
    <?php echo $dat2; ?> &nbsp; &nbsp; &nbsp; <?php echo $tim2; ?><input 
    type = "radio" name = "dat" <?php if (isset($dat) && $dat=="val2") echo 
                      "checked";?> value = "val2" ><br><br> 
    Proposed locations are :<br> 
    Location 1 : &nbsp; &nbsp; &nbsp; <?php echo $loc1; ?> <input type = 
                   "radio" name = "location" <?php if (isset($location) && 
                            $location=="val1") echo 
                                  "checked";?> value = "val1" checked="true" ><br> 
    Location 2 : &nbsp; &nbsp; &nbsp; <?php echo $loc2; ?> <input type = 
                   "radio" name = "location" <?php if (isset($location) && $location=="val2")   
                   echo 
                    "checked";?> value = "val2" ><br><br> 
    Do you want travel facility ? &nbsp; &nbsp; &nbsp; 
    <input type="checkbox" name="check_list1" value="yes"> <br><br> 
    Do you want hotel facility ? &nbsp; &nbsp; &nbsp; 
    <input type="checkbox" name="check_list2" value="yes"> <br><br><br> 
    <input type="submit" name="send" value="Send Response"> 
    <input type="reset" > 
    </form> 

    <?php 
}; 
?> 
+0

當你使用'GET',該參數是'$ _GET',但你使用'$ _POST ['mid']'。 – Barmar 2015-02-05 17:44:04

+0

如果您希望能夠通過GET或POST獲取參數,您可以使用'$ _REQUEST' - 它將它們結合起來。 – Barmar 2015-02-05 17:44:52

+0

我沒有看到你添加的輸入E,中期,到窗體... – satchcoder 2015-02-05 17:47:50

回答

0

你說你通過url發送了你的值,而不是通過post操作。所以$ _POST是空的,使用$ _GET作爲url值。 通過顯示如print_r($ _GET)和print_r($ _POST)的值來檢查您發送的內容。

1

您使用POST傳遞變量而不是GET。爲了獎金,我清理了可讀性的代碼。

在你的代碼更改此:

Your response was sent 
<?php 
} else { 
$top=$_GET['t']; 
$dat1=$_GET['d1']; 
$tim1=$_GET['t1']; 
$dat2=$_GET['d2']; 
$tim2=$_GET['t2']; 
$loc1=$_GET['l1']; 
$loc2=$_GET['l2']; 
$mid=$_GET['id']; 
$e=$_GET['pemail']; 
?> 

這樣:

Your response was sent 
<?php 
} else { 
$top=$_POST['t'].'<br>'; 
$dat1=$_POST['d1'].'<br>'; 
$tim1=$_POST['t1'].'<br>'; 
$dat2=$_POST['d2'].'<br>'; 
$tim2=$_POST['t2'].'<br>'; 
$loc1=$_POST['l1'].'<br>'; 
$loc2=$_POST['l2'].'<br>'; 
$mid=$_POST['id'].'<br>'; 
$e=$_POST['pemail']; 
?> 
+0

我已經改變了我的代碼根據你的,但它仍然不工作 – 654 2015-02-06 10:16:03