I need to update an existing MySQL database which has 10 fields:
- id_abst
- first_name
- last_name
- grad_student
- title
- rev_title
- timestamp
- rev_timestamp
- 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]