squiblo Posted July 28, 2009 Share Posted July 28, 2009 this code does work but does not place the filename into the database, i heard that it is because i am using a shared hosting website (one.com), the file uploads to the file manager using by using "core ftp" but how can i edit this script so that the file name is also uploaded to my sql database? <?php session_start(); include("checklogin.php"); $_SESSION['myusername']; $username = $_SESSION['username']; if ($_POST['submit']) { //get file attributes $name = $_FILES['myfile']['name']; $tmp_name = $_FILES['myfile']['tmp_name']; if ($name) { //start upload process $location = "profileimages/$name"; move_uploaded_file($tmp_name,$location); $query = mysql_query("UPDATE users SET imagelocation='$location' WHERE username='$'"); die("Your profile picture have been upload! <a href='profile.php'>Profile</a>"); } else die("Please select a file!"); } echo "Welcome, ".ucwords(strtolower($_SESSION['myusername']))."!<p>"; echo "Upload your image: <form action='upload.php' method='POST' enctype='multipart/form-data'> File: <input type='file' name='myfile'> <input type='submit' name='submit' value='Upload'> </form> "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/ Share on other sites More sharing options...
MadTechie Posted July 28, 2009 Share Posted July 28, 2009 change $location = "profileimages/$name"; move_uploaded_file($tmp_name,$location); $query = mysql_query("UPDATE users SET imagelocation='$location' WHERE username='$'"); to $location = dirname(__FILE__)."/profileimages/$name"; move_uploaded_file($tmp_name,$location); $query = mysql_query("UPDATE users SET imagelocation='$location' WHERE username='$username'") or die(mysql_error()); EDIT: note that the script would NOT work as the sql statement was incorrect! Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885348 Share on other sites More sharing options...
squiblo Posted July 28, 2009 Author Share Posted July 28, 2009 it still doesnt put the filename into sql, it has now changed to this: <?php session_start(); include("checklogin.php"); $_SESSION['myusername']; $username = $_SESSION['username']; if ($_POST['submit']) { //get file attributes $name = $_FILES['myfile']['name']; $tmp_name = $_FILES['myfile']['tmp_name']; if ($name) { //start upload process $location = dirname(__FILE__)."/profileimages/$name"; move_uploaded_file($tmp_name,$location); $query = mysql_query("UPDATE members SET imagelocation='$location' WHERE username='$username'") or die(mysql_error()); die("Your profile picture have been upload! <a href='profile.php'>Profile</a>"); } else die("Please select a file!"); } echo "Welcome, ".ucwords(strtolower($_SESSION['myusername']))."!<p>"; echo "Upload your image: <form action='upload.php' method='POST' enctype='multipart/form-data'> File: <input type='file' name='myfile'> <input type='submit' name='submit' value='Upload'> </form> "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885356 Share on other sites More sharing options...
MadTechie Posted July 28, 2009 Share Posted July 28, 2009 do you get an error ? does Your profile picture have been upload! <a href='profile.php'>Profile</a> display ? Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885365 Share on other sites More sharing options...
squiblo Posted July 28, 2009 Author Share Posted July 28, 2009 yes that does display, and i get the image in ftp but not in sql Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885366 Share on other sites More sharing options...
squiblo Posted July 28, 2009 Author Share Posted July 28, 2009 why is the filename not uploading into sql? Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885378 Share on other sites More sharing options...
MadTechie Posted July 28, 2009 Share Posted July 28, 2009 you keep saying the file uploads to the sql but your code only refers to the file path, if your not getting an sql error then its working, i suggest you check your looking in the correct place.. echo out the query and use a select to check it Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885386 Share on other sites More sharing options...
squiblo Posted July 28, 2009 Author Share Posted July 28, 2009 im reali confused and dont know why it is not working properly? Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885400 Share on other sites More sharing options...
MadTechie Posted July 28, 2009 Share Posted July 28, 2009 it maybe because your making impossible to help, by not posting any useful information! it doesn't work its not working, I don't know why its not working properly, really doesn't help.. Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885409 Share on other sites More sharing options...
squiblo Posted July 28, 2009 Author Share Posted July 28, 2009 ok sorry :S ill try to explain more Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885413 Share on other sites More sharing options...
squiblo Posted July 28, 2009 Author Share Posted July 28, 2009 <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); if(isset($_POST['Login'])){ // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); //$_SESSION['myusername']=$dbusername; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "profile.php" session_register("myusername"); session_register("mypassword"); header("location:profile.php"); } else { header("location: http://www.squiblo.com/retrylogin.php"); } } ?> <?php session_start(); include("checklogin.php"); $_SESSION['myusername']; $username = $_SESSION['username']; if ($_POST['submit']) { //get file attributes $name = $_FILES['myfile']['name']; $tmp_name = $_FILES['myfile']['tmp_name']; if ($name) { //start upload process $location = dirname(__FILE__)."/profileimages/$name"; move_uploaded_file($tmp_name,$location); $query = mysql_query("UPDATE members SET imagelocation='$location' WHERE username='$username'") or die(mysql_error()); die("Your profile picture have been upload! <a href='profile.php'>Profile</a>"); } else die("Please select a file!"); } echo "Welcome, ".ucwords(strtolower($_SESSION['myusername']))."!<p>"; echo "Upload your image: <form action='upload.php' method='POST' enctype='multipart/form-data'> File: <input type='file' name='myfile'> <input type='submit' name='submit' value='Upload'> </form> "; ?> when i upload an image, i cannot view it in sql but i can view it in ftp, when i click the upload button on the page i do get the message "Your profile picture have been upload!" Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885423 Share on other sites More sharing options...
MadTechie Posted July 29, 2009 Share Posted July 29, 2009 Well you marked this as solved, so i assume you found the problem! Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885456 Share on other sites More sharing options...
squiblo Posted July 29, 2009 Author Share Posted July 29, 2009 i changed $_SESSION['myusername']; $username = $_SESSION['username']; to $_SESSION['myusername']; $username = $_SESSION['myusername']; Quote Link to comment https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/#findComment-885468 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.