Jump to content


Photo

Help with image uploader


  • Please log in to reply
14 replies to this topic

#1 XxDeadmanxX

XxDeadmanxX
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 26 October 2006 - 06:36 PM

Ok im making website where users can upload images,videos and music but what i dont know how to grab the username that uploaded something and i want the username and file to go to database.

Here is the code i dont know why it doesnt work.

<?php
$reqlevel = 1;
include("membersonly.inc.php");


//print_r($_POST);

if($_POST["action"] == "Upload Image")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";


$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "images/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}
$query = "INSERT INTO Img (username, file) VALUES ("'$user_currently_loged','$imagename')";  
$result = mysql_query($query);
}

include("upload_form.php");

if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>n";
}
}

include("list_images.php");

?>


#2 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 26 October 2006 - 06:49 PM

I'm taking it that your included members script is what is populating this variable:

$user_currently_loged

If not, then how is getting passed, in a session? hidden field? etc..

Also, is that the correct name for the variable? Just not sure if 'loged' should be 'logged' maybe.

Post some additional code showing how that variable is initially being set and then passed to this page.

#3 XxDeadmanxX

XxDeadmanxX
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 26 October 2006 - 06:50 PM

I'm taking it that your included members script is what is populating this variable:

$user_currently_loged

If not, then how is getting passed, in a session? hidden field? etc..

Also, is that the correct name for the variable? Just not sure if 'loged' should be 'logged' maybe.

Post some additional code showing how that variable is initially being set and then passed to this page.

$user_currently_loged shows the user login so when i put it in there it should of grabed the username and put it in database but it didnt.

#4 XxDeadmanxX

XxDeadmanxX
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 26 October 2006 - 06:54 PM

WOW 30+ views and only 5 posts.

#5 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 26 October 2006 - 06:55 PM

Humm I think we are confused? I would store the logged in username in a session.

session_register("current_username");
$current_username = $user_currently_logged;

Then simply do a mysql query:

$sql = "INSERT into thetable (username) VALUES ($_SESSION['current_username']) WHERE someclause";
mysql_query($sql) or die(mysql_error());

#6 XxDeadmanxX

XxDeadmanxX
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 26 October 2006 - 06:57 PM

Humm I think we are confused? I would store the logged in username in a session.

session_register("current_username");
$current_username = $user_currently_logged;

Then simply do a mysql query:

$sql = "INSERT into thetable (username) VALUES ($_SESSION['current_username']) WHERE someclause";
mysql_query($sql) or die(mysql_error());

So  Your saying like this.
<?php
$reqlevel = 1;
include("membersonly.inc.php");


//print_r($_POST);

if($_POST["action"] == "Upload Image")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";


$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "images/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}
$sql = "INSERT into thetable (username, file) VALUES ($_SESSION['current_username'],$imagename) WHERE someclause";
mysql_query($sql) or die(mysql_error());
}

include("upload_form.php");

if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>n";
}
}

include("list_images.php");

?>


#7 XxDeadmanxX

XxDeadmanxX
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 26 October 2006 - 07:08 PM

Hello

#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 26 October 2006 - 07:25 PM

WOW 30+ views and only 5 posts.


1 good reply is all you need.

If the message title were more meaningful, instead of just a "help me" then more people might think "I can probably help with that".

See forum guidelines
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#9 XxDeadmanxX

XxDeadmanxX
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 26 October 2006 - 07:59 PM

WOW 30+ views and only 5 posts.


1 good reply is all you need.

If the message title were more meaningful, instead of just a "help me" then more people might think "I can probably help with that".

See forum guidelines

That didnt help me

#10 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 26 October 2006 - 08:18 PM

It was not meant to help directly. I was telling you to read the guidelines and use meaningful topic titles.

Also, have you considered that the 25+ who didn't post may be waiting for your answers to the questions posed by Freakus?

Again, read the guidelines. If someone is trying to help but needs more info, it's in your interests to provide that extra info.

I'm taking it that your included members script is what is populating this variable:

$user_currently_loged

If not, then how is getting passed, in a session? hidden field? etc..

Also, is that the correct name for the variable? Just not sure if 'loged' should be 'logged' maybe.

Post some additional code showing how that variable is initially being set and then passed to this page.


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#11 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 26 October 2006 - 08:19 PM

It looks like you have an extra double quote in with your values.

Try changing this ->

$query = "INSERT INTO Img (username, file) VALUES ("'$user_currently_loged','$imagename')";  
$result = mysql_query($query);

to this ->

$query = "INSERT INTO Img (username, file) VALUES ('$user_currently_loged','$imagename')";  
$result = mysql_query($query);

As a side note, you do realize that a broad range of users come here to find help and give help. You may have a lot of views because people are looking for solutions to similar problems. Try a be a little more patient with the time it may take for someone to give their time freely to help you.Barand is probably one of the best resources you could have help you, but your lack patience can put people off.

Anyways, hopefully that fixed your problem.

#12 XxDeadmanxX

XxDeadmanxX
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 29 October 2006 - 03:59 PM

It looks like you have an extra double quote in with your values.

Try changing this ->

$query = "INSERT INTO Img (username, file) VALUES ("'$user_currently_loged','$imagename')";  
$result = mysql_query($query);

to this ->

$query = "INSERT INTO Img (username, file) VALUES ('$user_currently_loged','$imagename')";  
$result = mysql_query($query);

As a side note, you do realize that a broad range of users come here to find help and give help. You may have a lot of views because people are looking for solutions to similar problems. Try a be a little more patient with the time it may take for someone to give their time freely to help you.Barand is probably one of the best resources you could have help you, but your lack patience can put people off.

Anyways, hopefully that fixed your problem.

Thanks man


#13 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 29 October 2006 - 04:26 PM

WOW 30+ views and only 5 posts.


Just because you have 30+ views doesn't mean the people who look at it know how to help ;)  I go through alot of posts to see if I can help and sometimes I can't *shrug*

#14 XxDeadmanxX

XxDeadmanxX
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 29 October 2006 - 07:55 PM

WOW 30+ views and only 5 posts.


Just because you have 30+ views doesn't mean the people who look at it know how to help ;)  I go through alot of posts to see if I can help and sometimes I can't *shrug*

LOL i understand like 2 people told me.

#15 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 29 October 2006 - 08:04 PM

Yea sorry bout that. Odd that I missed those posts.. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users