Im having a trouble getting my data from mysql db using $_POST

by Sherwin Estrera   Last Updated July 12, 2019 14:26 PM - source

I cant get the data from my db which I need to display it.

<label style="font-size:20px"><b>Doctor:</b></label><br>
        <select name="doctor" id="doctor-list" class="demoInputBox" style="width:100%;height:35px;border-radius:9px">
        <option value="">Select Doctor</option>
        $sql1="SELECT * FROM doctor where did in(select did from doctor_availability where cid in (select cid from manager_clinic where mid=$mid));";
        while($rs=$results->fetch_assoc()) { 
        <option value="<?php echo $rs["did"]; ?>"><?php echo "Dr. ".$rs["name"]; ?></option>

        <input type="date" name="dateselected" required><br><br>
            <button type="submit" style="position:center" name="submit" value="Submit">Submit</button>

        include 'dbconfig.php';
        $sql1 = "SELECT * FROM book WHERE DOV='". $_POST['dateselected']."' AND DID= $did AND CID= $cid order by Timestamp ASC";

I have a table book there is lot of values there. If I choose the date it must be display all of the same values where dates are the same.


thats my values from book table

It just display the value with CID = 1



Tags : php mysql

Answers 1

I am not entirely sure, but I think you need JOINs and definitely you need prepared statements. See my code below. I used JOINs to connect the 3 tables together and then I used your session value to match the mid.

if (isset($_POST['submit'])) {
    include 'dbconfig.php';

    $stmt = $conn->prepare('SELECT * FROM book 
        JOIN doctor_availability USING(did)
        JOIN manager_clinic USING(cid)
        WHERE dov=? AND did=? AND mid=?');
    $stmt->bind_param('sii', $_POST['dateselected'], $_POST['doctor'], $_SESSION['mgrid']);
    $results1 = $stmt->get_result();
July 12, 2019 13:51 PM

Related Questions

Mysql Can't create/write to file error#13

Updated April 16, 2018 11:26 AM