FATAL ERROR:在布尔值ON SELECT OPTION上调用成员bind_param()

时间:2017-05-27 19:14:31

标签: php mysqli error-handling

您好看了其他已回答的问题,但一直无法修复我的问题。基本运行查询到数据库每个都在文本字段上发布,但是当涉及选择选项时,它返回此错误。 Prepare failed: (0) Fatal error: Call to a member function bind_param() on boolean in /home/assessment.php on line 32。通过在问题来源的时间查询一个字段来对所有内容进行条带化,我发现是在发布选择选项的时候。

下面是我的完整代码。

<?php
session_start();
//error_reporting(E_ALL); ini_set('display_errors', 1);


if(!isset($_SESSION['user_type'])){
header('Location: index.php');
}

// include file
require_once('include/connection.php');

// define user session
$userId = $_SESSION['user_id'];
$userName = $_SESSION['user_name'];

                $error = [] ;
                $status = "";
                if(isset($_POST['submit']))    {

                        $priority = trim($_POST['priority']);
                        $services = trim($_POST['services']);                  
                        $therapist = implode(' / ', $_POST['therapist']);     

                        $created_at = date('Y-m-d');
                        $stmt = $con->stmt_init();  
                        if(!($stmt = $con->prepare("INSERT INTO assessment (priority, services, therapist, created_at) 
                                VALUES (?,?,?,?)"))) {
                                echo "Prepare failed: (" . $con->errno . ")" . $con->error;
                        }

                        if(!$stmt->bind_param('ssss', $priority, $services, $therapist, $created_at)){
                         echo "Binding paramaters failed:(" . $stmt->errno . ")" . $stmt->error;
                        }

                        if(!$stmt->execute()){
                         echo "Execute failed: (" . $stmt->errno .")" . $stmt->error;
                        }

                        if($stmt) {
//                   $_SESSION['main_notice'] = '<div class="alert alert-success">"Access Code Added successfully!"</div>';
                                        $status = '<div class="alert alert-success">Client Added successfully!</div>';

                                        }else{
                                            $status = '<span class="alert alert-danger">Error in your query</div>';
                                        }

                            $stmt->close();
                }                      

    // title page
    $title = "New Assessment Record Entry | Task Allocation ";

    // include header
    require_once('include/header.php');
?>

<!-- ====================================================
================= CONTENT ===============================
===================================================== -->
<section id="content">

<div class="page page-shop-single-order">

<div class="pageheader">

<h2>New Accessment Record <span>// please complete below form details and information</span></h2>

<div class="page-bar">

        <ul class="page-breadcrumb">
                <li>
                        <a href="index.php"><i class="fa fa-home"></i> Task Allocation</a>
                </li>
                <li>
                        <a href="client.php">Client Records</a>
                </li>
                <li>
                        <a href="#">Client Details</a>
                </li>
        </ul>

</div>

</div>


<!-- row -->
<div class="row">
<!-- col -->
<div class="col-md-12">

<!-- tile -->
<section class="tile">

<!-- tile header -->
<div class="tile-header dvd dvd-btm">
<h1 class="custom-font"><strong>Assessment</strong> Information</h1>
<ul class="controls">
            <li class="dropdown">

                    <a role="button" tabindex="0" class="dropdown-toggle settings" data-toggle="dropdown">
                            <i class="fa fa-cog"></i>
                            <i class="fa fa-spinner fa-spin"></i>
                    </a>

                    <ul class="dropdown-menu pull-right with-arrow animated littleFadeInUp">

                            <li>
                                    <a role="button" tabindex="0" class="tile-refresh">
                                            <i class="fa fa-refresh"></i> Refresh
                                    </a>
                            </li>

                    </ul>

             </li>
</ul>
</div>
<!-- /tile header -->

<?php if(isset($status)){ echo $status; }?>


<!-- tile body -->
<div class="tile-body">

<p class="text-muted">Please enter your client personal details below. </p>

<br>

<form name="assessmentRecord" role="assessmentRecord" id="client_form" data-parsley-validate="" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" autocomplete='off'>

                 <div class="row">

                            <div class="form-group col-sm-6 col-md-3">
                                    <label for="services"><strong>Servcies:</strong> </label>
                                        <select name="services" class="form-control underline-input" placeholder="Select Servcie Option" value='<?php //echo $_POST['services']; ?>'
                                                        data-parsley-trigger="change"
                                                        required-no>
                                                <option value="">Select Servcie Option...</option>
                                                <option value="Repid Response Team">Rapid Response Team</option>
                                                <option value="Supported Discharge Team">Supported Discharge Team</option>
                                                <option value="Early Supported Discharge">Early Supported Discharge</option>                                                
                                        </select> 

                            </div>  
                         <div class="form-group col-sm-6 col-md-3">
                                    <label for="priority"><strong>Priorty Visit: </strong></label>
                                            <select name="priority" class="form-control underline-input"
                                                            data-parsley-trigger="change"
                                                            required-no>
                                                    <option value=>Select Priorty...</option>
                                                    <option value="essential">Essential</option>
                                                    <option value="non-essential">Non-Essential</option>
                                            </select>                                           
                            </div>  
                <div class="form-group col-sm-6 col-md-4">
                <label for="therapist"><strong>Senior Practitional / SP: </strong></label>                                                
                        <select name="therapist" class="form-control selectpicker"

            <?php
                require_once('include/database.php');


            //                      // read current record's data
                    try {
                            // prepare select query
                            $getUser = "select firstname, lastname, profession from user WHERE user_type = 'therapist'";
                            $stmt = $con->prepare( $getUser );

                            // execute our query
                            $stmt->execute();

                            // store retrieved row to a variable
                            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){

                            // values to fill up our form
                            $firstname = $row['firstname'];
                            $lastname = $row['lastname'];
                            $profession = $row['profession'];


                                echo '<option id="firstname_'.$row['id'].'" value="'. $row['id'] .'">'.$row['firstname'] . ' ' . $row['lastname'] . ' - ' . $row['profession'].'</option> ';

                            }


                    }

                    // show error
                    catch(PDOException $exception){
                            die('ERROR: ' . $exception->getMessage());
                    }

            ?>
                    </select>                                           
            </div>  

                    </div>


                    <div class="form-group text-left mt-20">
                        <button type="submit" class="btn btn-primary pull-right"  name="submit" id='submit'>ADD RECORD</button>
                    <!--                             <label class="checkbox checkbox-custom-alt checkbox-custom-sm inline-block">
                                        <input type="checkbox"><i></i> Remember me
                                </label> -->
                         <a href="assessment.php">
                             <button type="button" class="btn btn-greensea b-0 br-2 mr-5">Back To Records</button>
                        </a>
                     </div>


</form>


</div>
<!-- /title body -->
</section>

</div>
<!-- /col -->

</div><!-- /row-->
</div><!-- page -->
</section>
<!--/ CONTENT -->



<!-- ============================================
============== INCLUDE FOOTER ===============
============================================= -->

<?php include_once 'include/footer.php'; ?>
也许你可能会看到遗漏的东西。感谢

0 个答案:

没有答案