包含$ _SESSION和$ _GET时不插入数据

时间:2017-08-16 21:25:33

标签: php html

我不知道这里有什么问题。我试图包含$ _SESSION和$ _GET并插入变量。查询工作正常,似乎正在执行它,但没有数据插入数据库。

$ _ SESSION和$ _GET有一个数据。我试着回应它并显示我想要的数据,这些数据是从数据库中存储的。

PHP

 <?php
      session_start();

      include_once 'packages-header.php';

      include 'includes/dbh.inc.php';

    mysqli_select_db($conn, "test");
    $sql = "SELECT * FROM package";
    $data = mysqli_query($conn, $sql);


    while ($record = mysqli_fetch_array($data)) {

    $id = $record['package_id'];

    echo "<table border = 1>";
    echo "<tr>";
    echo "<th>" . $record['package_name'] . "</th>";


    echo "</tr>";
    echo "<tr>"; 
    echo "<td>" . "<br />" .  $record['package_details'] . "<br />" . "</td>" ;

    echo "<tr/>";

    echo  "<td><a  href='package.all.php?id=$id'>Submit</a></td>";



    }

    echo "</table>";

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


    $p_id = $_GET['id'];
    $c_id = $_SESSION['u_id'];
    $e_name = mysqli_real_escape_string($conn, $_POST['e_name']) ;
    $d_event = mysqli_real_escape_string($conn, $_POST['d_event']) ;
    $t_event = mysqli_real_escape_string($conn, $_POST['t_event']) ;
    $e_t_event = mysqli_real_escape_string($conn, $_POST['e_t_event']) ;
    $theme = mysqli_real_escape_string($conn, $_POST['theme']) ;
    $date = date('Y-m-d H:i:s');


      if (empty($e_name) || empty($d_event) || empty($t_event) || empty($e_t_event) || empty($theme)){

        header("Location:../Packages.all.php?empty");
        exit();
      }else{


    $sql = "INSERT INTO event_table (event_name, event_date, event_time_start, event_time_end, cusact_id, theme, reserve_date_time) VALUES ('$e_name', '$d_event', '$t_event', '$e_t_event', '$c_id', '$theme', '$date');";
    mysqli_query($conn, $sql);

    }
    }
     else {

      echo 'isset was false'; 


    }


    ?>

HTML文件

               <?php 
      if (isset($_SESSION['u_uid'])) {


        echo '<form action="includes/logout.inc.php"    method="POST">
        <button type="submit" name="submit">logout</button>
        </form>

        ';
      } else {
        echo '<form action="Login.php"><button type="submit" name="submit">
        Login</button> </form>
        <form action="signup.php"> <button type="submit" name="signup">Signup</button> </form>';
      }
      ?>
          </ul>
          <span class='follow'>
            <a class='links' href='#' target='_blank' title='Twitter'>
              <i class='fa fa-twitter'></i>
            </a>

            <a class='links' href='#' target='_blank' title='Youtube'>
              <i class='fa fa-facebook'></i>
            </a>
            <a class='links' href='#' target='_blank' title='Youtube'>
              <i class='fa fa-google-plus'></i>
            </a>


          </span>
        </div>


      </header>

<div class="form-style-5">


<form method="POST">
<label>Event Name</label>
<input type="text" name="e_name" placeholder="Enter Event Name*"/>

<label for="job">Day of the Event</label>
<input type="date" name="d_event" placeholder="Enter Date of Event*"/>


<label for="job">Time of the Event</label>
<input type="Time" name="t_event" placeholder="Enter Time of Event*"/>

<label for="job">End Time of the Event</label>
<input type="Time" name="e_t_event" placeholder="Enter End Time of Event*"/>

<label>Theme</label>
<input type="text" name="theme" placeholder="Enter Theme*"/>
<input name="submit" type="submit" value="Submit"/>
</form>


      <footer id='contacts'>

        <span class='cc'>
          @ 2014 . Zaldy Ducusin
        </span>
      </footer>
    </div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
    <script>
      window.jQuery || document.write('<script src="/javascripts/libs/jquery-1.10.2.min.js"><\/script>')
    </script>
    <script src="javascripts/libs/holder.js" type="text/javascript"></script>
    <script src="javascripts/plugins.js" type="text/javascript"></script>
    <script src="javascripts/formsjs.js" type="text/javascript"></script>

</html>

我对PHP很新,所以请耐心等待。还在学习。非常感谢你的时间:))

1 个答案:

答案 0 :(得分:0)

试试这个,它会给你错误信息。:

$sql = "INSERT INTO event_table (event_name, event_date, event_time_start, event_time_end, cusact_id, theme, reserve_date_time) VALUES ('$e_name', '$d_event', '$t_event', '$e_t_event', '$c_id', '$theme', '$date');";
$result = mysqli_query($conn, $sql);

    if(!$result){
        echo("Error description: " . mysqli_error($conn));
    }

了解详情:http://php.net/manual/en/mysqli.error.php