myrok24 Posted September 29, 2008 Share Posted September 29, 2008 Hi there, Im dealing with this problem for a long time now, i need your help please!. I have this update page, where i can change a title and an image. New text and images works fine, but if i DON'T change the picture (only text or even nothing at all), it's going wrong somewhere. It should check wether the image is changed or not. if it's NOT: don't do anything with it and keep it.. please.. it's probably (i hope) a simple problem.. thnx! My code: <?php include '../library/config.php'; include '../library/opendb.php'; if (!isset($_GET['id'])) { echo "Album id is not defined"; exit; } else if(isset($_POST['upload'])) { $id = $_POST['id']; $name = $_POST['name']; $label = $_POST['label']; if (!get_magic_quotes_gpc()) { $name = addslashes($name); $label = addslashes($label); } if ($_FILES['userfile']['tmp_name']) { $name = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $uploadDir = '../image/'; $filePath = $uploadDir . $name; if( file_exists($filePath) ) { unlink($filePath); } $result = move_uploaded_file($tmpName, $filePath); // $result = move_uploaded_file($tmpName, $_SERVER['DOCUMENT_ROOT'] . '/image/' . $_FILES['userfile']['name']); if (!$result) { echo "Error uploading file"; exit; } } else { $name = ""; //zit hier de fout?... } $query = "UPDATE upload ". "SET label = '$label', name = '$name', path = '$filePath',size = '$fileSize', type = '$fileType' ". "WHERE id = '{$_GET['id']}'"; mysql_query($query) or die('Error, modify album failed : ' . mysql_error()); } else { $id = $_GET['id']; $sql = "SELECT id, name, label, path FROM upload WHERE id = '{$_GET['id']}'"; $result = mysql_query($sql) or die('Error, get album info failed. ' . mysql_error()); if (mysql_num_rows($result) == 0) { } else { $row = mysql_fetch_assoc($result); ?> <form action="" method="post" enctype="multipart/form-data" name="uploadform"> <table width="400" border="0" cellpadding="8" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#990066"> <tr> <td class="info">Titel:</td> <td><input name="label" type="text" id="label" value="<?php echo $row['label']; ?>"> </td> </tr> <tr> <td class="info">Locatie:</td> <td><input name="path" type="text" id="path" value="<?php echo $row['path']; ?>"> </td> </tr> <tr> <tr> <td class="info">Huidge afbeelding: </td> <td><?php echo '<img class=scale2 src="../image/' . $row['name'] . '" />' ; ?></td> </tr> <tr> <td class="info">Afbeelding uploaden:</td> <td><input name="userfile" type="File" class="box" id="userfile" size="15"></td> </tr> <tr> <td class="info"> </td> <td><input name="upload" type="Submit" id="upload" value="Uploaden"> <input type="hidden" name="id" value="<? echo "$id"; ?>" /></td> </tr> </table> </form> <?php } } ?> <input name="btnCancel" type="button" id="btnCancel" value="Terug" onclick="window.history.back(); Link to comment https://forums.phpfreaks.com/topic/126301-update-image-problem/ Share on other sites More sharing options...
myrok24 Posted September 30, 2008 Author Share Posted September 30, 2008 Someone please?.. Link to comment https://forums.phpfreaks.com/topic/126301-update-image-problem/#findComment-653676 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.