Question

so I'm new to php and I have two buttons on this html page here (the id value is included in the url):

<!DOCTYPE html>
<head>

<title>StoryBlox is a Social Story Builder Tool</title>

<meta charset="utf-8">
<!-- these support the header/footer formatting -->
<link type="text/css" rel="stylesheet" href="css/main.css">
<link type="text/css" rel="stylesheet" href="css/header_footer.css">
<script src="js/header.js"></script>
<?php //include_once 'confirm_login.php' 
    include_once 'story_manager.php';
    include_once 'open_connection.php';
    //include_once 'functions.php';
    //sec_session_start();
    if(isset($_GET['id'])){
        $str_id = $_GET['id'];
        $draft_id = get_story_attribute($str_id, 'draft');
    }else{
        echo "Invalid story id.";
        echo "<br>";
    }
    ?>

</head>

<body>
<div id="wrapper_main">
    <div id="wrapper_content">

        <?php include_once 'header.php'; ?>

        <h1>Welcome to StoryBlox Create Story!</h1>

    </div>
    <!-- menu -->
    <!--<div id="inputs"> -->
    <form id="create_form" action="save_story.php?id=<?php echo $str_id?>" method="POST">
        <input type="text" name="storyTitle" id="title" placeholder="Enter title." autofocus/><br>
        <textarea rows="4" cols="50" name="storyDesc" id="description" placeholder="Enter description here."></textarea>

        <div id="footer">
            <input type="button" name="draftBtn" onclick="this.form.submit()" value="Save as Draft"/>
            <input type="button" name="finalBtn" onclick="this.form.submit()" value="Finished!"/>
        </div>
    </form>

    </div>
</div>
<?php include_once 'footer.php'; ?>
</body>

When I click one of these two buttons, I'm brought to this php document here:

include_once 'open_connection.php';
include_once 'story_manager.php';
$mysqli = open_connection();

if($_SERVER['REQUEST_METHOD'] === 'POST'){
if(isset($_POST['draftBtn'])){
    $title = $_POST['storyTitle'];
    $desc = $_POST['storyDesc'];
    $str_id = $_GET['id'];
    update_story_title($str_id, $title);
    //update_story_description($str_id, $desc);
    header('Location: createStory.php');
}
elseif(isset($_POST['finalBtn'])){
    $title = $_POST['storyTitle'];
    $desc = $_POST['storyDesc'];
    $str_id = $_POST['storyID'];
    update_story_title($str_id, $title);
    //update_story_description($str_id, $desc);
    save_draft_as_completed($str_id);
    header('Location: ../home.php');
}else{ echo "failed";}
}?>

And I always get "failed" printed out on my page. I've been Googling this for hours and I don't understand where I'm going wrong here. If anybody could help that would be appreciated. Also, if anyone could shed some light on what the equivalent to

<input type="textarea"> 

would be that would be great. Thanks!

Was it helpful?

Solution

Use

 <input type="submit" name="draftBtn" value="Save as Draft"/>

instead of the button types with their onclick events.

OTHER TIPS

try to use submit tag instead of button. and if you want to use button tag then you can pass value through hidden field. set value of hidden field on click event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top