Problem sending something to database

0

So, I'm trying to create a page, simple even, to send some things to the database, (id, username, code_plate) but I can not, by removing the lines that give error, the page opens, however, to send only refreshes the page and does not send anything to the database, could you help me? Errors that appear:

Warning: include(../../Templates/Hk_Head_2.php): failed to open stream: No such file or directory in /home/iceag061/public_html/hk/badges.php on line 2

Warning: include(../../Templates/Hk_Head_2.php): failed to open stream: No such file or directory in /home/iceag061/public_html/hk/badges.php on line 2

Warning: include(): Failed opening '../../Templates/Hk_Head_2.php' for inclusion (include_path='.:/opt/php56/lib/php') in /home/iceag061/public_html/hk/badges.php on line 2

Fatal error: Call to a member function query() on null in /home/iceag061/public_html/hk/badges.php on line 4

Code:

<?php
include "../../Templates/Hk_Head_2.php";

$query = $link->query('SELECT rank FROM usuarios WHERE username = "' .$username. '"');
while($row = mysqli_fetch_array($query))
{
  $rangouser = $row['rank'];
}
if("$rangouser" == "2"){
header("Location: " . $_SERVER['HTTP_REFERER']);
  exit;
}a
if("$rangouser" == "1"){
header("Location: " . $_SERVER['HTTP_REFERER']);
  exit;
}
if("$rangouser" == "3"){
header("Location: " . $_SERVER['HTTP_REFERER']);
  exit;
}
if("$rangouser" == "4"){
header("Location: " . $_SERVER['HTTP_REFERER']);
  exit;
}

include "../../Templates/Hk_Nav.php";
?>

      <div class="container">
      <!-- Main component for a primary marketing message or call to action -->
     <div class="row">
<div class="col-md-8">
          <div class="panel panel-default">
                  <div class="panel-heading blue">
              <h3 class="panel-title"><?php echo $lang[426]; ?></h3>
            </div>
            <div class="panel-body">

<div class="formulariohk">
<form action="" method="post" enctype="multipart/form-data">
              <label><?php echo $lang[418]; ?></label>
                    <input style="margin-bottom: 10px;" type="text" required="" class="form-control" name="id" placeholder="Id Da Placa" value="" />  <br>

                     <label><?php echo $lang[422]; ?></label>
                    <input style="margin-bottom: 10px;" type="text" required="" class="form-control" name="username" placeholder="Usuario" value="" />  <br>

                    <label><?php echo $lang[423]; ?></label><br>
                    <input style="margin-bottom: 10px;" type="text" required="" class="form-control" name="code_placa" placeholder="Codigo do emblema" value="" />  <br>

                    <center><input class="btn btn-primary" name="guardar" type="submit" value="<?php echo $lang[192]; ?>" style="width: 120px;" /></center>
                      </form>

                      <?php
if ($_POST['guardar'] && $_POST['titulo']) {
$enviar = "INSERT INTO usuarios_placas (id,username,code_placa) values ('".$username."','".strip_tags($_POST['id'])."','".strip_tags($_POST['username'])."','".$_POST['code_placa']."')";

if (@$link->query($enviar)) { 

// Guardar acci贸n en Logs si se ha iniciado sesi贸n

$fecha_log = date("Y-m-d");
$accion = $lang[434];
$enviar_log = "INSERT INTO logs (usuario,accion,fecha) values ('".$username."','".$accion."','".$fecha_log."')";
$link->query($enviar_log);
// Log guardado en Base de datos

?>
<script type="text/javascript">
  location.href ="<?php echo $_SERVER['HTTP_REFERER']; ?>";
</script>
<?php
}
}
?>

</div></div>
            </div>
          </div>

        </div>
      </div><!-- /container -->

<?php 

include "../../Templates/Hk_Footer_2.php";

?>
    
asked by anonymous 27.03.2018 / 03:08

2 answers

0

The first three errors mean that the path or file names are incorrect if you need more help to resolve this problem edit your question by adding the structure of your project folders

The 4th error means that the variable $link is null, ie there is no connection variable with the database, to create:

$link = new mysqli('localhost', 'username', 'password', 'database');

This is probably because pages that are not being included are where the connection to the database is being created

Tip: instead of using a loop to save the data:

while ($row = mysqli_fetch_array($query)) {
    $rangouser = $row['rank'];
}

You can use mysqli's fetch_all function:

$rangouser = mysqli_fetch_all($query);

You can still pass a second parameter:

  • MYSQLI_ASSOC - returns an associative array
  • MYSQLI_NUM - returns a numeric array
  • MYSQLI_BOTH - returns a single array with the attributes of both.

MYSQLI_BOTH is the default value

Caution: When using tweening in your SQL statement your code is subject to SQL Injection

    
28.03.2018 / 03:33
0

Your problem lies in the fact that your includes are being done the wrong way.

Let's look at the following example:

index.php
 /includes/footer.php

If I'm in index.php to include footer, just:

include 'includes/footer.php';

If I'm in footer.php and want to include the index:

include '../index.php';

Now let's go to a scenario similar to yours:

index.php
 /includes/page/footer.php

If I'm in index.php to include footer.php, just:

include 'includes/page/footer.php';]

If I'm in footer.php and want to include the index:

include '../../index.php';

The error that appears in your code clearly shows that the script can not find the paths you entered to include them. Well I do not know how your file organization is. So I can not infer much. But I think if you try to change these parameters you will be able to solve them.

    
27.03.2018 / 04:43