在我的代码中,我试图从一个php获取变量的值到另一个。在这个php文件中,我通过url从其他一些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
Time<br>
<?php echo $dat1; ?> <?php echo $tim1; ?><input
type = "radio" name = "dat" <?php if (isset($dat) && $dat=="val1") echo
"checked";?> value = "val1" checked="true" ><br>
<?php echo $dat2; ?> <?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 : <?php echo $loc1; ?> <input type =
"radio" name = "location" <?php if (isset($location) &&
$location=="val1") echo
"checked";?> value = "val1" checked="true" ><br>
Location 2 : <?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 ?
<input type="checkbox" name="check_list1" value="yes"> <br><br>
Do you want hotel facility ?
<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 :(得分: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'];
?>
答案 1 :(得分:0)
您说您是通过网址发送的,而不是通过帖子操作发送的。所以$ _POST为空,使用$ _GET作为url值。 通过显示以下值来检查发送的内容:print_r($ _ GET)和print_r($ _ POST)。