Good afternoon, I am trying to do an exercise that consists of a bus manager, trying to register new buses through a form. I attached the code and my doubts to see if you can help me:
The form where the data is entered:
<form action="funciones.php" method="post">
<label for="Nombre">Nombre</label>
<input type="text" name="Nombre" value="" id="Nombre" />
<label for="Color">Color</label>
<input type="text" name="Color" value="" id="Color" />
<label for="Capacidad">Capacidad</label>
<input type="text" name="Capacidad" value="" id="Capacidad" />
<input type="submit" name="alta" value="Dar de alta"/>
<div class="clearfix"></div>
</form>
The functions.php file and the function to insert a new bus:
function altaAutobuses(){
$nombre = $_POST["Nombre"];
$color = $_POST["Color"];
$capacidad = $_POST["Capacidad"];
$autobus = new Autobuses($nombre, $color, $capacidad);
conexionBD($autobus->consulta());
header('Location:ver_autobuses.php');
}
Here the class bus, to see the query function () that is the one that passes the query to MySQL:
class Autobuses{
private $nombre;
private $color;
private $capacidad;
function __construct($nombre, $color, $capacidad){
$this->nombre->$nombre;
$this->color->$color;
$this->capacidad->$capacidad;
}
public function consulta(){
$consulta = "INSERT INTO autobuses (Nombre,Color,Capacidad) VALUES ('".$this->nombre."','".$this->color."','".$this->capacidad."')";
return $consulta;
}
}
The point is that I have another file to see the buses that are in the database, and if that shows the buses on the screen, so the connection to the database works, and if I add a new bus in the database, PHPMyAdmin also shows it, so there is no doubt that the connection to the database goes well. I do not understand what is failing, I have tried to change the variables of the query () function of the bus and put words directly, but it does not connect to the database, instead, I put the request "SELECT * FROM buses" and if that shows me the contents of the database ....
Also, I try to do an echo with the variables that happened through the form, and write them on the screen, so you are receiving them. I understand that the problem is in the writing of new data in the database of PHPMyAdmin ...
Thank you and greetings.