I am starting to program a web application with php and mysql, but I have run into a problem. It turns out that I have a table that shows a series of fields and values of a table. I have added a button to view, edit or delete a row from the table. To do this, I use the "id" of the table
<?php
include "conexion.php";
$user_id=null;
$sql1= "select * from batchinput where batchactive like 'Yes'";
$query = $con->query($sql1);
?>
The data is displayed, and at the end of each row I have put the buttons, using the id. For example, for the edit button:
<a href="./formulario.php?id=<?php echo $r["id"];?>" class="btn btn-sm btn-warning">Edit</a>
On the form page the form is opened, collecting the data that is in the database, and thus be able to edit the fields:
<?php
include "conexion.php";
$user_id=null;
$sql1= "select * from batchinput where id = ".$_GET["id"];
$query = $con->query($sql1);
$batchinput = null;
if($query->num_rows>0){
while ($r=$query->fetch_object()){
$batchinput=$r;
break;
}
}
?>
etc ...
Well, now I've thought that instead of picking up the id, I want to select the row in the database using the batchnumber field. Well where I put "id" I change it to "batchnumber", or so I thought, but it gives me "connection error", and it does not show it.
The reason I want to do this, is that I have a second table in which I add comments to each batch, so different IDs are generated to the main table, but the batchnumber is maintained, so that send the link with the batch number from the table, the form to edit the fields of the second table would be opened.
But it does not work for me. What have I overlooked?
Thanks and best regards! Alex.