yandoo Posted March 10, 2008 Share Posted March 10, 2008 Hi there, I currently have a little page of code that will INSERT an image into a folder and link it in a field in a table of my database. The trouble is i need to change the INSERT to an UPDATE as i need to detemrine what the ID record will be to add the image to it (unstead of inserting new record).... I have tried it out for some time and cant get it to work right...... This is the snipet of code i need to change from insert into update: $sql = "INSERT INTO `animal` (`AnimalID`,` `Image`) VALUES ('".$_POST['panimal']."','".$link_dir.$image_name."')"; if anybody can help that be super Thank You Heres the full code: <?php require_once('Connections/woodside.php'); ?><?php mysql_select_db($database_woodside, $woodside); $query_animal = "SELECT AnimalID FROM animal ORDER BY AnimalID DESC"; $animal = mysql_query($query_animal, $woodside) or die(mysql_error()); $row_animal = mysql_fetch_assoc($animal); $totalRows_animal = mysql_num_rows($animal); //image upload test $file_dir = "C:/wamp/www/Woodside/Images/"; $link_dir = "./Images/"; $file_url = "http://localhost/woodside/Images/"; if (isset($_POST['submit'])) { $image_name = $_FILES['image']['name']; $image_size = $_FILES['image']['size']; $image_type = $_FILES['image']['type']; $uploadfile = $file_dir.basename($image_name); if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; // Query to insert data mysql_select_db($database_woodside, $woodside); $sql = "INSERT INTO `animal` (`Image`) VALUES ('".$link_dir.$image_name."')"; echo "$sql<br />"; mysql_query($sql)or die(mysql_error()); } else { echo "Possible file upload attack!\n"; } //Uncomment these lines if you are having problems echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; print "<center>Image path: $file_dir<br>\n"; print "<center>Image name: $image_name<br>\n"; print "<center>Image size: $image_size bytes<br>\n"; print "<center>Image type: $image_type<p><br>\n\n"; print "<img src=\"$file_url/$image_name\"><p>\n\n"; } ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data"><br/> <input type="hidden" name="MAX_FILE_SIZE" value="100000"> <input type="file" accept=".jpg" size="20" name="image" title="Image Upload" /><br> <input type="submit" name=submit value="Submit"> <input name="panimal" type="hidden" value="<?php echo $row_animal['AnimalID']; ?>" /> </form> <?php mysql_free_result($animal); ?> . Link to comment https://forums.phpfreaks.com/topic/95494-convert-insert-to-update/ Share on other sites More sharing options...
DarkerAngel Posted March 10, 2008 Share Posted March 10, 2008 Those two functions are completely different Update is like this UPDATE `table` SET `column1`=$value1, `column2`=$value2, `column3`=$value3 WHERE `id`=$id Link to comment https://forums.phpfreaks.com/topic/95494-convert-insert-to-update/#findComment-488848 Share on other sites More sharing options...
yandoo Posted March 11, 2008 Author Share Posted March 11, 2008 Hi, yes i understand the difference with the two....im trying to integrate the image tho and am having difficulties getting it working.... $sql = "UPDATE `animal` SET `Image`=`$link_dir.$image_name` WHERE `AnimalID`=$query_animal"; The image uploads to the folder but not to the database....the error message says: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT AnimalID FROM animal ORDER BY AnimalID DESC' at line 1 Im obviously missing something here Thanks Link to comment https://forums.phpfreaks.com/topic/95494-convert-insert-to-update/#findComment-489839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.