What do you do when everything should be working?

I am having a major issue atm. I am working on a program for a website I’m building. I got plenty of help with some issues I was having in the PHP forum. The problem that I am having now is that according to everything I’ve read, looked at, and triple-checked my code should be working. Except, of course, it isn’t. So what are some suggestions as to what I should do at this point?

I’m not getting any errors of any kind (syntax, php, database), but my data isn’t being sent to the database (even though it’s all stored in the variables it should be). I’m having some other issues too, but I’d be happy to start with fixing just that one.

So, what do you do when everything should be working properly, but isn’t?

Any suggestions would be great :confused:

Post your code so we can see what it’s doing.

Ugg, after I do that it’s gonna get moved x_x Just a min tho and I’ll put it up…

This is the index page, which includes the page that holds the html and whatnot:

include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/includes/db.inc.php';

$email = $_SESSION['email'];
$sql = "SELECT id, username, email, uploadtotal FROM user WHERE email='$email'";
$result = mysqli_query($link, $sql);
if (!$result)
{
	$error = 'Error fetching user information.';
	include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
	exit();
}

$row = mysqli_fetch_array($result);
$userid = $row['id'];
$username = $row['username'];
$email = $row['email'];
$useruploads = $row['uploadtotal'];

// Uploading a file
if (isset($_POST['action']) && $_POST['action'] == 'upload')
{
	include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/includes/db.inc.php';
	include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/includes/filewriting.inc.php';
		
	if (!is_uploaded_file($_FILES['file']['tmp_name']))
	{
		$error = 'This is not an HTTP upload.';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	
	if (!getimagesize($_FILES['file']['tmp_name']))
	{
		$error = 'Only image uploads are allowed.';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	
	$bytesize = $_FILES['file']['size'];
	
	$uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/users/' . $username . '/images/';
	$now = time();
	while (file_exists($uploadFileName = $uploaddir . $now . '-' . $_FILES['file']['name']))
	{
		$now++;
	}
	
	if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadFileName))
	{
		$error = 'Receiving directory has insufficient permissions.';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	// Get name of JUST the file (should include ext)
	$uploaddirlen = strlen($uploaddir);
	$justFileName = substr_replace($uploadFileName, '', 0, $uploaddirlen);

	// $dimensions[0] = width, 1 = height, 2 = mimetype
	$dimensions = getimagesize($uploadFileName);
	$uploaddate = date('Y-m-d');
	if ($bytesize < 1)
	{
		$error = 'Problem uploading image!';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}

	$sql = "INSERT INTO image SET
			name = '$justFileName',
			url = '$uploadFileName',
			userid = '$userid',
			size = '$bytesize',
			height = '$dimensions[1]',
			width = '$dimensions[0]',
			date = '$uploaddate'";
	if (!mysqli_query($link, $sql))
	{
		$error = 'Error adding image data to database.';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	$imageID = mysqli_insert_id($link);
	
	$useruploads++;
	$sql = "UPDATE user SET
			uploadtotal = '$useruploads'
			WHERE id = '$userid'";
	if (!mysqli_query($link, $sql))
	{
		$error = 'Error updating user upload total.';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	
	$thumbnail = makeThumbnail($uploadFileName, $username);
	if (!$thumbnail[0])
	{
		$error = 'Error creating thumbnail!';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	$thumbnailName = $thumbnail[1];
	$sql = "UPDATE image SET 
			thumbnail = '$thumbnailName'
			WHERE name = '$imageID'";
	if (!mysqli_query($link, $sql))
	{
		$error = 'Error writing thumbnail URL to image table.';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	
	// Putting information into an array to send to function :)
	$pageInfo = array(
				'username' => $username,
				'filename' => $justFileName,
				'fileurl' => $uploadFileName,
				'thumburl' => $thumbnailName,
				'date' => $uploaddate,
				'bytes' => $bytesize,
				'width' => $dimensions[0],
				'height' => $dimensions[1]);
	
	if (!makeImagePage($pageInfo))
	{
		$error = 'Error creating page for image.';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	
	$output = 'File uploaded successfully!';
	header('Location: ' . $_POST['tagit']);
}
	
if (isset($_POST['tagit']))
{
	include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/includes/db.inc.php';
	$imageID = mysqli_insert_id($link);
	$sql = "SELECT name, thumbnail FROM image WHERE id = '$imageID'";
	$result = mysqli_query($link, $sql);
	if (!$result)
	{
		$error = 'Error fetching image information.';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	$row = mysqli_fetch_array($result);
	$imagename = $row['name'];
	$thumburl = $row['thumbnail'];

	include 'uploadsuccess.html.php';
	exit();
}

The main index page just has an uploader atm, which works properly.

After uploading, it calls this function:

function makeThumbnail($originalImage, $username)
{
	$sidemax = 250;
	
	$removestr = $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/users/' . $username . '/images/';
	$removelen = strlen($removestr);
	$originalImageName = substr_replace($originalImage, '', 0, $removelen);
	$thumbnailName = 'thm-' . $originalImageName;
	$thumbnailName = $removestr . $thumbnailName;
	
	$dimensions = getimagesize($originalImage);
	$ow = $dimensions[0];
	$oh = $dimensions[1];
	$largerval = max($ow, $oh);
	$x = round(($oh * $sidemax) / $ow);
	if ($largerval == $ow)
	{
		$nw = $x;
		$nh = $sidemax;
	} else {
		$nw = $sidemax;
		$nh = $x;
	}
	
	$thumbie = imagecreatetruecolor($nw, $nh);
	if (!imagejpeg($thumbie, $thumbnailName))
	{
		$error = 'Error creating jpeg.';
		include $_SERVER['DOCUMENT_ROOT'] . '/funstuff/funnerstuff/error.html.php';
		exit();
	}
	
	$mimetype = exif_imagetype($originalImage);
	switch ($mimetype) {
		case 1:
			$original = imagecreatefromgif($originalImage);
			break;
		case 2:
			$original = imagecreatefromjpeg($originalImage);
			break;
		case 3:
			$original = imagecreatefrompng($originalImage);
			break;
		case 6:
			$original = imagecreatefromwbmp($originalImage);
			break;
		//default: I dunno, false?
	}
	
	$thumbie = imagecreatefromjpeg($thumbnailName);
	$thumbnail[0] = imagecopyresized($thumbie, $original, 0, 0, 0, 0, $nw, $nh, $ow, $oh);
	$thumbnail[1] = $thumbnailName;
	
	imagedestroy($thumbie);
	imagedestroy($original);
	
	return $thumbnail;
}

Oh yeah, and the original image is also being saved to an incorrect directory (I moved the index file recently). The user cp is suppose to be site.com/users/index.php, all images are suppose to be uploaded to site.com/users/username/images/. The original image is being put there, but it’s also being put at site.com/users/username/