Add image problems
Posted: Thu Apr 15, 2010 7:43 am
Hi,
I did this script but i have a problem with the image. The form I wright details in is ok even the browse for image, however when i click register and check the data in the database all data is inputted exept the filename field.
Any help please?? This is the code...
I did this script but i have a problem with the image. The form I wright details in is ok even the browse for image, however when i click register and check the data in the database all data is inputted exept the filename field.
Any help please?? This is the code...
Code: Select all
<?
session_start();
require('config/connection.php');
if (isset($_POST['btnCancel']))
{
header('Location: index.php');
}
else if (isset($_POST['btnRegister']))
{
$username = $_POST['txtUsername'];
$password = ($_POST['txtPassword']);
if (strlen(trim($username)) > 0 && strlen(trim($password)) > 0)
{
$confirmpassword = ($_POST['txtConfirmPassword']);
$firstname = $_POST['txtFirstName'];
$lastname = $_POST['txtLastName'];
$email = $_POST['txtEmail'];
if (strlen($_POST['txtDOB']) > 0)
{
$dob = explode("/", $_POST['txtDOB']);
$day = $dob[0];
$month = $dob[1];
$year = $dob[2];
$dob = date("Y-m-d", mktime(0,0,0,$month,$day,$year));
}
else
{
$dob = "";
}
$location = $_POST['txtLocation'];
$image = $_FILES['txtImage'];
$filename = "";
//checking if an image was uploaded
if ($image)
{
//checking if image is JPG
if ($image['type'] == "image/jpeg" || $image['type'] == "image/pjpeg")
{
$filename = $image['name'];
//uploading the file
move_uploaded_file($image['tmp_name'], "images/" . $image['name']);
}
else
{
$message = "Only .jpg images are allowed to be uploaded";
}
}
if (isset($_POST['rbnGender']))
{
$gender = $_POST['rbnGender'];
}
else
{
$gender = "";
}
if ($password == $confirmpassword)
{
$insert = "INSERT INTO users (username, password, firstname, lastname, email, dob, location, gender, filename, userlevel) VALUES ('" . addslashes($username) . "', '" .
addslashes($password) . "', '" . addslashes($firstname) . "', '" . addslashes($lastname) . "', '" . addslashes($email) . "', '" . addslashes($dob) . "', '" . addslashes($location) . "', '" . addslashes($gender) . "', '" . addslashes($filename) . "', '0')";
mysql_query($insert) or die(mysql_error());
header('Location: index.php');
}
else
{
$message = "Error: <b>Passwords</b> do not match. Please try again.";
}
}
else
{
$message = "Error: <b>Username</b> and <b>Password</b> are mandatory. Please try again.";
}
}
?>
<!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="styles/screen.css" />
<title>Register</title>
</head>
<body>
<div id="website">
<? include('top.php'); ?>
<div id="content">
<div id="contentgeneral2">
<h2>Register</h2>
<?
if (isset($message))
{
echo "<center>$message</center>";
unset($message);
}
?>
<form method="post">
<table>
<tr>
<td>
Username
</td>
<td>
<input type="text" style="width: 300px;" name="txtUsername" />
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<input type="password" style="width: 300px;" name="txtPassword" />
</td>
</tr>
<tr>
<td>
Confirm Password
</td>
<td>
<input type="password" style="width: 300px;" name="txtConfirmPassword" />
</td>
</tr>
<tr>
<td>
First Name:
</td>
<td>
<input type="text" style="width: 300px;" name="txtFirstName" />
</td>
</tr>
<tr>
<td>
Last Name:
</td>
<td>
<input type="text" style="width: 300px;" name="txtLastName" />
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<input type="text" style="width: 300px;" name="txtEmail" />
</td>
</tr>
<tr>
<td valign="top">
D/O/B:
</td>
<td>
<input type="text" style="width: 300px;" name="txtDOB" value="format: (dd/mm/yyyy)" /><br />
</td>
</tr>
<tr>
<td>
Location:
</td>
<td>
<input type="text" style="width: 300px;" name="txtLocation" />
</td>
</tr>
<tr>
<td>
Gender:
</td>
<td>
<input type="radio" value="Mr." name="rbnGender" /> Mr.
<input type="radio" value="Mrs." name="rbnGender" /> Mrs.
</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="btnRegister" value="Register" /> <input type="submit" name="btnCancel" value="Cancel" />
</td>
</tr>
</table>
</form>
</div>
<div id="contentright">
<div class="blog2" style="float: right; margin-left: 10px; margin-top:40px; width: 250px;">
<h2><center>Why Register?</center></h2>
<ul>
<li>Rate the Movies</li>
<li>Comment on Movies</li>
<li>Select Your Favorite Movies</li>
</ul>
</div>
</div>
</div>
<?
//will include the code from footer.php file
include('footer.php');
?>
</div>
</body>
</html>