I'm a beginner on coding and I've been working on this type of project in which I want to insert data to an SQL server with PHP, so what I'm struggling with is the part where I want to insert data and I want to take the select tags objects into variables, I've been getting Undefined Index so if you could help I'd be very grateful.
HTML Code:
<form action="" method="POST">
<input type="text" class="puo" id="modeloPU" name="Nmod" style="width:
9.6%">
<select class="puo" id="familiaSPU" name="Nfam">
<option value="-1 "></option>
<option value="0" style="font-style: italic; color:grey">indefinido</option>
<option value="1">ENFRIADORES</option>
<option value="2">FROSTER</option>
<option value="3">CONGELADORES</option>
<option value="4">MIRAGE</option></select>
<select class="puo puh" id="odpSPU" name="Nodp">
<option value="-1"></option>
<option value="0" style="font-style: italic; color:grey">indefinido</option>
<option value="1">HORIZONTAL</option>
<option value="2">VERTICAL</option></select>
<select class="puo puh" id="tdcSPU" name="Ntdc">
<option value="-1"></option>
<option value="0" style="font-style: italic; color:grey">indefinido</option>
<option value="1">CLIENTE PARTICULAR</option>
<option value="2">VALIDADOS</option>
<option value="3">DEFINIDOS</option>
<option value="4">ESTÁNDAR</option></select>
<select class="puo puh" id="clienteSPU" name="Ncliente">
<option value="-1"></option>
<option value="0" style="font-style: italic; color:grey">indefinido</option>
<option value="1">CBC</option>
<option value="2">COCA-COLA</option>
<option value="3">FASA</option>
<option value="4">FLORIDA</option>
<option value="5">HOSHISAKI</option>
<option value="6">JALEEL</option></select>
<select class="puo puh" id="voltajeSPU" name="Nvoltaje">
<option value="-1"></option>
<option value="0" style="font-style: italic; color:grey">indefinido</option>
<option value="1">110V(50Hz - 60Hz)</option>
<option value="2">140V(50Hz - 60Hz)</option>
<option value="3">220V(50Hz - 60Hz)</option></select>
<select class="puo puh" id="gradoSPU" name="Ngrado">
<option value="-1"></option>
<option value="0" style="font-style: italic; color:grey">indefinido</option>
<option value="1">C°</option>
<option value="2">F°</option></select>
<select class="puo puh" id="termostatoSPU" name="Ntermostato">
<option value="-1"></option>
<option value="0" style="font-style: italic; color:grey">indefinido</option>
<option value="1">CAREL</option>
<option value="2">COEL</option>
<option value="3">ELSTAT</option>
<option value="4">FULL GAUGE</option>
<option value="5">SOLLATEK</option>
<option value="6">WELLINGTON</option></select>
<select class="puo puh" id="tdpSPU" name="Ntdp">
<option value="-1"></option>
<option value="0" style="font-style: italic; color:grey">indefinido</option>
<option value="1">PVP</option>
<option value="2">PVPH</option>
<option value="3">PS</option></select>
<select class="puo puh" id="paisSPU" name="Npais">
<option value="-1"></option>
<option value="0" style="font-style: italic; color:grey">indefinido</option>
<option value="1">USA</option>
<option value="2">Puerto Rico</option>
<option value="3">Latino America</option></select>
<input type="submit" class="Boton" name="submit" id="AddButton"
value="Agregar" style="box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px
50px 0 rgba(0,0,0,0.19); cursor: pointer;">
</form>
PHP Code:
<?php
include 'conn.php';
$myDate = date('Y/m/d');
$model = $_POST['Nmod'];
$fam = $_POST['Nfam'];
$orientacion = $_POST['Nodp'];
$tdcliente = $_POST['Ntdc'];
$cli = $_POST['Ncliente'];
$volt = $_POST['Nvoltaje'];
$grad = $_POST['Ngrado'];
$termo = $_POST['Ntermostato'];
$tdpuerta = $_POST['Ntdp'];
$pai = $_POST['Npais'];
$SQL = "INSERT INTO usuario (modelo ,familia ,odp ,tdc ,cliente ,voltaje ,
grado ,termostato, tdp, pais, fecha)
VALUES ('$model', '$fam',
'$orientacion', '$tdcliente', '$cli', '$volt',
'$grad', '$termo', '$tdpuerta', '$pai','$myDate')";
if ($conn->query($SQL) == TRUE) {
echo "New record created successfully";
}
else {
echo "Error: " . $SQL . "<br>" . $conn->error;
}
$conn->close();
?>