doddsey_65 Posted November 22, 2009 Share Posted November 22, 2009 Okay here is the code: if (isset ($_COOKIE['ID_my_site'])) { $username = mysql_real_escape_string($_COOKIE['ID_my_site']); $pass = mysql_real_escape_string($_COOKIE['Key_my_site']); $check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or trigger_error (mysql_error()); if (mysql_num_rows ($check) > 0) { $info = mysql_fetch_array ($check); //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } else { $uploadDir = 'uploads/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } if(!get_magic_quotes_gpc()) { $filePath = addslashes($filePath); } $query = ("UPDATE users SET path='$filePath' WHERE username='$username'"); echo $query; } } } } else { header("Location: login.php"); exit (0); } ob_flush(); ?> When i run it the image is uploaded to the server but the db row isnt updated. Yet when i echo the query and put that into phpmyadmin it works fine. So why doesnt it work in php? Cheers Link to comment https://forums.phpfreaks.com/topic/182552-update-not-working/ Share on other sites More sharing options...
corbin Posted November 22, 2009 Share Posted November 22, 2009 Have you tried checking mysql_error to see why MySQL is saying it's not working? Link to comment https://forums.phpfreaks.com/topic/182552-update-not-working/#findComment-963514 Share on other sites More sharing options...
doddsey_65 Posted November 22, 2009 Author Share Posted November 22, 2009 yep and there are no errors at all Link to comment https://forums.phpfreaks.com/topic/182552-update-not-working/#findComment-963517 Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2009 Share Posted November 23, 2009 There's no code in your code to execute the UPDATE query. Adding a mysql_query() statement would be your best bet. Link to comment https://forums.phpfreaks.com/topic/182552-update-not-working/#findComment-963567 Share on other sites More sharing options...
mattyvx Posted November 23, 2009 Share Posted November 23, 2009 ..... $query = "("UPDATE users SET path='$filePath' WHERE username='$username'")"; mysql_query($query); // run your query! echo $query; } ....... should do the trick.... Link to comment https://forums.phpfreaks.com/topic/182552-update-not-working/#findComment-963579 Share on other sites More sharing options...
doddsey_65 Posted November 23, 2009 Author Share Posted November 23, 2009 @mattyvx: yeh that did it, although i did it before reading this i cant believe i missed the fact that i wasnt even running the query lol, bit embarrising but atleast it works now. Cheers for he help guys Link to comment https://forums.phpfreaks.com/topic/182552-update-not-working/#findComment-963624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.