jeudi 31 mai 2018

Database Connection with PHP

I am creating a website app. I am trying to send data to the database, but I got the error This page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500

After a long time trying to find the error I wasn't able to fix it and I was wondering if you could help me.

Here you have the code.

reportcreated.php

<?php
if (isset($_POST[`name`])) {
  $name = $_POST[`name`];
}
if (isset($_POST[`last_name`])) {
  $last_name = $_POST[`last_name`];
}
if (isset($_POST[`email`])) {
  $email = $_POST[`email`];
}
if (isset($_POST[`issue`])) {
  $issue = $_POST[`issue`];
}
if (isset($_POST[`imageReport`])) {
  $imageReport = $_POST[`imageReport`];
}
if (isset($_POST[`date`])) {
  $date = $_POST[`date`];
}
if (isset($_POST[`location_lat`])) {
  $location_lat = $_POST[`location_lat`];
}
if (isset($_POST[`location_lon`])) {
  $location_lon = $_POST[`location_lon`];
}
if (isset($_POST[`address`])) {
  $address = $_POST[`address`];
}
  try {
    require_once('../functions/db-conection.php');
    $sql = "INSERT INTO `reporte` (`issue_id`,`name`, `last_name`, `email`,`issue`, `imageReport`, `date`,`location_lat`, `location_lon`,`address`)";
    $sql .= "VALUES (NULL,'{$name}','{$last_name}','{$email}','{$issue}','{$imageReport}','{$date}','{$location_lat}',{$location_lon},{$address}); ";
    $result = $conn->query($sql);

  } catch (Exception $e) {
    $error = $e->getMessage();
  }
  ?>
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">


    <header>

    <h2>CityLife</h2>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <meta charset="utf-8">
    <style>
        #map {
           height: 100%;
         }
         /* Optional: Makes the sample page fill the window. */
         html, body {
           height: 100%;
           margin: 0;
           padding: 0;
         }
       </style>
    </header>

    <style>
    body {margin:0;}

    h2 {
      background-color: #000033;
      color: white;
      width: 100%;
      height: 33%;
      margin: auto;
      align-content: center;

    }


    .addReport {
      overflow: hidden;
      background-color:     #000033;
      position: fixed;
      bottom: 0;
      width: 100%;
      align-content: center;
    }

    .addReport a {
      float: left;
      display: block;
      color: #ffffff;
      text-align: center;
      padding: 30px 72px;
      text-decoration: none;
      font-size: 17px;
      width: 100%;
    }

    .addReport a:hover {
      background: #cccccc;
      color: white;
    }

    .addReport a.active:hover {
      background-color:     #ffffff;
      background: #cccccc;
      color: white;
    }

    .main {
      padding: auto;
      margin-bottom: 30px;
    }
.form {
  margin: 16px;
  width: 100%;

}
.input {
  margin-left: 16px;
  border-style: black;
  width: 100%;
}


    </style>

  </head>
  <body>

  <form action="reportcreated.php" style="margin: 16px" method="post">
    First name:<br>
    <input style="border-color:gray" type="text" id="nameid" name="firstname" value="" placeholder="First Name" for="name">
    <br>
    Last name:<br>
    <input style="border-color:gray" type="text" id="last_nameid" name="firstname" value="" placeholder="Last Name" for=last_name>
    <br>
    Email Address:<br>
    <input style="border-color:gray" type="text" id="emailid" name="email" value="" placeholder="Email Address" for="email">
    <br>
    Issue:
    <br>
    <select id="issue" name="issues" for="issue">
   <option value="#"></option>
   <option value="#"></option>
   <option value="#"></option>
   <option value="#"></option>
 </select>
    <br><br>
    <input style="border-color:black" type="button" onclick="window.history.go(-1); return false;" value="Cancel">  <input style="border-color:black" type="submit" value="Submit" value="Geocode">

  </form>

  </body>
  <script src="../JS/reportscript.js"></script>
  </script>
  <script async defer
  src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBFGBXCr32GmNkG_TAo76JWn4b0nprnukY&callback=">
  </script>
</html>

report.php

<?php
if(isset($_POST[`name`])) {
  $name = $_POST[`name`];
}
if(isset($_POST[`last_name`])) {
  $last_name = $_POST[`last_name`];
}
if(isset($_POST[`email`])) {
  $email = $_POST[`email`];
}
if(isset($_POST[`issue`])) {
  $issue = $_POST[`issue`];
}
if(isset($_POST[`imageReport`])) {
  $imageReport = $_POST[`imageReport`];
}
if(isset($_POST[`date`])) {
  $date = $_POST[`date`];
}
if(isset($_POST[`location_lat`])) {
  $location_lat = $_POST[`location_lat`];
}
if(isset($_POST[`location_lon`])) {
  $location_lon = $_POST[`location_lon`];
}
if(isset($_POST[`address`])) {
  $address = $_POST[`address`];
}
if(isset($_POST[`report_type`])) {
  $report_type = $_POST[`report_type`]
}
  try {
    require_once('../functions/db-conection.php');
    $sql = "INSERT INTO `users` (`user_id`, `name`, `last_name`, `email`) ";
    $sql .= "VALUES (NULL, '{$name}, '$last_name', '$email'); ";
    $result = $conn->query($sql);

  } catch (Exception $e) {
    $error = $e->getMessage();
  }
  ?>
<!DOCTYPE html>
<html>
  <head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">


    <header>

    <h2>CityLife</h2>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <meta charset="utf-8">
    <style>
        #map {
           height: 100%;
         }
         /* Optional: Makes the sample page fill the window. */
         html, body {
           height: 100%;
           margin: 0;
           padding: 0;
         }
       </style>
    </header>

    <style>
    body {margin:0;}

    h2 {
      background-color: #000033;
      color: white;
      width: 100%;
      height: 33%;
      margin: auto;
      align-content: center;

    }


    .addReport {
      overflow: hidden;
      background-color:     #000033;
      position: fixed;
      bottom: 0;
      width: 100%;
      align-content: center;
    }

    .addReport a {
      float: left;
      display: block;
      color: #ffffff;
      text-align: center;
      padding: 30px 72px;
      text-decoration: none;
      font-size: 17px;
      width: 100%;
    }

    .addReport a:hover {
      background: #cccccc;
      color: white;
    }

    .addReport a.active:hover {
      background-color:     #ffffff;
      background: #cccccc;
      color: white;
    }

    .main {
      padding: auto;
      margin-bottom: 30px;
    }
.form {
  margin: 16px;
  width: 100%;

}
.input {
  margin-left: 16px;
  border-style: black;
  width: 100%;
}


    </style>

  </head>
  <body>

<div class="reportCreated">
  <h1>Report Created</h1>

  <div class="content">
  <?php
    echo $sql;
   ?>
 </div>

</div>
  </body>
</html>

db-conection.php

<?php
  $conn = new mysqli('localhost', 'root', 'root', 'RoystonApp');

  if ($conn->connect_error) {
    echo $error = $conn->connect_error;
  }

 ?>

Thank you!




Aucun commentaire:

Enregistrer un commentaire