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
HTMLPHPAdobe Dreamweaver
13 Comments1 Solution456 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.";
}
 
}
?>


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.


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros