douweng3383 2014-09-04 13:17
浏览 42
已采纳

每当我将变量回显或写入文本文件时,它都会向webapge或文本文件输出“1”。

This is my code, as you can see the input being passed to the variables is what i want it to be. Please help im now just filling the space because it is required for me to ask the question, im currently re-installing xammp hopeing that it solves the problem but if it is a code issue, any help most appreciated.

<?php
$Name = isset($_POST['name']);
$Car  = isset($_POST['car']);
$Night = isset($_POST['yes']);
$Siteid = isset($_POST['siteid']);
$Date = isset($_POST['datepicker']);


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

        "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <title>Engineers Work </title>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

  <script type="text/javascript" src="jquery.timepicker.js"></script>
  <link rel="stylesheet" type="text/css" href="jquery.timepicker.css" />

  <script type="text/javascript" src="lib/bootstrap-datepicker.js"></script>
  <link rel="stylesheet" type="text/css" href="lib/bootstrap-datepicker.css" />

  <script type="text/javascript" src="lib/site.js"></script>
  <link rel="stylesheet" type="text/css" href="lib/site.css" />

</head>
<body>
<div id="center">
<br><br><br>
<!-- Allows User to who they are -->
<p>You are: </p><form action="" method="post">
<select name="name" id="name">
<option value="Noname"> </option>
<option value="Tom">Option 1</option>
<option value="Ben">Option 2</option>
<option value="Aaron">Option 3</option>
<option value="Sally">Option 4</option>
<option value="Paul">Option 5</option>
</select><br/><br/>

<!-- Allows User to pick the Vehicle -->
<p>You drive </p>
<select name="car" id="car">
<option value=""> </option>
<option value="Truck 1">Option 1</option>
<option value="Truck 2">Option 2</option>
<option value="Truck 3">Option 3</option>
<option value="Truck 4">Option 4</option>
<option value="Truck 5">Option 5</option>
</select><br/><br/>



<!-- Allows the user to say if they stayed overnight -->
<input type="checkbox" name="yes" value="yes">I Stayed Over night<br><br/>



                <p id="datepairExample">
                    <input type="text" class="date start" id="datepicker" name="datepicker" value="" />


                </p>


            <script src="http://jonthornton.github.io/Datepair.js/dist/datepair.js"></script>
            <script src="http://jonthornton.github.io/Datepair.js/dist/jquery.datepair.js"></script>
            <script>
                $('#datepairExample .time').timepicker({
                    'showDuration': true,
                    'timeFormat': 'g:ia'
                });

                $('#datepairExample .date').datepicker({
                    'format': 'm/d/yyyy',
                    'autoclose': true
                });

                $('#datepairExample').datepair();
            </script>
<br>
<br>


<!-- Allows User to pick site id -->

<p>Site Id: </p> <input type="text" id="siteid" name="siteid"><br/>
<br/><br/>

<!-- Allows User to pick the date -->

     <p>Left Hastings At: <input id="stepExample1" type="text" class="time" /> <br><br> Arived At first site at: <input id="stepExample2" type="text" class="time" /> <br><br> Left Site at: <input id="stepExample3" type="text" class="time" /></p>


            <script>
                $(function() {
                    $('#stepExample1').timepicker({ 'step': 15 });
                    $('#stepExample2').timepicker({ 'step': 60 });

                });
            </script>

<input name="submit" type="submit" value="submit" />

</form>
<?php
echo  $Name ."<br/>";
echo "". $Car ."<br/>";
echo "". $Night ."<br/>";
echo "". $Date ."<br/>";
echo "". $Siteid ."<br/>";
print_r($_POST);

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = $Name;
fwrite($myfile, $txt);
$txt = "Jane Doe
";
fwrite($myfile, $txt);
fclose($myfile);


?>

</div>



</body>
</html>
  • 写回答

2条回答 默认 最新

  • douxiong3245 2014-09-04 13:19
    关注

    isset() returns boolean and you are assigning the value of isset() function to your parameters, so when you try to echo a boolean you see "1". Try this code:

    $Name = isset($_POST['name']) ? trim($_POST['name']) :'';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题