PHP Update Help

Hi All,

I have been working on a script for a good few days now and it’s not working :(. Shown below is the code that I’ve been using for both the form and then obviously the script.

Both scripts have to keep the id field, if anyone can help please reply.

Form below


include ("../Connections/connect.php");
mysql_select_db($database_connect, $connect);
	
	if (isset($_GET['id'])){
		
		 $this_page_id = $_GET['id'];
		
	$page_query = mysql_query ("SELECT * FROM co_pic_main_uploads WHERE id = $this_page_id") or die(mysql_error());
	
		$page_content = mysql_fetch_array($page_query);
		
		echo '<img src=' . $page_content['path'] . ' width="250" height="300" >
	<form action="pic_change.php" method="GET" enctype="application/x-www-form-urlencoded">
  <p><br  />
     <label for="file">Select a file:</label> 
     <input type="file" name="userfile" id="file"> 
     <br />
     
     <button name="upload">Upload File</button>
   <p>
</form>
	<a href="co_los_front.php">Back to Images</a>';
	 
	
	} else {
			
	
	$query_news = mysql_query ("SELECT * FROM co_pic_main_uploads ORDER BY id")or die(mysql_error());
		echo '<ul>';

	while($row = mysql_fetch_array($query_news)) {
	echo '<li><a href=co_los_front.php?id=' . $row['id'] . '><img src=' . $row['path'] . ' width="72" height="72" ></a></li>';
	}
			echo '</ul>';

	}
	
	?>

Upload Script

	<?php
	

	
	// Configuration - Your Options
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg'); // These will be the types of file that will pass the validation.
      $max_filesize = 15242880; // Maximum filesize in BYTES (currently 5.0MB).
      $upload_path = '../images/uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
 
   $filename = $_GET['userfile']['name']; // Get the name of the file (including file extension).
   $tmpname = $_GET['userfile']['tmp_name']; // Give it a temporary name
	$filesize = $_GET['userfile']['size']; // Get the file size
	$filetype = $_GET['userfile']['type']; // Get the file type
	$filepath = $upload_path . $filename;
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
   $result = move_uploaded_file($tmpname, $filepath);

	if (!$result) {
	echo "Error uploading file";
	exit;
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');
 
   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_GET['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');
 
   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');
 
   // Upload the file to your specified path.
   if(move_uploaded_file($_GET['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a> <br>
		     <p>Once your done you can simply click the link below</p>
	<p><img src="../images/PNG/onebit_34.png" width="48" height="48" /><br />
      <a href="co_admin.php">Return Home </a></p> '; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed :(.
																							  
	}
	//Connect to my SQL																						  
	include ("../Connections/connect.php");
	
	 if(!get_magic_quotes_gpc())
{
$upload_path = addslashes($upload_path);
}



// Insert data obtained above into table 
if (isset($_GET['id'])){
		
		$this_page_id = $_GET['id'];

$query = mysql_query("UPDATE co_pic_main_uploads 
		SET name ='$filename', size='$filesize', type='$filetype', path='$filepath' WHERE id='$this_page_id'")or die('Error, query failed : ' . mysql_error());
	}


echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a> <br>
		     <p>Once your done you can simply click the link below</p>
	<p><img src="../images/PNG/onebit_34.png" width="48" height="48" /><br />
      <a href="co_admin.php">Return Home </a></p> '; // It worked.


	
	
 
?>

What exactly is not working ? What happens when you run it ? what was supposed to happen ? what error message do you get, if any ?

The updating of the SQL records isn’t working. What’s meant to happen is that it updates the mysql table according to the picture that’s been uploaded the code is then meant to display this new picture.

The error message I get is error whilst uploading. Which is what’s written into the script.