Jump to content

[SOLVED] doesnt work with shared hosting


squiblo

Recommended Posts

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>

";

?>

Link to comment
https://forums.phpfreaks.com/topic/167860-solved-doesnt-work-with-shared-hosting/
Share on other sites

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!

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>

";

?>

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

<?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!"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.