Send a different field to the ID to edit a form

0

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.

    
asked by Alex 22.07.2017 в 09:00
source

1 answer

1

You mention that the error is connection. If your error was in the field then you would have an error or a warnning and I would tell you the problem of the query.

Try to be sure that you close the connections and reopen them before making a query, it is a very common error when working like this. I think that at some point you close your connection and then try to make a query. You may also open it and never close it and your session expires.

Greetings, I hope I have been helpful.

    
answered by 22.07.2017 в 16:22