Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
onclick function fails to update sql

I have this button

<button id = "addBtn-1" onclick = "noneAdd();add1()">Add to My Classes</button> 

It calls a function called add1() from my js file, which adds and removes classes and also calls add():

function add(){
    $.ajax({url:"add.php",
    success:function(result){
        alert("Added to My Classes");
    }
    });
}

which calls my php file, add.php:

require_once "config.php";
include "classes.php";

$myun = $_SESSION["un"];
function bookmark1Add(){

    $sql = "SELECT testclass1 FROM classes WHERE username = ?";
    if($stmt = mysqli_prepare($db, $sql)){

        mysqli_stmt_bind_param($stmt, "s", $param_un);
        $param_un = $myun;

        if(mysqli_stmt_execute($stmt)){

            mysqli_stmt_bind_result($stmt, $myclass1);

            if(mysqli_stmt_fetch($stmt)){

                if($myclass1 == 0){

                    $sql2 = "UPDATE classes
                    SET testclass1 = 1";

                    if($stmt2 = mysqli_prepare($db, $sql2)){

                        mysqli_stmt_bind_param($stmt2, "s", "param_un");
                        $param_un = $myun;

                        if(mysqli_stmt_execute($stmt2)){
                            header("Refresh:0");
                        }
                        else{
                            echo "Something went wrong, please try again later!";
                        }
                    }
                    mysqli_stmt_close($stmt2);
                }
            }
        }
    }
    mysqli_stmt_close($stmt);
}

bookmark1Add();

This line of code is supposed to update the data in my table, but it doesn't seem to be working. When I click the button, nothing changes in the database, however the adding and removing of classes from add1() works so it succeeded in calling the function

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

nvm I made the code much simpler since the one above was way too complicated and rat it on its own to see if there were any bugs.

<?php
require_once "config.php";
include "classes.php";

$myun = $_SESSION["un"];
$sql = "UPDATE classes SET testclass1 = 1 WHERE username = '$myun'";

if (mysqli_query($db, $sql)) {
    header: "Refresh:0";
}
?>

this worked way better

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda