UPDATE statement not working

I need to update an existing MySQL database which has 10 fields:

  1. id_abst
  2. first_name
  3. last_name
  4. email
  5. grad_student
  6. title
  7. rev_title
  8. timestamp
  9. rev_timestamp
  10. login

It is initially is populated with 8 fields. One of the fields is a file. At a later date, the user can upload a revised version if they would like. We would like to add the revised version (rev_title) of the file rather than overwrite the original. The time of the upload (rev_timestamp) would also be added.

From all I read this should be very simple, but unfortunately it’s not working for me. I’m comparing the unique code (login) which was emailed to the user at initial upload to the $rev_code entered by user at time of revision upload.

Can someone please help me find my mistake(s)? Thanks!

[php]
$rev_code = $_POST[‘revisioncode’]; // revisioncode name of form text box
$rev_title = $_POST[‘uploadfile’]; // uploadfile name of form text box
$timestamp = date(‘F dS Y h:i:s A’);

$count = 0;
		
// assign database info to php variable
$db_hostname = "*****";
$db_username = "*****";
$db_password  = "*****";
$database       = "*****";

//Connecting to your database
mysql_connect($db_hostname, $db_username, $db_password);
@mysql_select_db($database) or die("Unable to select database");

// Get all the data from table
$result = mysql_query("SELECT * FROM table_name") or die( mysql_error() );  

while($row = mysql_fetch_array($result))
{
	if ($row['login'] == $rev_code)
	{
		// debuggig - looking at correct values?  *****************************************
		echo "login =  " . 	$row['login'] . "   matches user input  " . $rev_code . "<br>";
		// ********************************************************************************
		
		$query = "UPDATE abstract_submission_2014 SET rev_title='$rev_title', rev_timestamp='$timestamp' WHERE login='$rev_code'])";
		
		$count = 1;		// allows printing of "no match" statement
		
	}  // end IF
}  // end WHILE

if ($count == 0)
	echo "Sorry, no match found. Try again.";

	
mysql_query($query);
mysql_close();

[/php]

I found the error… on line 29, I had unnecessary “])” at the end.
Sorry - should’ve caught it earlier.

Sponsor our Newsletter | Privacy Policy | Terms of Service