duanpacan9388 2013-09-17 15:10
浏览 46

表单提交后没有显示任何内容(PHP)

I have been trying to secure my web page for a while now by preventing sql injection. However, now nothing is being displayed on the page at all after I submit my form. Here is my complete code because I don't know where my error is occurring.

   <?php
   require_once 'db_connect.php';
   ?>
   <head> 
   <title> Data </title>
   <link href = "ss2.css" type = "text/css" rel = "stylesheet" >
   </head>
  <body>
  <h1> Research Center </h1>
  <a href = "home.php"> Data Home Page </a>

  <ol class = 'instructions'>

  <li> Step 1: Please select your first year you want to gather data from. </li>
  <li> Step 2: Next, select a second year to create a time interval. </li>
  <li> Step 3: Then, select the time of year you want to retrieve data from. </li>
  <li> Step 4: Finally, specify a specific regional location. </li>

  </ol>


  <form action="unemployed2.php" method ="post">
  <input type="hidden" name="submitted" value="true" />

  <fieldset>
  <legend>
  Specify Date, Month, and County
  </legend>
  <p class = 'year'>
  <label for="year">
  Please Select years: From 
  </label>

  <select name= 'year'>
  <option value= ''> </option>
  <?php
  $query = "select distinct year from unemployed";

  $result = $conn->query($query);
  while($row = $result->fetch_object()) {
    echo "<option value='".$row->year."'>".$row->year."</option>";
   }
  ?>
  </select>
  </p>

  <p class = 'year'>
  <label for="year">
  To
  </label>

  <select name= 'year2'>
  <option value= ''> </option>
  <?php
  $query = "select distinct year from unemployed";

  $result = $conn->query($query);
  while($row = $result->fetch_object()) {
    echo "<option value='".$row->year."'>".$row->year."</option>";
   }
  ?>
  </select>
  </p>


  <p>
  <label for="month">
  Please select a month
  <label>

  <select name= 'month'>
  <option value= ''> </option>
  <?php
  $query = "select distinct month from unemployed";

  $result = $conn->query($query);
  while($row = $result->fetch_object()) {
    echo "<option value='".$row->month."'>".$row->month."</option>";
   }
  ?>
  <option value = "All Months"> All Months </option>
  </select>
  </p>

  <p>
  <label for="location">
  Please specify a location
  </label>

  <select name='location'>
  <option value= ''> </option>

  <option value = 'Fayette'> Fayette County (IN) </option>
  <option value = 'Henry'> Henry County (IN) </option>
  <option value = 'Randolph'> Randolph County (IN) </option>
  <option value = 'Rush'> Rush County (IN) </option>
  <option value = 'Union'> Union County (IN) </option>
 <option value = 'Wayne'> Wayne County (IN) </option>
 <option value = 'INCounties'> Local Indiana Counties </option>
 <option value = 'Indiana'> Indiana </option>
 <option value = 'Butler'> Butler County (OH) </option>
 <option value = 'Darke'> Darke County (OH) </option>
 <option value = 'Mercer'> Mercer County (OH) </option>
 <option value = 'Preble'> Preble County (OH) </option>
 <option value = 'OHCounties'> Local Ohio Counties </option>
 <option value = 'Ohio'> Ohio </option>
 <option value = 'US'> United States </option>

 </select>
 </p>


 <input type ="submit" />

 </fieldset>
 </form>

<?php

  if (isset($_POST['submitted'])) {


  $gYear = $_POST["year"];
  $gYear2 = $_POST["year2"];
 $gMonth = $_POST["month"];


 $array = array('loc1' => 'Fayette', 'loc2' => 'Henry', 'loc3' => 'Randolph', 
         'loc4' => 'Rush', 'loc5' => 'Union', 'loc6' => 'Wayne',
         'loc7' => 'INCounties','loc8' => 'Indiana', 'loc9' => 'Butler', 'loc10' => 'Darke',
         'loc11' => 'Mercer', 'loc12' => 'Preble', 'loc13' => 'OHCounties',
         'loc14' => 'Ohio', 'loc15' => 'US');

 if ($gYear > $gYear2) {

 die('ERROR: Your second year cant be a time period before the first year you selected');
 }

 else {

 if (array_key_exists($_POST["location"], $array)) {

 $column = $_POST["location"];
 }

 else {
 echo "ERROR";
 }



 $sql = "SELECT `$column`, `Year`, `Month` FROM unemployed WHERE year BETWEEN ? AND ? and month= ?";
 $query = $conn->prepare($sql);
 $query->bind_param('sss', $gyear, $gYear2, $gMonth);

 $query->execute(); 
 $result = $query->get_result();

 echo "<table>";
 echo "<tr><th>Year</th><th>Month</th><th>$column</th></tr>";

 while ($row = $result->fetch_object()){

 echo "<tr><td>";
 echo $row->$column;
 echo "</td><td>";
 echo $row->Year;
 echo "</td><td>";
 echo $row->Month;
 echo "</td></tr>";

 }

 $query->close();



 echo "</table>";

 }
 } // end of main if statement

 ?>

 </body>

If I had to guess, my error lies within these lines of code because the web page shows ERROR after I push the submit button:

$array = array('loc1' => 'Fayette', 'loc2' => 'Henry', 'loc3' => 'Randolph', 
             'loc4' => 'Rush', 'loc5' => 'Union', 'loc6' => 'Wayne',
             'loc7' => 'INCounties','loc8' => 'Indiana', 'loc9' => 'Butler', 'loc10' => 'Darke',
             'loc11' => 'Mercer', 'loc12' => 'Preble', 'loc13' => 'OHCounties',
             'loc14' => 'Ohio', 'loc15' => 'US');
else {

     if (array_key_exists($_POST["location"], $array)) {

     $column = $_POST["location"];
     }

     else {
     echo "ERROR";
     }

Does anyone know what my error is? Any help would be greatly appreciated.

  • 写回答

4条回答 默认 最新

  • doulu4976 2013-09-17 15:15
    关注

    add error_reporting(E_ALL); and ini_set("display_errors",1); at the top of your code, and check for an error

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答