0
Hello, I have the following code and I need to pick up a student’s class at the bank and if yes to confirm
in JS: "climb" your class.
Ex: The student is 1A, I press the button to go up and he needs to go to 2A (but it won’t be just one, by pressing this button everyone will go up too).
The code as it is below enters the confirm
but if clicked on OK
, the page is blank because it does nothing but.
I understand that it has flaws but I can’t think of anything (seriously, help ;-;) and I would like someone to help me :v (so that’s just the idea of what I need)
<script>
function up()
{
<?php
include ('connection.php');
$busca = $con->prepare("SELECT * FROM turmas;");
$busca->execute();
$linha = $busca->fetch(PDO::FETCH_ASSOC);
if($linha['turma'].equals("1A"))
{
$sql = "UPDATE carterinha SET turma = '2A';";
$stmt = $conn->prepare($sql);
try
{
$stmt->execute();
echo '
<script>
alert("Turmas upadas!");
location.replace("../../index.php");
</script>
';
} catch(PDOException $e)
{
echo '
<script>
alert("Falha! Tente novamente!");
location.replace("../../index.php");
</script>
';
}
}
?>
}
</script>
<?php
echo '
<script>
if(confirm("Deseja realmente upar as turmas?"))
{
up();
alert("Turmas upadas!");
location.replace("../../index.php");
} else
{
alert("Up turma cancelado");
location.replace("../../index.php");
}
</script>
';
?>
Hello java script is in the client part, and php on the server is not possible to mix the two so it is necessary to send through a post or get to the server with a form or via Javascript and on the save server.
– Renan Chaves
I understand... Any suggestions of what I can do, at least in "climbing" the classes :v or making this confirm with php somehow?
– Vitor Pessan
It’s just, from what I’ve seen, you’re starting now, right? if yes a hint would be to start studying only php with html then add the simplest to understand java script.
– Renan Chaves