Data

As a PHP based website one main feature of the site is the form which displays the list of drinks that are available for the users after the budget is inputed, after the user has submitted their budget the user will receive the feedback of alcoholic beverages they can drink, under this text is the code that was used.

<?php

define(“DB_SERVER”, “localhost”);
define(“DB_USER”, “tpaine”);
define(“DB_PASS”, “**********”);
define(“DB_NAME”, “tpaine”);

$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

if(mysqli_connect_errno()) {
die(“Database connection failed: ” .
mysqli_connect_error() .
” (” . mysqli_connect_errno() . “)”
);
}
?>

index.php – The index file acts as the central focus of the website, primarily it’s used to store all the code that is in the homepage of the website. In the code is the mysqli_query that sends a request to the database and the html form that the request is linked to:

<div class=”container”>

<head>

</head>

<h1>Prinks</h1>
<p>Enter your budget below and find out what you can afford for pre-drinks!</p>
<form action=”index.php” method=”post”>
£ <input type=”text” name=”price”>
<input type=”submit” name=”price-sort” value=”Get Drinks”>
</form>

<?php while($drink = mysqli_fetch_assoc($result)) { ?>

<h2><?php echo $drink[“name”]; ?> – <?php echo $drink[“category”]; ?></h2>

<p>£<?php echo $drink[“price_per_lt”]; ?></p>

<?php } ?>

</div>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s