Problem adding date
Posted: Thu Jul 08, 2010 3:19 am
Hi
I am using this code to a movie to my database. However I am having problems adding the dates of the MovieReleaseDate and DVDReleaseDate.
Any help about what I have wrong please?
Thanks
I am using this code to a movie to my database. However I am having problems adding the dates of the MovieReleaseDate and DVDReleaseDate.
Any help about what I have wrong please?
Thanks
Code: Select all
<?php
//Connecting with the Database
require('dbconnect.php');
//Start up PHP session
session_start();
include('securitycheck.php');
if ($isAdmin) {
if (isset($_POST['btnCancel'])) {
header('Location: movies.php');
} elseif (isset($_POST['btnAddMovie'])) {
$title = $_POST['txtTitle'];
$director = isset($_POST['Director']) ? $_POST['Director'] : array();
$genre = isset($_POST['Genres']) ? $_POST['Genres'] : array();
if (strlen(trim($title)) > 0 && !empty($director) && !empty($genre)) {
if(!empty($_POST['txtMovieReleaseDate'])) {
$moviereleasedate = date("Y-m-d", strtotime($_POST['txtMovieReleaseDate']));
} else {
$moviereleasedate = '';
}
if(!empty($_POST['txtDVDReleaseDate'])) {
$dvdreleasedate = date("Y-m-d", strtotime($_POST['txtDVDReleaseDate']));
} else {
$dvdreleasedate = '';
}
$image = $_FILES['txtImage'];
$rating = $_POST['ddlRating'];
$review = $_POST['txtReview'];
$filename = "NoImage.jpg";
//This will check if an Image was Uploaded
if (!empty($image['name'])) {
//This will check if the uploaded Image is .JPG
if ($image['type'] == "image/jpeg" || $image['type'] == "image/pjpeg") {
$filename = $image['name'];
//This will Upload the Image to the Movie Images Folder
move_uploaded_file($image['tmp_name'], "Images/Movies/" . $image['name']);
} else {
$message = "Only <b>.jpg</b> Images can be uploaded";
}
}
$insert = "INSERT INTO movies (Title, Review, Rating, MovieReleaseDate, DVDReleaseDate, Filename) VALUES ('" . mysql_real_escape_string($title) . "', '" . mysql_real_escape_string($review) . "', '" . $rating . "', '" . $moviereleasedate . "', '" . $dvdreleasedate . "', '" . $filename . "')";
mysql_query($insert) or die(mysql_error());
$LastMovieID = mysql_insert_id();
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="CSSWebStyles/style.css" />
<link rel="shortcut icon" href="Images/filmicon.ico"/>
<title>Add Movie</title>
</head>
<body>
<div id="website">
<?php
//This will include the code for the banner & navigation
include('banner.php');
?>
<?php
//This will check if the user is an administrator
if (isset($_SESSION['superadmin'])) {
if ($_SESSION['superadmin'])
include('adminmenu.php');
}
?>
<div id="content">
<center>
<br />
<h2>Add Movie</h2>
<br />
</center>
<div id="contentgeneral">
<?php
if (isset($message)) {
echo "<center>$message</center>";
unset($message);
}
?>
<form method="post" enctype="multipart/form-data">
<table>
<tr>
<td>
Title
</td>
<td>
<input type="text" style="width: 300px;" name="txtTitle" />*
</td>
</tr>
<tr>
<td valign="top">
Movie Release Date
</td>
<td>
<input type="text" style="width: 100px;" name="txtMovieReleaseDate" /><small>Date Format: (dd/mm/yyyy)</small><br />
</td>
</tr>
<tr>
<td valign="top">
DVD Release Date
</td>
<td>
<input type="text" style="width: 100px;" name="txtDVDReleaseDate" /><small>Data Format: (dd/mm/yyyy)</small><br />
</td>
</tr>
<tr>
<td valign="top">
Review
</td>
<td>
<textarea name="txtReview" rows="10" cols="100"></textarea>
</td>
</tr>
<tr>
<td valign="top">
Image
</td>
<td>
<input type="file" name="txtImage" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="btnAddMovie" value="Add" /> <input type="submit" name="btnCancel" value="Cancel" />
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
</body>
</html>