I have a page where I upload a number of values to my database.
This works on my local machine, however I have uploaded my files, and changed the credentials accordingly to work with the database. On the server, it just does not happen.
It uploads $new_name, but not $title or $description. Here is my code:
<?php //include("../../ssi/register_sessions.php");// throws away if not logged
//REGISTERING SESSIONS
session_start();
// is the one accessing this page logged in or not?
if (!isset($_SESSION['userid']) && $_SESSION['password'] !== true)
{
//not logged in? Move to login page
header("Location: news_login.php");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>title</title>
<?php include("../../ssi/database_header.inc");?>
<?php //start: main content?>
<tr>
<td>
<table width="100%" cellpadding="8" cellspacing="0" border="0" summary="0">
<tr>
<td width="100%" align="left" bgcolor="#ffffff" class="titletext"> News Upload <img src="../../images/common/down_arrow.gif" alt="" border="0"></td>
</tr>
</table>
</td>
<tr>
<tr>
<td align="center" valign="top" bgcolor="#ffffff">
<?php //START UPLOAD CODE?>
<?php
//Change this to the correct dir
$dir = "/mydirectory/";
//MIME types to allow, Gif, jpeg, zip ::Edit this to your liking
$types = array("image/gif","text/html","application/msword","application/octet-stream","application/vnd.ms-powerpoint","image/pjpeg","application/x-zip-compressed", "application/pdf");
//Check to determine if the submit button has been pressed
if(isset($_POST['submit']))
{
//Shorten Variables
$tmp_name = $_FILES['upload']['tmp_name'];
$new_name = $_FILES['upload']['name'];
//Check MIME Type
if (in_array($_FILES['upload']['type'], $types))
{
//Connection Credentials
include('../../ssi/mysqlCredentials.php');
//START temp DATABASE CONNECTION
mysql_connect($db_connect,$db_user,$db_pass);
//SELECT DATABASE
@mysql_select_db($db_name) or die( "Unable to select database");
//START QUERY
//ENTERING DATA INTO TABLE CALLED NEWS title, description and diretcory data
$query = "INSERT INTO news VALUES ('','$title','$description','$new_name')";
mysql_query($query);
//Move file from tmp dir to new location
move_uploaded_file($tmp_name,$dir . $new_name);
echo "<div class='text'>{$_FILES['upload']['name']} was uploaded sucessfully!</div>";
}
else
{
//Print Error Message
echo "<div class='text'>File {$_FILES['upload']['name']} Was Not Uploaded!</div>";
//Debug
$name = $_FILES['upload']['name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
$tmp = $_FILES['upload']['name'];
echo "<div class='text'>Name: $name<br/ >Type: $type<br />Size: $size<br />Tmp: $tmp</div>";
//mysql_close();
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<table width="400" cellpadding="5" cellspacing="0" border="0" summary="">
<tr>
<td width="10%" class="text" align="right">Title:</td>
<td width="90%"><input name='title' type='text' class='text' size='50' maxlength='100'></td>
</tr>
<tr>
<td class="text" valign="top" align="right">Description:</td>
<td><textarea name='description' class='text' cols='50' rows='8'></textarea></td>
</tr>
<tr>
<td class="text" align="right">Upload file:</td>
<td><input type="file" name="upload" class="text"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Upload News Item" class="text"></td>
</tr>
</form>
<br><br>
<tr>
<td colspan="2" align="right" class="linkage">| <a href="news_view.php" title="View News Items">view news items</a> | | <a href="news_logout.php" title="Log Out">log out</a> |</td>
</tr></table>
</td>
</tr>
<?php include("../../ssi/database_footer.inc");?>
It is very weird as it works on my machine with no problems.
Does anyone see any flaws that would determine this not working?
Thanks in advance