开发者

Blank Page after pressing Submit button with all fields filled up

as shown in the title, I have a page for users to create projects and another page to add it into my database. However when I press submit with the form fields empty, the page it post to isn't blank. But when I submit with the fields filled up, it just shows be a blank page without any errors and I have looked through both pages of codes but can't seem to find anything wrong. Perhaps someone here could help me out? Thanks.

//codes on page where data is submitted.

if ($_POST['projectTitle'] != "" && $_POST['projectStatus'] != "" && $_POST['projectDesc'] != "" && $_POST['projectDeliv'] != "" && $_POST['year'] != "" && $_POST['month'] != "" && $_POST['day'] != "" && $_POST['projectSS'] != "") {

        $host = "localhost";
        $user = "root";
        $pass = "";
        $db = "fyp1";

        $pt = $_POST['projectTitle'];
        $ps = $_POST['projectStatus'];
        $pdes = $_POST['projectDesc'];
        $pdel = $_POST['projectDeliv'];
        $date = $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['day'];
        $pss = $_POST['projectSS'];
        date_default_timezone_set('UTC+8');
        $cDate = date('Y-m-d');
        $uid = $_SESSION['id'];

        $link = mysqli_connect($host, $user, $pass, $db) or die(mysqli_error());
        $query = "SELECT * FROM project WHERE project_title = $pt AND project_description = $pdes AND project_deliverables = $pdel AND project_skillset = $pss";
        $dub = mysqli_query($link, $query) or die(mysqli_connect_error($link));

        if (mysqli_num_rows($dub) == 0) {

            $insertQ = "INSERT INTO project(project_title,project_description,project_deliverables,project_start,project_end,project_skillset,project_status)
                VALUES ('$pt','$pdes','$pdeliv','$cDate','$date','$pss',$ps)";
            mysqli_query($link, $insertQ) or die(mysqli_connect_error($link));

            $getPID = "SELECT * FROM project WHERE project_title = $pt AND project_description = $pdes AND project_deliverables = $pdel AND project_start = $cDate AND projecct_end = $date AND project_skillset = $pss";
            $pid = mysqli_query($link, $getPID) or die(mysqli_connect_error($link));
            if (mysqli_num_rows($pid) == 1) {
                while ($row = mysqli_fetch_array($pid)) {
                    $proid = $row['project_id'];
                    $insertF = "INSERT INTO user_has_project(user_id,project_id) VALUES ('" . $uid . "','" . $proid . "')";
                    mysqli_query($link,$insertF) or die(mysqli_connect_error($link));
                    $message = "<p>Project Successfully Added!</p>";
                    $message .= "<a href='index.php'>Back</a>";
                    $a = true;
                }
            } else {
                $message = "<p>Project Failed To Be Added!</p>";
                $message .= "<a href='createProject.php'>Back</a>";
                $a = false;
            }
        } else {
            $message = "<p>Duplicate Project Found!</p>";
            $message .= "<a href='createProject.php'>Back</a>";
            $a = false;
        }
    } else {
        $message = "<p>Please Fill Up All Fields When Creating A Project!</p>";
        $message .= "<a href='createProject.php'>Back</a>";
        $a = false;
    }

// codes on page with form

    <div id="content">
        <?php if ($a == false) {
        ?>
                <h2 id="registerFont">Create Project</h2>
                <form name="createProject" method="post" action="doCreateProject.php" onSubmit="return validateForm(this);">
                    <fieldset>
                        <table>
                            <tr>
                                <th colspan="4"><h2>New Project</h2></th>
                            </tr>
                            <tr>
                                <th colspan="4"><hr /></th>
                            </tr>
                            <tr>
                                <td><label for="projectTitle">Project Title:</label></td><td><input name="projectTitle" type="text" /></td>
                                <td><label for="projectStatus">Project Status:</label></td>
                                <td><select name="projectStatus">
                                <?php while ($row = mysqli_fetch_array($result1)) {
                                ?>
                                    <option value="<?php echo $row['status_id']; ?>" ><?php echo $row['status_type']; ?></option>
                                <?php } ?>
                            </select></td>
                    </tr>
                    <tr>
                        <td><label for="projectDesc">Project Description:</label></td><th colspan="3"><textarea name="projectDesc" rows="5" cols="40" ></textarea></th>
                    </tr>
                    <tr>
                        <td><label for="projectDeliv">Project Deliverables:</label></td><th colspan="3"><textarea name="projectDeliv" rows="5" cols="40" ></textarea></th&g开发者_运维技巧t;
                    </tr>
                    <tr>
                        <td>Start Date:</td><td><?php echo $date; ?></td>
                    </tr>
                    <tr>
                        <td>End Date : </td>
                        <th colspan="3" align="left">
                            <select name="year">
                                <option>---Year---</option>
                                <?php for ($i = $cYear; $i < ($cYear + 100); $i++) {
                                ?>
                                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
                                <?php } ?>
                            </select>
                            <select name="month">
                                <option>---Month---</option>
                                <?php while ($rows = mysqli_fetch_array($result)) {
                                ?>
                                    <option value="<?php echo $rows['month_id']; ?>"><?php echo $rows['month']; ?></option>
                                <?php } ?>
                            </select>
                            <select name="day">
                                <option>---Day---</option>
                                <?php for ($i = 1; $i < 32; $i++) {
                                ?>
                                    <option value="<?php echo $i ?>"><?php echo $i ?></option>
                                <?php } ?>
                            </select>
                        </th>
                    </tr>
                    <tr>
                        <td><label for="projectSS">Project Skill Set:</label></td><td><input name="projectSS" type="text"/></td><th colspan="2"><small>(Please Separate By Comma)</small></th>
                    </tr>
                </table>
            </fieldset>
            <br />
            <input name="submit" type="submit" value="Create Project" />
        </form>
        <?php
                            } else {
                                echo $message;
                            }
        ?>
                        </div>


I managed to solve the problem. When querying into the database, at my SELECT statement, the variables I forgot to add ''. E.g SELECT * FROM project WHERE project_title = '$variable';

Anyways. thanks for those who helped out. I really appreciate it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜