Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74735

get error message when using php and html to interact with mysql database

$
0
0

I'm creating a simple booking system for pet sitting using HTML and PHP. I planned to grab information from the user input

  • city
  • date
  • pet type

from HTML page as SQL statement criteria and POST using PHP to show how many sitters available in the database but it errors

criteria for SQL statement:

city from user input = citystate from pet_sitter table date from user input is not in the date_pickup in the Order table pet type from user input = pet_type in Pet_Sitter table using email as a foreign key.

Desire result

When clicking the "check availability", I want a new page called "result" page to show a table of information that meets the criteria from the MySQL database. Database structuresearch pageresult page

HTML page (index.php)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bring Your Pet to Work</title>
    <!-- Google font -->
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet">
    <!-- Bootstrap -->
    <link type="text/css" rel="stylesheet" href="css/bootstrap.min.css" />
    <!-- / Forms stylesheet -->
    <!-- <link rel="stylesheet" type="text/css" href="demo/demo.css" media="screen" /> -->
    <link rel="stylesheet" type="text/css" href="css/slick_rf.css" media="screen" />
    <!-- Custom stlylesheet -->
    <link type="text/css" rel="stylesheet" href="css/style.css" />

</head>
<body>
    <!--        MIT License        -->
    <nav role="navigation">
        <div id="menuToggle">
            <!--
    A fake / hidden checkbox is used as click reciever,
    so you can use the :checked selector on it.
    -->
            <input type="checkbox" />

            <!--
    Some spans to act as a hamburger.
    They are acting like a real hamburger,
    not that McDonalds stuff.
    -->
            <span></span>
            <span></span>
            <span></span>
            <ul id="menu">
                <a href="index.html">
                    <li>Home</li>
                </a>
                <a href="#">
                    <li>About</li>
                </a>
                <a href="register.html">
                    <li>Service Register</li>
                </a>
                <a href="#">
                    <li>Contact</li>
                </a>
                <a href="pet_sitter.html">
                    <li>Pet Sitter</li>
                </a>
            </ul>
        </div>
    </nav>
    <!--        MIT License        -->


    <div id="booking" class="section">
        <div class="section-center">
            <div class="container">
                <div class="row">
                    <div class="col-md-7 col-md-push-5">
                        <div class="booking-cta">
                            <h1>Bring Your Pet to Work</h1>
                            <p>Caring and Loving Pet service
                            </p>
                        </div>
                    </div>
                    <div class="col-md-4 col-md-pull-7">
                        <div class="booking-form">

<!--php stuffs-->
<form method="POST" action = "result.php">
                                <div class="form-group">
                                    <span class="form-label">Where do you work? </span>
                                    <input class="form-control" type="text" placeholder="Please enter your city" name="city">
                                </div>
                                <!-- date picker -->

                                <div class="row">
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <span class="form-label">Reserve date on</span>
                                            <input class="form-control" type="date", name = "date" required>
                                        </div>
                                    </div>

                                </div>


                                <div class="row">

                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <span class="form-label">Pet?</span>
                                            <select class="form-control" name = "pet">
                                                <option value = "cat">Cat</option>
                                                <option value = "dog">Dog</option>
                                                <option value = "others">Others<option>
                                            </select>
                                            <span class="select-arrow"></span>
                                        </div>
                                    </div>

                                </div>
                                <div class="form-btn">
                                    <button class="submit-btn" value = "available">Check availability</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <footer>
        <p class="copyright">©  70
        </p>
    </footer>


</body>

</html>

PHP page to show the result, file name (result.php)

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

    $conn = mysqli_connect('1', '2', '3','4');

//check connection
if (mysqli_connect_errno())
{echo nl2br("Failed to connect to MySQL: ". mysqli_connect_error() . "\n"); }
else
{ echo nl2br("Search results <br><br>");}

$city = mysqli_real_escape_string($conn, $_POST['city']);
$date = mysqli_real_escape_string($conn, $_POST['date']);
$pet = mysqli_real_escape_string($conn, $_POST['pet']);

$sql = "SELECT CONCAT(s.lname, '', s.fname) AS fullName, s.ratings, s.rate
        FROM Pet_Sitter AS s, Orders AS o
        WHERE s.email = o.email
        AND $city = s.citystate
        AND $pet = s.pet_type
        AND $date Not In o.date_pickup
        "
        ;
$result = $conn->query($sql);

if ($result=mysqli_query($conn,$sql))
  {
  // Return the number of rows in result set
  $rowcount=mysqli_num_rows($result);
  printf("%d Sitters Available.\n",$rowcount);
  }

$num_rows = mysqli_num_rows($result);


if ($result->num_rows > 0) {
    echo "<table border = '1'><tr><th> Sitter Name</th><th>ratings</th><th>rates</th></tr>";
    while ($row = $result->fetch_assoc()) {
    echo"<tr><td>" . $row['fullName'] . "</td><td>" . $row['s.rating'] . "</td><td>" . $row['s.rates'] . "</td></tr>";}
    echo"</table>";


}   else {
        echo "0 results";
    }
        mysqli_close($conn);

?>  


Viewing all articles
Browse latest Browse all 74735

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>