Andrew Y Andrew Y - 7 months ago 13
SQL Question

html button (onlick) not working when sending data to mysql table

So I have a forms on a html page which retrieve data from a mysql table. The user can modify these data, or delete the entire row. I have a html button with functionality of deleting the entire row, and with that button I have a javascript function that displays a confirm pop up box confirming if the user wants to delete it. If they click yes then it is sent to another php page where the deletion is performed. The problem is when I click on the confirm box nothing happens, it just stays on the same page. Here is my html and javascript code:

<form class="form-inline" method=GET action="envoieModifierAlbumAdmin.php">
<table class="table table-striped">
<tr>
<td><button type="button" class="btn btn-danger" onclick="verif()">Supprimer Cet Album</button>
</td><td></td><td></td>
</tr>

<tr>
<td><label for="exampleInputName2">id: </label>
<input readonly type="text" class="form-control" value="<?php echo "$donnees[id]"?>" id="exampleInputName2" name="id">
</td><td></td><td></td>
</tr>
<tr>
<td><label for="exampleInputName2">Nom d'album: </label>
<input type="text" class="form-control" id="exampleInputName2" name="titre" value="<?php echo "$donnees[titre]"?>"></td>
<td></td><td></td>
</tr>
</table>
</form>
<script>
function verif(){
var x;
if(confirm("Vous êtes sûr que vous voulez supprimer ce compte?") == true){
document.location="supprimerAlbumAdmin.php?id=$_GET['id']";
}
else
}
</script>


The only problem is with the button, the other parts of the table above are just to show an example of what the user is modifying. Thanks in advance!

Answer

your value should be like this

value="<?php echo  $GET['id'] ?>"

not like this

value="<?php echo "$donnees[id]"?>"

and change button type into submit

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>


function verif(){
	alert("hi");
        var x;
        if(confirm("Vous êtes sûr que vous voulez supprimer ce compte?") == true){
            
			//window.location.replace("https://google.com");
			//exit();
          return true;
          
        }
        else
          {
            
            return false;
            
            }
        
    }
</script>
<form class="form-inline" method="GET" action="envoieModifierAlbumAdmin.php">
    <table class="table table-striped">


        <tr>
            <td><label for="exampleInputName2">id: </label>
                <input readonly type="text" class="form-control" value="" id="exampleInputName2" name="id">
            </td><td></td><td></td>
        </tr>
        <tr>
            <td><label for="exampleInputName2">Nom d'album: </label>
            <input type="text" class="form-control" id="exampleInputName2" name="titre" value=""></td>
            <td></td><td></td>
        </tr>
              <tr>
            <td><button type="submit" class="btn btn-danger" onclick="verif()">Supprimer Cet Album</button>
            </td><td></td><td></td>
        </tr>
    </table>
</form>