Show Code:
piece-create.php
<?php include 'session.php'; ?> <!DOCTYPE html>
<html>
<head>
<title>Alexandria</title>
<link href="style1.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body onload="initMap()">
<?php include 'nav.php'; ?>
<?php include 'db-connect.php'; ?>
<main>
<?php
//handle initial create page
if( $_POST['piece_name']==''){
?>
<form method="post" action="piece-create.php" enctype="multipart/form-data">
<label>Art Piece: </label>
<input type="text" name="piece_name" required>
<!--Create the artist select menu-->
<label>Artist: </label>
<select name="artist_fk">
<?php
$sql="SELECT * FROM t_artists ORDER BY artist_name";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result)){
echo '<option value="'.$row['artist_id'].'">'.$row['artist_name'].'</option>';
echo PHP_EOL;
}
?>
</select>
<!--End the artist select menu-->
<!--Create the medium select menu-->
<label>Medium: </label>
<select name="medium_fk">
<?php
$sql="SELECT * FROM t_mediums ORDER BY medium_name";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result)){
echo '<option value="'.$row['medium_id'].'">'.$row['medium_name'].'</option>';
echo PHP_EOL;
}
?>
</select>
<!--End the medium select menu-->
<!--Get Image File From User-->
<label>Image: </label>
<input type="file" name="fileToUpload" id="fileToUpload">
<!--End Get Image File-->
<!--Google Maps API Location-->
<label>Location: </label>
<div id="search-container">
<input id="search-input" type="text" placeholder="Search for Location">
<button id="search-button" type="button" onclick="searchLocation()">Search</button>
</div>
<div id="map"></div>
<label for="lng">Longitude:</label>
<input type="text" id="lng" name="piece_longitude">
<label for="lat">Latitude:</label>
<input type="text" id="lat" name="piece_latitude">
<label for="city">City:</label>
<input type="text" id="city" name="city">
<!--End Google Maps API Location-->
<input type="submit" value="Create">
</form>
<!--Google Map with Search Bar-->
<?php
}
//handle recursive form
else{
$piece_name=$_POST['piece_name'];
$artist_fk=$_POST['artist_fk'];
$medium_fk=$_POST['medium_fk'];
$piece_longitude=$_POST['piece_longitude'];
$piece_latitude=$_POST['piece_latitude'];
include 'image-handler.php';
$sql='INSERT INTO t_pieces (piece_name, artist_fk, medium_fk,location_fk,piece_image,piece_longitude,piece_latitude)
VALUES ("'.$piece_name.'","'.$artist_fk.'","'.$medium_fk.'",1,"'.$target_file.'","'.$piece_longitude.'","'.$piece_latitude.'")';
if(mysqli_query($con,$sql)){
echo 'Piece has been created';
}
else{
echo "Error creating Piece: " . mysqli_error($con);
}
}
?>
<?php mysqli_close($con); //Close Connection?>
</main>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyANqabCeXfuvJLMFOmswsDin9bAJzOSGF8"></script>
<script src="alexandria-maps.js"></script>
</body>
</html>