dimanche 1 novembre 2020

The variables in an IF-Statement arent working

I´m trying to get some code working to upload some text to my database. The problem is that apparently my variable isnt passed throught to my IF-Statement. I literly tried everything. I hope you can help me. If you need more code snippets to work with im willing to give more.

I also use the jquery-tabledit from markcell. Github: https://github.com/markcell/jquery-tabledit

Here is the code of my index page:

    <?php 
                $id= $_GET["id"];
                $ser = $id."_ser";
                $wdh = $id."_wdh";
                $br  = $id."_br";
                $max  = $id."_max";
                $is  = $id."_is";
include_once("db_connect.php");
include("live_edit.php");
?>

And here is the code of my live_edit.php:

<?php
include_once("db_connect.php");
$input = filter_input_array(INPUT_POST);
if ($input['action'] == 'edit') {   
    $update_field='';
    if(isset($input[$ser])) {
        $update_field.= "$ser='".$input[$ser]."'";
    } else if(isset($input[$wdh])) {
        $update_field.= "$wdh='".$input[$wdh]."'";
        }
        else if(isset($input[$br])) {
            $update_field.= "$br='".$input[$br]."'";
            }
    if($update_field && $input['id']) {
        $sql_query = "UPDATE nameanddsc SET $update_field WHERE id='" . $input['id'] . "'"; 
        mysqli_query($conn, $sql_query) or die("database error:". mysqli_error($conn));     
    }
}
?>

Html Code of index.php

<?php 
                $id= $_GET["id"];
                $ser = $id."_ser";
                $wdh = $id."_wdh";
                $br  = $id."_br";
                $max  = $id."_max";
                $is  = $id."_is";
include_once("db_connect.php");
include("live_edit.php");
?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<title>Sportarten ändern</title>
<script type="text/javascript" src="dist/jquery.tabledit.js"></script>
<?php include('container.php');?>    
<h1>Normale Aufgaben</h1>
    <table id="data_table" class="table table-striped">
        <thead>
            <tr>
                <th>Nummer</th>
                <th>Name</th>
                <th>Serie</th>
                <th>Wdhl</th>
                <th>Pause</th>
                <th>Maximal</th>
                <th>Ist-Wert</th>
            </tr>
        </thead>
        <tbody>
            <?php 
            
            $sql_query = "SELECT * FROM nameanddsc WHERE id <= 24 AND name!='' ORDER BY id";    
            $resultset = mysqli_query($conn, $sql_query) or die("database error:". mysqli_error($conn));
            while( $row = mysqli_fetch_assoc($resultset) ) {
            ?>
               <tr id="<?php echo $row ['id']; ?>">
               <td><?php echo $row ['id']; ?></td>
               <td><?php echo $row ['name']; ?></td>
               <td><?php echo $row [$ser]; ?></td>
               <td><?php echo $row [$wdh]; ?></td> 
               <td><?php echo $row [$br]; ?></td>
               <td><?php echo $row [$max]; ?></td>  
               <td><?php echo $row [$is]; ?></td>    
               </tr>
            <?php } ?>
        </tbody>
    </table>

        <h1>Zeitliche Aufgaben</h1>
        <table id="data_table1" class="table table-striped">
        <thead>
            <tr>
            <th>Nummer</th>
                <th>Name</th>
                <th>Serie</th>
                <th>Wdhl</th>
                <th>Pause</th>
                <th>Maximal</th>
                <th>Ist-Wert</th>
            </tr>
        </thead>
        <tbody>
            <?php 
            $sql_query = "SELECT * FROM nameanddsc WHERE id >= 25 AND name!='' ORDER BY id";        
            $resultset = mysqli_query($conn, $sql_query) or die("database error:". mysqli_error($conn));
            while( $row = mysqli_fetch_assoc($resultset) ) {
            ?>
               <tr id="<?php echo $row ['id']; ?>">
               <td><?php echo $row ['id']; ?></td>
               <td><?php echo $row ['name']; ?></td>
               <td><?php echo $row [$ser]; ?></td>
               <td><?php echo $row [$wdh]; ?></td> 
               <td><?php echo $row [$br]; ?></td>
               <td><?php echo $row [$max]; ?></td>  
               <td><?php echo $row [$is]; ?></td>
               </tr>
            <?php } ?>
        </tbody>
    </table>    

<script type="text/javascript">
$(document).ready(function(){
    $('#data_table').Tabledit({
        deleteButton: false,
        editButton: false,          
        columns: {
          identifier: [0, 'id'],                    
          editable: [[2, '<?php echo $ser; ?>'], 
          [3, '<?php echo $wdh; ?>'], 
          [4, '<?php echo $br; ?>']]
        },
        hideIdentifier: false,
        url: 'live_edit.php'        
    });
});
$(document).ready(function(){
    $('#data_table1').Tabledit({
        deleteButton: false,
        editButton: false,          
        columns: {
          identifier: [0, 'id'],                    
          editable: [[1, 'name'], [2, 'dsc']]
        },
        hideIdentifier: false,
        url: 'live_edit.php'        
    });
});
</script>

Aucun commentaire:

Enregistrer un commentaire