Jump to content

consists of creating a database in phpmyadmin and creating pages to manage ALL tables with php. I have the template but I am not able to change some information


LuisMiguel

Recommended Posts

I have the template and I´m changing the information but it´s always giving error

for example the delete and insert aren´t working:

<h1 style='text-align: center;'>Gestão das Consultas</h1>

<?php
    if(isset($_GET['a'])) {
        if($_GET['a']==1) {
            
                $stmt = $mysqli->prepare("DELETE from consulta where id_consulta=?");
                $stmt->bind_param("i", $_GET['id']);
                $stmt->execute();
                $stmt->close();
                
        }    
        if($_GET['a']==2) {
        if($stmt = $mysqli->prepare("Select id_consulta, id_veterinario, id_animal, data, preco from consulta where id_consulta")) {
        $stmt->bind_param("sssss", $_GET['id']);
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($id_consulta, $id_veterinario, $id_animal, $data, $preco);
        $num_rows = $stmt->num_rows;
        $stmt->fetch();
        echo "$id_veterinario, $id_animal, $data, $preco <br>";
        $stmt->close();
        }    

        ?>
        <div class="col-12 mb-3 mb-lg-5">
                                    <div class="card h-100">
                                        <div class="card-header">
                                            <h5 class="mb-1">Editar Consultas</h5>
                                        </div>
                                        <div class="card-body">
                                            <form class="row g-3" action="index.php?mod=consultages&a=5&id=<?php echo $_GET['id']; ?>"
                                                <div class="col-12">
                                                  <label for="inputAddress" class="form-label">Veterinário</label>
                                                  <input type="text" class="form-control" id="nome" name= "nome" value="<?php echo $id_veterinario; ?>"
                                                  placeholder="Edite o veterinário" required>
                                                </div>
                                                <div class="col-12">
                                                  <label for="inputAddress" class="form-label">Animal</label>
                                                  <input type="float" class="form-control" id="nome" name= "nome" value="<?php echo $id_animal; ?>"
                                                  placeholder="Edite o animal" required>
                                                </div>
                                                <div class="col-12">
                                                  <label for="inputAddress" class="form-label">Data</label>
                                                  <input type="float" class="form-control" id="date" name= "nome" value="<?php echo $data; ?>"
                                                  placeholder="Edite a data" required>
                                                </div>
                                                <div class="col-12">
                                                  <label for="inputAddress" class="form-label">Preço</label>
                                                  <input type="float" class="form-control" id="nome" name= "nome" value="<?php echo $preco; ?>"
                                                  placeholder="Edite o preço" required>
                                                </div>
                                                <div class="col-12">
                                                  <button type="submit" class="btn btn-primary">Editar</button>
                                                </div>
                                              </form>
                                        </div>
                                    </div>
                                </div>

        <?php        
        return;
    }
        
        else if($_GET['a']==3) {
            ?>
            <div class="col-12 mb-3 mb-lg-5">
                                    <div class="card h-100">
                                        <div class="card-header">
                                            <h5 class="mb-1">Inserir Consultas</h5>
                                        </div>
                                        <div class="card-body">
                                                <form class="row g-3" action="index.php?mod=consultages&a=5&id=<?php echo $_GET['id']; ?>"
                                                <div class="col-12">
                                                  <label for="inputAddress" class="form-label">Veterinário</label>
                                                  <input type="text" class="form-control" id="nome" name= "nome" value="<?php echo $id_veterinario; ?>"
                                                  placeholder="Insira o veterinário" required>
                                                </div>
                                                <div class="col-12">
                                                  <label for="inputAddress" class="form-label">Animal</label>
                                                  <input type="float" class="form-control" id="nome" name= "nome" value="<?php echo $id_animal; ?>"
                                                  placeholder="Insira o animal" required>
                                                </div>
                                                <div class="col-12">
                                                  <label for="inputAddress" class="form-label">Data</label>
                                                  <input type="float" class="form-control" id="date" name= "nome" value="<?php echo $data; ?>"
                                                  placeholder="Insira a data" required>
                                                </div>
                                                <div class="col-12">
                                                  <label for="inputAddress" class="form-label">Preço</label>
                                                  <input type="float" class="form-control" id="nome" name= "nome" value="<?php echo $preco; ?>"
                                                  placeholder="Insira o preço" required>
                                                </div>
                                                <div class="col-12">
                                                  <button type="submit" class="btn btn-primary">Inserir</button>
                                                </div>
                                              </form>
                                        </div>
                                    </div>
                                </div>
                                
            <?php
            return;
        }
        else if($_GET['a']==4) {

                $stmt = $mysqli->prepare("INSERT INTO consulta VALUES (null, ?)");
                $stmt->bind_param('s', $_POST['consulta']);
                $stmt->execute();
                echo "$stmt->affected_rows registos inseridos";
                $stmt->close();
            
            return;
        }    
        
        else if($_GET['a']==5) {
            $stmt = $mysqli->prepare("Update consulta set consulta=? where id_consulta=?");
            $stmt->bind_param("si", $_POST['consulta'], $_GET['id']);
            $stmt->execute();
            echo "$stmt->affected_rows registos inseridos";
            $stmt->close();    
        
        return;
        }
    }
        
?>
                <div class='col-12 mb-3 mb-lg-5'>
                  <div class='position-relative card table-nowrap table-card'>
           
                    <div class='table-responsive'>
                      <table class='table mb-0'>
                        <thead class='small text-uppercase bg-body text-muted'>
                          <tr>
                            <th>ID</th>
                            <th>Veterinário</th>
                            <th>Animal</th>
                            <th>Data</th>
                            <th>Preço</th>
                            <th>Actions</th>
                          </tr>
                        </thead>
                        <tbody>
                        
                        
                            <?php
                                if($stmt = $mysqli->prepare("SELECT c.id_consulta, v.nome AS nome_veterinario, a.nome AS nome_animal, c.preco, c.data_consulta FROM consulta c INNER JOIN veterinario v ON c.id_veterinario = v.id_veterinario INNER JOIN animal a ON c.id_animal = a.id_animal ORDER BY c.id_consulta")) {
                                    $stmt->execute();
                                    $stmt->store_result();
                                    $stmt->bind_result($id_consulta, $nome_veterinario, $nome_animal, $preco, $data);
                                    $num_rows = $stmt->num_rows;
                                    while ($stmt->fetch()) {
                                        echo "
                                        <tr class='align-middle'>
                                            <td>$id_consulta</td>
                                            <td>$nome_veterinario</td>
                                            <td>$nome_animal</td>
                                            <td>$preco €</td>
                                            <td>$data</td>
                                            <td>
                                              <a href='index.php?mod=consultages&a=1&id=$id_consulta' class='btn btn-danger'>APAGAR</a>
                                              <a href='index.php?mod=consultages&a=2&id=$id_consulta' class='btn btn-info' >EDITAR</a>
                                            </td>
                                          </tr>
                                        ";
                                    }
                                    
                                    $stmt->close();
                                }
                            ?>
                        
                    
                          
                        </tbody>
                      </table>
                      <a href='index.php?mod=consultages&a=3' class='btn btn-success'>INSERIR</a>
                    </div>
                  </div>
                </div>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.