Commit 9ce59ab1 authored by Sorrel Harriet's avatar Sorrel Harriet
Browse files

removing unused file

parent 0a3688dd
$content = "<h1>Update Album Stock</h1>";
// define a variable with path to the script which will process form
// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php)
$action = $_SERVER["PHP_SELF"]."?page=update-stock";
// turn autocommit off
mysqli_autocommit($link, FALSE);
// start a transaction
mysqli_query($link, 'START TRANSACTION');
// fetch the albums and associated stock info
// apply FOR UPDATE to prevent reads until
// the transaction is completed with COMMIT or ROLLBACK
$sql = "SELECT a.upc, a.title, i.stock
FROM Album a
INNER JOIN Inventory i
ON a.upc=i.album_upc
$result = mysqli_query($link, $sql);
// check query returned a result
if ($result === false) {
echo mysqli_error($link);
} else {
$options = "";
// create an option for each artist
while ($row = mysqli_fetch_assoc($result)) {
$options .= "<option value='".$row['upc']."'>";
$options .= $row['title'];
$options .= "</option>";
// define the form HTML (would ideally be in a template)
$form_html = "<form action='".$action."' method='POST'>
<label for='t_name'>Name:</label>
<input type='text' name='t_name' required>
<label for='t_number'>Track number:</label>
<input type='number' name='t_number' min='1' max='25'>
<label for='a_upc'>Album:</label>
<select name='a_upc' required>
<option value='' disabled selected>Select an album</option>
<button type='submit'>Submit</button>
// append form HTML to content string
$content .= $form_html;
// ------- START form processing code... -------
// define variables and set to empty values
$title = $artist_id = $price = $year = $genre = "";
// check if there was a POST request
// validate the form data
$a_upc = mysqli_real_escape_string($link, clean_input($_POST["a_upc"]));
$t_name = mysqli_real_escape_string($link, clean_input($_POST["t_name"]));
$t_number = mysqli_real_escape_string($link, clean_input($_POST["t_number"]));
// define the insertion query
$sql = sprintf("INSERT INTO Track (album_upc, name, track_number)
VALUES ('%s', '%s', %d)", $a_upc, $t_name, $t_number);
// run the query to insert the data
$result = mysqli_query($link, $sql);
// check if the query went ok
if ($result === false) {
mysqli_rollback($link); // if query returns false, rollback transaction
// handle specific errors based on mysli error number code
// (in order to output more useful message to user!)
$errno = mysqli_errno($link);
switch ($errno) {
case 1062 : // case for duplicate entry
$content .= "There is already a track with that name or number.";
default :
echo mysqli_error($link);
} else {
mysqli_commit($link); // else, commit transaction
$content .= "Track successfully added.";
// ------- END form processing code... -------
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment