troubleshooting Question

Amending code to upload a file to a folder on my server. It's not working.

Avatar of Adam
AdamFlag for United Kingdom of Great Britain and Northern Ireland asked on
PHPAdobe DreamweaverHTML
13 Comments4 Solutions456 ViewsLast Modified:
Hello,

I'm trying to amend some code which was created by a developer for a website I own (the developer is currently not contactable).

Looking at the code she created, I'm trying to modify it for use in a new webpage, stored on a different server (which points to a different database etc). The code will do exactly the same in the new website as it did in the old, so I had hoped it would just be a case of changing the settings to connect to the new database. Unfortunately not.


My amended code is shown below (with my comments) - I've taken out what I think is the unimportant stuff for the purpose of this question:

<?php
session_start();
if($_POST['submit'] == ''){
?>


.....

<form enctype="multipart/form-data" action="<?php echo $_SERVER['file:///C|/Users/Adam/Documents/websites/orangutanenglish/PHP_SELF']; ?>" - I'm not sure what this paths refers to (My Comment)

 method="post"> <!-- JHCO: changed from $_SERVER['../PHP_SELF'] to $_SERVER['PHP_SELF'] -->
  <div align="center">
          <input type="hidden" name="MAX_FILE_SIZE" value="8000000" />
          <span class="style18">Select your profile picture</span><strong>:</strong>
          <input type="file" name="user_picture" />
          <input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id']; ?>" />
          <input type="submit" name="submit" value="submit" />
        </div>
    </form>

      ....<?php
} else {
require_once('../Connections/sensei.php'); - this file exists (My Comment)

$upload_path = "/home/orangu8/public_html/upload"; - changed to new path (My Comment)

$extension = $_FILES['user_picture']['name'];
$extension = explode('.',$extension);
$extension = array_reverse($extension);
$extension = $extension[0];
$upload_file_name = "user_pic-".$_SESSION['user_id'].'.'.$extension;
$upload_full_path = $upload_path.'/'.$upload_file_name;

if(move_uploaded_file($_FILES['user_picture']['tmp_name'], $upload_full_path)){

$sqlUpdateUser = "UPDATE TestTable SET photoid='".$upload_file_name."', photo='1' WHERE autonumber=".$_POST['user_id'];

mysql_select_db($database_sensei, $sensei);
if(! ( mysql_query($sqlUpdateUser, $sensei))){
die('There was a problem!<br>Query being exectued:'.$sqlUpdateUser.'<br><br> MySQL error number:'.mysql_errno($sensei).'<br><br> MySQL message:'.mysql_error($sensei));
} else {
           echo '<script language="JavaScript">
           window.location="SenseiConnect_Add_Your_Profile2.php";
           </script>';
}
} else {
echo "there was a problem.";
}
 
}
?>

Open in new window



Anyway, the error I get when I try to upload a file to the location is -

There was a problem!
Query being exectued:UPDATE TestTable SET photoid='user_pic-.png', photo='1' WHERE autonumber=

MySQL error number:1064

MySQL message:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

If there's a simple tutorial somewhere about uploading files to locations on the server I'd be happy if somebody could point me towards it. Or if the code above just needs a tweak or two to get it working I'd be grateful if anybody could let me know what needs tweaked.

I'm not a developer by the way, just trying to re-use code I don't really understand.

thanks.


ASKER CERTIFIED SOLUTION
maeltar

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 4 Answers and 13 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 4 Answers and 13 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004