Problem with a record working with 2 tables, in mysql

0

I have a problem in this query, it consists of 3 sheets, one where I enter an email from a table to find a specific student, another where I change the course and another that modifies the course of the student table.

The problem is that I have a Syntax error according to MySQL and I do not see the error, I pass the code to you.

This is page 1, where I enter the student's email

<html>
<head>
    <meta charset="UTF-8">
    <title>Problema</title>
</head>
<body>
    <form action="pagina17.php" method="post">
        <br> 
        <label for="mail" id="e1">Introduzca el email del alumno</label>
        <input type="text" name="mail"><br>
        <input type="submit" value="buscar">
    </form>
</body>

This is page 2, where I search if the student exists and the course is changed

 <?php $conexion = mysqli_connect("localhost", "root", "", "base1")
    or die("problemas con la conexion");

$registros = mysqli_query($conexion, "select * from alumnos where mail='$_REQUEST[mail]'")
    or die("problemas con la consulta " . mysqli_error($conexion));

if ($regAlu = mysqli_fetch_array($registros)) {
?>
<form action="pagina18.php" method="post">
    <input type="hidden" name="mailviejo" value="<?php echo $regAlu['mail'] ?>">
    <select name="codigocurso">

<?php
        $registros = mysqli_query($conexion, "select * from cursosprog") 
                or die("problemas "
                        . "en el select: " . mysqli_error($conexion));
        while ($reg = mysqli_fetch_array($registros)) {
            if (regalu['codigocurso'] == $reg['codigo']) {
                echo "<option value=\"$reg[codigo]\" selected>$reg[nombrecurso]</option>";
            } else {
                echo "<option value=\"reg[codigo]\">$reg[nombrecurso]</option>";
            }
        }
        ?>

</select>
    <br>
    <input type="submit" value="Modificar">
</form>
<?php
} else {
echo "No existen alumnos con ese email";
}
?>

and here the final page

<?php $conexion = mysqli_connect("localhost", "root", "", "base1")or die("problemas "
            . "con la conexion");

$registros = mysqli_query($conexion, "update alumnos "
    . "set codigocurso=$_REQUEST[codigocurso] "
    . "where mail='$_REQUEST[mailviejo]'") or
    die("problemas en el select ggg" . mysqli_error($conexion));

echo "el curso fue modificado con éxito"
?>
<fieldset>
<a href="pagina16.php">Volver al formulario</a>
</fieldset>

table of students

table cursosprog

The problem he gives me is this (I added it to ggg to locate the bug):

  

problems in the select gggYou have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[code] where mail="[email protected]' at line 1

what syntax error is it?

    
asked by Alberto Bedmar Montaño 03.01.2019 в 05:41
source

1 answer

0

The error shows [code] but in your code is like [code], keeping this in mind you should verify what the file.php receives.

Well the error is because a single quote was opened and it was not closed, now this code works, I have performed a test and it has no syntax error.

    <?php $conexion = mysqli_connect("localhost", "root", "", "base1")or die("problemas "
        . "con la conexion");

    $registros = mysqli_query($conexion, "update alumnos "
     . "set codigocurso=$_REQUEST[codigocurso] "
     . "where mail='$_REQUEST[mailviejo]'") or
        die("problemas en el select ggg" . mysqli_error($conexion));

        echo "el curso fue modificado con éxito"
      ?>

Therefore I would recommend that you verify your code well and check if your variables have to be called code or only code and try it again ..! Remember that if the variable is a String it should be in quotes.

    
answered by 03.01.2019 в 15:38