stouffers3 Posted March 29, 2007 Share Posted March 29, 2007 I have a page that I use for users on my site to upload an image (displayed on their personal page). I am trying to figure out how I can update/replace the image in the database so that they can change their image. Can binary data be updated? Here's the code for my upload script: <?php // code that will be executed if the form has been submitted: if ($submit) { // connect to the database mysql_select_db($database_mydatabase, $mydatabase); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result=MYSQL_QUERY("INSERT INTO binary_data (username, bin_data,filename,filesize,filetype) ". "VALUES ('$username','$data','$form_data_name','$form_data_size','$form_data_type')"); print "<p>Your image has been uploaded"; MYSQL_CLOSE(); } else { ?> </p> <form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <table width="300" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Username:</td> <td><input type="text" name="username" /></td> <tr> <td align="right">Image:</td> <td><input type="file" name="form_data" size="40"></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="submit" ></td> </tr> </table> <br> <br> <p> </form> <?php } ?> I tried using UPDATE ... SET ... but that won't work. PS. If I can't update binary data, are there any suggestions of how my users could change their picture. One thing I've thought of is on upload renaming the image with the user's username?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/44855-updating-images-binary-data/ Share on other sites More sharing options...
BlackenedSky Posted March 30, 2007 Share Posted March 30, 2007 update should have worked. check your syntax, and echo "mysql_error()" to see what's wrong, and it will also check if your syntax is valid (only outputs on an error,otherwise blank) Quote Link to comment https://forums.phpfreaks.com/topic/44855-updating-images-binary-data/#findComment-217837 Share on other sites More sharing options...
stouffers3 Posted March 30, 2007 Author Share Posted March 30, 2007 I am not getting an error. I get "your image has been uploaded". But when I go to the database the old image is there, nothing has changed. M update page code: <?php require_once('../Connections/mydatabase.php'); ?> <?php $colname_image = "-1"; if (isset($_GET['username'])) { $colname_image = (get_magic_quotes_gpc()) ? $_GET['username'] : addslashes($_GET['username']); } mysql_select_db($database_mydatabase, $mydatabase); $query_image = sprintf("SELECT * FROM binary_data WHERE username = '%s'", $colname_image); $image = mysql_query($query_image, $mydatabase) or die(mysql_error()); $row_image = mysql_fetch_assoc($image); $totalRows_image = mysql_num_rows($image); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <p>Image uploaded for: <?php echo $row_image['username']; ?> <?php // code that will be executed if the form has been submitted: if ($submit) { // connect to the database mysql_select_db($database_mydatabase, $myspace); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result=MYSQL_QUERY("UPDATE binary_data SET(bin_data,filename,filesize,filetype) ". "VALUES ('$data','$form_data_name','$form_data_size','$form_data_type')"); print "<p>Your image has been uploaded"; MYSQL_CLOSE(); } else { ?></p> <p><form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <table width="300" border="0" cellspacing="0" cellpadding="0"><tr> <td align="right">Image:</td> <td><input type="file" name="form_data" size="40"></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="submit" ></td> </tr> </table> <br> <br> <p> </form></p> <?php } ?> </body> </html> <?php mysql_free_result($image); ?> I don't know what else to do. Please help Quote Link to comment https://forums.phpfreaks.com/topic/44855-updating-images-binary-data/#findComment-217863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.