0

Ive been trying all day to create a new entry in my table. Sorry for all the text in spanish. I hope it is not a problem.

enter image description here

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    $nueva_tienda = $_POST['nueva_tienda'];
    if(!empty($nueva_tienda)){
        echo "not empty";
        include('connection.php');
        mysqli_query($dbc, "INSERT INTO tiendas (nombre) VALUES ('$nueva_tienda')");
    }
    else{
        echo "Porfavor llena todos los campos";
    }
}
else{
    echo "No form has been submitted";
}

?>



<h1>Nueva tienda</h1>
    <form action="processing2.php" method="post">
    <p>Nombre de la nueva tienda: <input type="text" name="nueva_tienda" maxlength="50"/></p>
    <p><input type="submit" name="submit" value="Submit"/></p>
    </form>

EDIT:

Added connection include file from comments:

 <?php $hostname = "localhost"; 
       $username = "root"; 
       $password1 = ""; 
       $dbname = "inventario_collares"; //making the connection to mysql        
       $dbc = mysqli_connect($hostname, $username, $password1, $dbname) OR die("could not connect to database, ERROR: ".mysqli_connect_error()); 
     //set encoding 
       mysqli_set_charset($dbc, "utf8"); 
?>
Martin
  • 22,212
  • 11
  • 70
  • 132

2 Answers2

0

Create an object of your connection class.

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    $nueva_tienda = $_POST['nueva_tienda'];
    if(!empty($nueva_tienda)){
        echo "not empty";
        include('connection.php');
    //create an object for your connection class
        $dbc=new connection();
        mysqli_query($dbc, "INSERT INTO tiendas (nombre) VALUES ('$nueva_tienda')");
    }else{
        echo "Porfavor llena todos los campos";
    }
    }else{
    echo "No form has been submitted";
}


?>



<h1>Nueva tienda</h1>
    <form action="processing2.php" method="post">
    <p>Nombre de la nueva tienda: <input type="text" name="nueva_tienda" maxlength="50"/></p>
    <p><input type="submit" name="submit" value="Submit"/></p>
    </form>
Sinsil Mathew
  • 498
  • 6
  • 20
0

1) Turn on PHP error outputting at the top of your script:

ini_set('display_errors', 1);
error_reporting(E_ALL);

2) set this line:

mysqli_query($dbc, "INSERT INTO tiendas (nombre) 
 VALUES ('$nueva_tienda')") 
    or die("Error MySQL Line ".__LINE__." :".mysqli_Error($dbc));

This will output any problems if the MySQL insert query fails.

If you do both of these things and still get no error, then the problem is elsewhere (such as is your file called processing2.php? etc.).

Martin
  • 22,212
  • 11
  • 70
  • 132