Info not appearing in an edit form

时间:2015-08-07 01:32:13

标签: php html mysqli

I am currently making an edit page, where you would click on a link to edit a specific user, it would bring you to edit.php?id= and it would show all their info they currently have set and what they don't have set. In which you could edit it to your liking then save it. I'm sort of getting used to mysqli as I recently transitioned over from mysql. When i load edit.php page up i get these errors in the text boxes: <br /><b>Notice</b>: Undefined variable: user in <b>C:\xampp\htdocs\edit.php</b> on line <b>13</b><br /> and the line changing depending on the text box.

Edit.php

<?php include_once('header.php'); ?>
    <?php include_once('classes/check.class.php'); ?>
    <?php include_once('config/db.php'); ?>


    <?php if( protectThis("1, 2, 3") ) : ?>

    <div id="newform">
        <form method="post" role="form">
            <div class="form-group">
                <label for="user">User</label>
                <input name="user" type="text" class="form-control" id="user" placeholder="Username" value="<?php echo $user; ?>"> 
            </div>
            <div class="form-group">
                <label for="position">Position</label>
                <input name="position" type="text" class="form-control" id="position" placeholder="GG" value="<?php echo $pos; ?>">
            </div>
            <div class="form-group">
                <label for="date">Date</label>
                <input name="date" type="text" class="form-control" id="date" placeholder="<?php echo date('d M y'); ?>" value="<?php echo $date; ?>">
            </div>
            <div class="form-group">
                <label for="tag">Tag</label>
                <input name="tag" type="text" class="form-control" id="tag" placeholder="blue" value="<?php echo $tag; ?>">
            </div>
            <div class="form-group">
                <label for="adt">ADT</label>
                <input name="adt" type="text" class="form-control" id="adt" placeholder="BINGO" value="<?php echo $adt; ?>">
            </div>
            <div class="form-group">
                <label for="exp">EXP</label>
                <input name="exp" type="text" class="form-control" id="exp" placeholder="420" value="<?php echo $exp; ?>">
            </div>
            <div class="form-group">
                <label for="reg">Regiment</label>
                <input name="reg" type="text" class="form-control" id="reg" placeholder="P" value="<?php echo $reg; ?>">
            </div>
            <div class="form-group">
                <label for="notes">Notes</label>
                <input name="notes" type="text" class="form-control" id="notes" placeholder="away" value="<?php echo $note; ?>">
            </div>
            <center>
            <button name="submit" value="submit" type="submit" class="btn btn-default">Submit</button>
            </center>
        </form>
    </div>

    <?php

    //Submitting the information from the form----------------------------------

    if(isset($_POST['submit'])){
    //Values to be inserted into the DB
    $user = $_POST['user'];
    $date = $_POST['date'];
    $tag  = $_POST['tag'];
    $pos  = $_POST['position'];
    $adt  = $_POST['adt'];
    $exp  = $_POST['exp'];
    $reg  = $_POST['reg'];
    $note = $_POST['notes'];

    //Preparing the statement
    $query = "INSERT INTO players (user, date, tag, position, adt, exp, reg, notes) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
    $statement = $mysqli->prepare($query);

    //Binding Parameters for markers, where (s = string, i = integer, d = double, b = blob)
    $statement->bind_param('sssssiss', $user, $date, $tag, $pos, $adt, $exp, $reg, $note);

    //Execution
    if($statement->execute()){
        header('Location: home.php');
    }else{
        die('Error : ('.$mysqli->errno .') '. $mysqli->error);
    }
    $statement->close();
    }

    // Grabbing the information for the form----------------------------------------

    if(isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0){

    $ids = $_GET['id'];

    $result = $mysqli->query("SELECT * FROM players WHERE id = $ids");

    $row = $result->fetch_array();

    if($row){
    $id   = $row['id'];
    $user = $row['user'];
    $date = $row['date'];
    $tag  = $row['tag'];
    $pos  = $row['position'];
    $adt  = $row['adt'];
    $exp  = $row['exp'];
    $reg  = $row['reg'];
    $note = $row['notes'];
    }else{}

    // Frees the memory associated with a result
    $result->free();

    }




    ?>

    <?php endif; ?>


    <?php include_once('footer.php'); ?>

0 个答案:

没有答案