0

I need to be able to call the id that is stored in the qr, but i dont know how to call it, i´m sorry for the horrible code its my first proyect.


<html>
<body>

    <?php
    function connection (){
    $connection= mysqli_connect("localhost","root","","control_index");
    return $connection;
}
    $hostname="localhost";
    $username="root";
    $password="";
    $databaseName="control_index";
    $connect=mysqli_connect($hostname,$username,$password,$databaseName);
    $query_curso="SELECT * FROM curso";
    $result1=mysqli_query($connect,$query_curso);

  ?>
  <form method="POST">
    <script src="html5-qrcode.min.js"></script>
        <h3>asistencia:</h3>
        <select name="curso">
            <option value="" disabled selected>Selecciona una curso</option>
            <?php while($row1 = mysqli_fetch_array($result1)):;?>
            <option value="<?php echo $row1[0];?>">
                <?php echo $row1[1];?>
            </option>
            <?php endwhile;?>
        </select>
        <p><a href="http://localhost/index_archivos/Menu_principal.html">Volver</a></p>
<div class="row" align="center">
  <div class="col" align="center">
    <div style="width:500px;" id="reader"></div>
  </div>
  <div class="col" style="padding:30px;">
    <h4>SCAN RESULT</h4>
    <div id="result">Result Here</div>
  </div>
</div>
<script type="text/javascript">
function onScanSuccess(qrCodeMessage) {
    document.getElementById('result').innerHTML = '<span class="result">id_trabajador = '+qrCodeMessage+'</span>';
    "${result}";
    return qrCodeMessage;
}
function onScanError(errorMessage) {
  //handle scan error
}


var html5QrcodeScanner = new Html5QrcodeScanner(
"reader", { fps: 10, qrbox: 250 });
html5QrcodeScanner.render(onScanSuccess, onScanError);


</script>

  <?php
if(isset($_POST['curso'])){
$id_curso=$_POST['curso'];

$sql=mysqli_query($connect,"INSERT INTO asistencia(ID_Trabajador,ID_Curso,Hora_De_Asistencia)values('$id_trabajador','$id_curso',CURRENT_TIME)");  
}

?>

<input type="submit" name="submit">

</form>
</body>
</html> 

I know where its displayed and its generated in on scan success, but i dont know how to call the function to php to be able to store it in an sql

MXSF97
  • 1
  • 1
    What do you mean by "call the id"? Please explain more. What is the content of the QR Code? What exactly do you want to do with it? Break down your problem into multiple smaller problems. Which one of those do you know to solve and which one do you habe a problem with? – NineBerry Dec 27 '22 at 15:19
  • 1
    You are open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized prepared statements instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) and [MySQLi](https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even data from the database, [you are still at risk of corrupting your data](https://bobby-tables.com/). [Escaping is not enough](https://stackoverflow.com/q/5741187). – Jason K Dec 27 '22 at 15:21
  • I think you're using this: https://github.com/mebjas/html5-qrcode That might be useful for people to know. – KIKO Software Dec 27 '22 at 15:23
  • yes i forgot to put the library that im using sorry for that, the qr has a value that is the user id, im trying to store that number into an sql query – MXSF97 Dec 27 '22 at 15:28

0 Answers0