XxDeadmanxX Posted October 26, 2006 Share Posted October 26, 2006 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.[code]<?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");?>[/code][color=black][/color] Quote Link to comment Share on other sites More sharing options...
freakus_maximus Posted October 26, 2006 Share Posted October 26, 2006 I'm taking it that your included members script is what is populating this variable:$user_currently_logedIf 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. Quote Link to comment Share on other sites More sharing options...
XxDeadmanxX Posted October 26, 2006 Author Share Posted October 26, 2006 [quote author=freakus_maximus link=topic=112843.msg458187#msg458187 date=1161888540]I'm taking it that your included members script is what is populating this variable:$user_currently_logedIf 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.[/quote]$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. Quote Link to comment Share on other sites More sharing options...
XxDeadmanxX Posted October 26, 2006 Author Share Posted October 26, 2006 WOW 30+ views and only 5 posts. Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted October 26, 2006 Share Posted October 26, 2006 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()); Quote Link to comment Share on other sites More sharing options...
XxDeadmanxX Posted October 26, 2006 Author Share Posted October 26, 2006 [quote author=JustinK101 link=topic=112843.msg458194#msg458194 date=1161888919]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());[/quote]So Your saying like this.[code]<?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");?>[/code] Quote Link to comment Share on other sites More sharing options...
XxDeadmanxX Posted October 26, 2006 Author Share Posted October 26, 2006 Hello Quote Link to comment Share on other sites More sharing options...
Barand Posted October 26, 2006 Share Posted October 26, 2006 [quote author=XxDeadmanxX link=topic=112843.msg458193#msg458193 date=1161888897]WOW 30+ views and only 5 posts.[/quote]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 Quote Link to comment Share on other sites More sharing options...
XxDeadmanxX Posted October 26, 2006 Author Share Posted October 26, 2006 [quote author=Barand link=topic=112843.msg458218#msg458218 date=1161890737][quote author=XxDeadmanxX link=topic=112843.msg458193#msg458193 date=1161888897]WOW 30+ views and only 5 posts.[/quote]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[/quote]That didnt help me Quote Link to comment Share on other sites More sharing options...
Barand Posted October 26, 2006 Share Posted October 26, 2006 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.[quote author=freakus_maximus link=topic=112843.msg458187#msg458187 date=1161888540]I'm taking it that your included members script is what is populating this variable:$user_currently_logedIf 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.[/quote] Quote Link to comment Share on other sites More sharing options...
freakus_maximus Posted October 26, 2006 Share Posted October 26, 2006 It looks like you have an extra double quote in with your values.Try changing this ->[code]$query = "INSERT INTO Img (username, file) VALUES ("'$user_currently_loged','$imagename')"; $result = mysql_query($query);[/code]to this ->[code]$query = "INSERT INTO Img (username, file) VALUES ('$user_currently_loged','$imagename')"; $result = mysql_query($query);[/code]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. Quote Link to comment Share on other sites More sharing options...
XxDeadmanxX Posted October 29, 2006 Author Share Posted October 29, 2006 [quote author=freakus_maximus link=topic=112843.msg458251#msg458251 date=1161893981]It looks like you have an extra double quote in with your values.Try changing this ->[code]$query = "INSERT INTO Img (username, file) VALUES ("'$user_currently_loged','$imagename')"; $result = mysql_query($query);[/code]to this ->[code]$query = "INSERT INTO Img (username, file) VALUES ('$user_currently_loged','$imagename')"; $result = mysql_query($query);[/code]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.[/quote]Thanks man Quote Link to comment Share on other sites More sharing options...
SharkBait Posted October 29, 2006 Share Posted October 29, 2006 [quote author=XxDeadmanxX link=topic=112843.msg458193#msg458193 date=1161888897]WOW 30+ views and only 5 posts.[/quote]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* Quote Link to comment Share on other sites More sharing options...
XxDeadmanxX Posted October 29, 2006 Author Share Posted October 29, 2006 [quote author=SharkBait link=topic=112843.msg459530#msg459530 date=1162139174][quote author=XxDeadmanxX link=topic=112843.msg458193#msg458193 date=1161888897]WOW 30+ views and only 5 posts.[/quote]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*[/quote]LOL i understand like 2 people told me. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted October 29, 2006 Share Posted October 29, 2006 Yea sorry bout that. Odd that I missed those posts.. :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.