Pass 2 or more variables in php

1

Happy Friday and happy weekend!

I have a couple of problems, one could be resolved if I pass at least two variables to the next page. One works well

link = '098usredit.php?idusr=' . $row098['98idusr'];

Of pure ambition I wanted to spend 3 but I settle for two, this is within the php

$link = '098usredit.php?idusr=' . $row098['98idusr']'&nomb=' . $row098['98nomb']'&gr=' . $row098['gr'] ; //asi no funciona pero creo que es porque no sé formar la oración GARCIA A MARZO.
     echo "<tr>";
        echo "<td align='center'>" . $row098['98idusr'] . "</td>";
        echo "<td aling='left'>" . $row098['98nomb'] . "</td>";
        echo "<td align='left'>" . $row098['gr'] .  "</td>";
        echo "<td align='center'><a href=\"$link\" target= _self ><img src='img/001-lapiz2.png' width='16' height='16' alt=''/></a></td>";
        echo "<td align='center'></td>";

same file another topic Next page 098usredit.php

On the one hand if I can pass iduser (I can already) but also the name would avoid making an unnecessary query on this page with what would only be 2 instead of 3 as now. The problem is that to get the new user group I use a select / option that works perfectly in other pages but it is not registered and does not incorporate it into UPDATE. I transcribe the basic code, but do not challenge me. I already have the iduser or id or 98idusr and I choose in the select / option the new group

FORM

<select name="grupo" required id="grupo" form="f098" title="grupo" >            <option value=""></option>
<?php $sql098b="select idgr, gr from $t98g"; 
$r098b=mysqli_query($mysqli, $sql098b); 
while($rw098b=mysqli_fetch_array($r098b)) { 
?>
<option value="<?php echo $rw098b['idgr']; ?>"><?php echo $rw098b['gr']; ?></option>
    <?php } $grupo = $rw098b['idgr']; ?>
</select>

DO NOT TAKE THIS ERROR: ERROR: It is not possible to execute UPDATE 98usr SET 98group = '' WHERE 98idusr = '31 '. Incorrect integer value: '' for column '98group' at row 1

<?php
    if($_SERVER["REQUEST_METHOD"] == "POST"){
    // verificar que el boton SUBMIT fue presionado
if(isset($_POST['bt-098']))
{
require_once '990conn.php';
// seleccionar la variable que se va a actualizar grupo = 98grupo también un número definida en la selecion 
$sql098 = "UPDATE 98gr SET 98grupo = '$grupo' WHERE 98idusr='$idusr'"; 
if($mysqli->query($sql098) === true){
    echo "El grupo fue cambiado.";
} else{
    echo "ERROR: No es posible ejecutar $sql098. " . $mysqli->error;
} } }
// Close connection
$mysqli->close();
?>

In short, I see that the select is not registered as a value to pass and that frustrates me a lot. Talueguito.

    
asked by Silvia Gaviota Garcia 03.11.2017 в 23:22
source

1 answer

0

A. If the UPDATE you try from the same page

If the UPDATE you want to launch it from the same page, without pressing any button of the form, you are assigning $grupo out of while ... you have to put a magnifying glass to see it in the middle of your code.

Notice how nice an organized code is, you see the errors at once:

<select name="grupo" required id="grupo" form="f098" title="grupo" >
        <option value=""></option>
<?php 
    $sql098b="select idgr, gr from $t98g"; 
    $r098b=mysqli_query($mysqli, $sql098b); 
    while($rw098b=mysqli_fetch_array($r098b)) { 
?>
        <option value="<?php echo $rw098b['idgr']; ?>"><?php echo $rw098b['gr']; ?></option>
<?php 
        $grupo = $rw098b['idgr'];  //Esto estaba fuera del recorrido de resultados
    }
?>
</select>

B. If the UPDATE is sent when sending a form

If the UPDATE is thrown when sending a form, then you must retrieve the group value like this:

$grupo=$_POST["grupo"];

C. Regarding your query UPDATE :

$sql098 = "UPDATE 98gr SET 98grupo = '$grupo' WHERE 98idusr='$idusr'"; 

Note that if any of the values is numeric, you should remove the single quotes that surround the variable:

Example, assuming that 98grupo is of the numeric type in the database:

$sql098 = "UPDATE 98gr SET 98grupo = $grupo WHERE 98idusr='$idusr'"; 

The same thing, if 98idusr were numeric, you should remove the single quotes.

PS: I no longer challenge more to use prepared queries, but I always put the note that this code is dangerous and I am not responsible for the damage.

    
answered by 04.11.2017 / 00:04
source