Show Code:
artist-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>
<?php include 'nav.php'; ?>
<?php include 'db-connect.php'; ?>
<main>
<?php
//handle initial create page
if( $_POST['artist_name']==''){
?>
<form method="post" action="artist-create.php" enctype="multipart/form-data">
<label>Artist Name: </label>
<input type="text" name="artist_name">
<label>Year of Birth: </label>
<input type="text" name="year_birth">
<label>Year of Death: </label>
<input type="text" name="year_death">
<label>Biography: </label>
<input type="text" name="artist_biography">
<!--Create the movement select menu-->
<label>Movement: </label>
<select name="movement_fk">
<?php
$sql="SELECT * FROM t_movements ORDER BY movement_name";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result)){
echo '<option value="'.$row['movement_id'].'">'.$row['movement_name'].'</option>';
echo PHP_EOL;
}
?>
</select>
<!--End the artist select menu-->
<label>Artist Image: </label>
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Create">
</form>
<?php
}
//handle recursive form
else{
$artist_name=$_POST['artist_name'];
$movement_fk=$_POST['movement_fk'];
$year_birth=$_POST['year_birth'];
$year_death=$_POST['year_death'];
$artist_biography=$_POST['artist_biography'];
include 'image-handler.php';
$sql='INSERT INTO t_artists (artist_name,movement_fk,artist_image, year_death, year_birth, artist_biography)
VALUES ("'.$artist_name.'","'.$movement_fk.'","'.$target_file.'",'.$year_birth.','.$year_death.',"'.$artist_biography.'")';
echo $sql;
if(mysqli_query($con,$sql)){
echo 'Artist has been created';
}
else{
echo "Error creating artist: " . mysqli_error($con);
}
}
?>
<?php mysqli_close($con); //Close Connection?>
</main>
</body>
</html>