Cheri Anne 0 Newbie Poster

How do I echo selected option?

<?php
    session_start();
        if(isset($_SESSION['cherianne'])){
        }else{
            header("Location:login.php");
        }

    include("../includes/header.php");

    // Retrieve our critical page setter variable.
    $char_id = $_GET['id']; 
    //echo "<h1>$char_id</h1>";
    // set this as a default value
    if (!isset($char_id)) {
        $result = mysqli_query($con, "SELECT bid FROM cde_blog LIMIT 1");
        while ($row = mysqli_fetch_array($result)) {
            $char_id = $row['id'];
        }
    }
    // Step 3: UPDATE the DB with the new info from the form. Validate first.
    if(isset($_POST['mysubmit'])) {

        $title = strip_tags(trim($_POST['title']));
        $message = strip_tags(trim($_POST['message']));
        //echo "$title, $message";
        $valid = 1;
        $msgPre = "<div class=\"alert alert-success\">";
        $msgPreError = "<div class=\"alert alert-danger\">";
        $msgPost = "</div>\n";
        // Title Validation
        if((strlen($title) < 2) || (strlen($title) > 50)) {
            $valid = 0;
            $valTitleMsg = "Please enter a title from 2 to 50 characters.<br>";
        }

        // Description Validation
        if ((strlen($message) < 10) || (strlen($message) > 1000)) {
            $valid = 0;
            $valMessageMsg = "\nPlease enter your message in 10 to 1000 characters.<br>";
        }

        // SUCCESS. Validation has been successful, so go ahead and put info in the DB
        if ($valid == 1) {

            $msgSuccess = "ENTRY ADDED!";
            $newTitle = $_POST['title'];
            $newMessage = $_POST['message'];
            mysqli_query($con, "UPDATE cde_blog SET
                cde_title = '$newTitle', 
                cde_message  = '$newMessage'
                WHERE bid = $char_id;
                ") or die(mysqli_error($con));
        }
    }// if submitted
    // STEP 1: Create list of items that the user can select from.
    $result = mysqli_query($con, "SELECT * FROM cde_blog") or die(mysqli_error($con));
    while ($row = mysqli_fetch_array($result)) {
        $title = $row['cde_title'];
        $message = $row['cde_message'];
        $id = $row['bid'];

        $editOptions .= "\n\t\t<option value=\"edit.php?id=$id\">" .$title ."</option><br>";
    }
    // STEP 2: Grab data for select character and prepopulate from field.
    $result = mysqli_query($con, "SELECT * FROM cde_blog WHERE bid = '$char_id'") or die(mysqli_error($con));
    while ($row = mysqli_fetch_array($result)) {

        $title = $row['cde_title'];
        $message = $row['cde_message'];
        $id = $row['bid'];

    }
?>
<h2>Edit Blog Entries</h2>
<form id="myform" name="myform" method="post" action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?>">
    <div class="form-group">
        <select name="entryselect" class="form-control" onchange="go()" >
            <option>--select a blog entry to edit--</option>
            <option value=" "<?php if ($char_id = 'id') { echo 'selected'; } ?>><?php echo $editOptions ?></option>
        </select>
    </div>
    <div class="form-group">
        <label for="title">Title:</label>
        <input type="text" name="title" class="form-control" value="<?php if($title) {echo $title;} ?>">
        <?php if ($valTitleMsg){echo $msgPreError .$valTitleMsg .$msgPosts;} ?>
    </div>
    <div class="form-group">
        <label for="message">Message:</label>
        <textarea name="message" class="form-control"><?php if($message) {echo $message;} ?></textarea>
        <?php if ($valMessageMsg){echo $msgPreError .$valMessageMsg .$msgPosts;} ?>
    </div>
    <div> <!--Emoticon Editor-->
        <a href="javascript:emoticon(':D')"><img src="../emoticons/icon_biggrin.gif"></a>
        <a href="javascript:emoticon(';)')"><img src="../emoticons/icon_wink.gif"></a>
        <a href="javascript:emoticon(':(')"><img src="../emoticons/icon_sad.gif"></a>
        <a href="javascript:emoticon('?')"><img src="../emoticons/icon_question.gif"></a>
        <a href="javascript:emoticon('-->')"><img src="../emoticons/icon_arrow.gif"></a>
    </div>
    <div class="form-group">
        <label for="submit">&nbsp;</label>
        <input type="submit" name="mysubmit" class="btn btn-info" value="Edit">
    </div>
    <?php
        if ($msgSuccess){
            echo $msgPre.$msgSuccess. $msgPost;
        }
    ?>
</form>
<?php
    include("../includes/footer.php");
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.