Jump to content

[SOLVED] I don't know what is wrong


The Little Guy

Recommended Posts

Here is the form:

<?php
echo'<form action="'.$home.'/uploadfiles.php?type=profile_image" method="post" enctype="multipart/form-data">
<table>';
$sql = mysql_query("SELECT * FROM pictures WHERE id='$_SESSION[userid]'")or die(mysql_error());
for($i=1;$i <= $maximages;$i++){
$picts = mysql_fetch_array($sql);
if($picts){
	echo'<tr>
	<td colspan="2"><input class="checkbox" type="checkbox" name="image_delete[]" value="'.$picts['filename'].'">
	<img src="images/userimages/thumbs/'.$picts['filename'].'"></td>
	</tr>';
}else{
	echo'
	<tr>
		<td>Picture Of You ('.$i.'):</td>
		<td><input class="file" type="file" name="pictures[]"></td>
	</tr>';
}
}
echo'
<tr>
	<td><input type="submit" name="upload_images" value="Upload"></td>
	<td><input type="submit" name="delete_images" value="Delete"></td>
</tr>
</table>
</form>';
?>

 

This code, when the page loads, doesn't go into the second if statement.

 

If i type echo 'I am here'; right after the first { it echos, but if it is right after the second, it doesn't echo, I can't find the error. Please help.

<?php
session_start();
if($_SESSION['logedin']!=1){
header("Location: $home/index.php");
exit;
}
include"functions.php";
include"globalvars.php";
if($_GET['type'] == "profile_image"){
if(isset($_POST['upload_images'])){

 

Here is what the URL Looks like (Don't click, probably won't work.)

http://68.117.46.68:6251/date/uploadfiles.php?type=profile_image

Link to comment
Share on other sites

I'm not sure what your problem is, but try echoing the sql see if it is correct.

 

$sql = mysql_query("SELECT * FROM pictures WHERE id='$_SESSION[userid]'")or die(mysql_error());
echo 'SQL :'. $sql;
for($i=1;$i <= $maximages;$i++){
$picts = mysql_fetch_array($sql);

 

Try posting a simpler code example, trim it down to 4-5 lines or code. You'll probably find the error yourself if you do that.

 

Link to comment
Share on other sites

One thing you might try is having a hidden input with a value of 1. I always have that ever since I figured out that Submit values don't always send.

 

For example, if you push enter, but don't click submit, the submit buttons value isn't sent. So adding a field like this would fix it:

<input type="hidden" name="upload_images" value="1">

 

Make sure you change your input button's name though to avoid conflicting names.

Link to comment
Share on other sites

One thing you might try is having a hidden input with a value of 1. I always have that ever since I figured out that Submit values don't always send.

 

For example, if you push enter, but don't click submit, the submit buttons value isn't sent. So adding a field like this would fix it:

<input type="hidden" name="upload_images" value="1">

 

Make sure you change your input button's name though to avoid conflicting names.

 

That didn't do work. could this be an HTML error?

Link to comment
Share on other sites

Frome the editor:

<?php
echo'<form action="'.$home.'/uploadfiles.php?type=profile_image" method="post" enctype="multipart/form-data">
							<table>';
							$sql = mysql_query("SELECT * FROM pictures WHERE id='{$_SESSION['userid']}'")or die(mysql_error());
							for($i=1;$i <= $maximages;$i++){
								$picts = mysql_fetch_array($sql);
								if($picts){
									echo'<tr>
										<td colspan="2"><input class="checkbox" type="checkbox" name="image_delete[]" value="'.$picts['filename'].'">
										<img src="images/userimages/thumbs/'.$picts['filename'].'"></td>
									</tr>';
								}else{
									echo'
									<tr>
										<td>Picture Of You ('.$i.'):</td>
										<td><input class="file" type="file" name="pictures[]"></td>
									</tr>';
								}
							}
							echo'
							<tr>
								<td><input type="submit" name="upload_images" value="Upload"></td>
								<td><input type="submit" name="delete_images" value="Delete"></td>
								</tr>
							</table>
						</form>';
?>

 

From the Browser Source Code:

<form action="http://ifolio.no-ip.org/date/uploadfiles.php?type=profile_image" method="post" enctype="multipart/form-data">
							<table>
									<tr>
										<td>Picture Of You (1):</td>

										<td><input class="file" type="file" name="pictures[]"></td>
									</tr>
									<tr>
										<td>Picture Of You (2):</td>
										<td><input class="file" type="file" name="pictures[]"></td>
									</tr>
									<tr>
										<td>Picture Of You (3):</td>

										<td><input class="file" type="file" name="pictures[]"></td>
									</tr>
									<tr>
										<td>Picture Of You (4):</td>
										<td><input class="file" type="file" name="pictures[]"></td>
									</tr>
							<tr>
								<td><input type="submit" name="upload_images" value="Upload"></td>

								<td><input type="submit" name="delete_images" value="Delete"></td>
								</tr>
							</table>
						</form>

Link to comment
Share on other sites

uploadfiles.php:

<?php
session_start();
if($_SESSION['logedin']!=1){
header("Location: $home/index.php");
exit;
}
include"functions.php";
include"globalvars.php";
if($_GET['type'] == "profile_image"){
if(isset($_POST['upload_images'])){
	foreach ($_FILES["pictures"]["error"] as $key => $error){
		if($error === 0){
			$filename = time().$_FILES["pictures"]["name"][$key];
			if($_FILES["pictures"]["type"]!="image/gif"||$_FILES["pictures"]["type"]!="image/jpg"||$_FILES["pictures"]["type"]!="image/png"){
				header("Location: $home/user.php?page=images&type=profile_image");
				exit;
			}
			move_uploaded_file($_FILES["pictures"]["tmp_name"][$key], "$home/images/userimages/$filename");
			createThumbnail("$home/images/userimages", "$filename", "$home/images/userimages/thumbs", 100);
			mysql_query("INSERT INTO pictures(`id`, `filename`) VALUES ('$_SESSION[userid]', '$filename')")or die(mysql_error());
		}
	}

// More code below that doesn't pertain the this:



header("Location: $home/user.php?page=images&type=profile_image");
	exit;
}elseif(isset($_POST['delete_images'])){
	foreach($_POST['image_delete'] as $img){
		mysql_query("DELETE FROM pictures WHERE filename='$img'")or die(mysql_error());
		$delete_img = "$home/images/userimages/$img";
		$delete_thumb = "$home/images/userimages/thumbs/$img";
		unlink($delete_img);
		unlink($delete_thumb);
	}
	header("Location: $home/user.php?page=images&type=profile_image");
	exit;
}
}elseif($_GET['type'] == "avatar_image"){
if($_GET['action'] == "delete"){
	$delete_avatar = "$home/images/avatars/$_POST[filename]";
	unlink($delete_avatar);
	mysql_query("DELETE FROM avatars WHERE id='$_SESSION[userid]'");
	header("Location: $home/user.php?page=images&type=avatar_image");
}elseif($_GET['action'] == "upload"){
	foreach ($_FILES["avatar"]["error"] as $key => $error){
		if($error === 0){
			$filename = time().$_FILES["avatar"]["name"][$key];
			move_uploaded_file($_FILES["avatar"]["tmp_name"][$key], "images/avatars/$filename");
			createThumbnail("$home/images/avatars", "$filename", "$home/images/avatars", 100);
			mysql_query("INSERT INTO avatars(`id`, `filename`) VALUES ('$_SESSION[userid]', '$filename')")or die(mysql_error());
		}
	}
	header("Location: $home/user.php?page=images&type=avatar_image");
	exit;
}
}

?>

Link to comment
Share on other sites

Try making a backup of your uploadfiles.php or point your form to a new location and simply put print_r($_POST); at the top of the file it posts to. Then see what the outcome is.

 

The other thing you can try is checking your error logs on your server. It looks like PHP may be erroring out some where and you may have error_reporting set to not report anything.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.