Hi all, probably a super simple question here but what would be the best way to go about editing the image (as in, image name) in mysql - sort of...
Currently, this script will display current details and image for associated artists by artistid. I want to basically say if there's a new image uploaded, update the database with the new image, and if no image was uploaded (ie, $uploadedimage is empty), use the current image and do nothing to the image field.
I've included everything between the body tags so we don't miss anything. Thanks for viewing.
---edit_artist.php---
<?php
include("../config.php");
if($submit)
{
$target_path = "/var/www/html/artists/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br>\n";
chmod("$target_path", 0777);
$image_entry = mysql_real_escape_string($_FILES['uploadedfile']['name']);
}
$bandname = mysql_real_escape_string($_POST['bandname']);
$description = mysql_real_escape_string($_POST['description']);
$website_url = mysql_real_escape_string($_POST['website_url']);
//add automatic line breaks
$description = ereg_replace(13,"<p>",$description);
//get ride of slashes
$description = stripslashes($description);
$bandname = stripslashes($bandname);
$result = mysql_query("UPDATE artists SET bandname='$bandname', description='$description', website_url='$website_url', image_path='$image_entry' WHERE artistid='$artistid' ",$connect);
echo "<b>Artist updated successfully!<br>You'll be redirected to the control panel after (4) seconds, or click <a href=\"index.php\">click here</a> to go there now.\n";
echo "<meta http-equiv=Refresh content=4;url=index.php>";
}
elseif($artistid)
{
$result = mysql_query("SELECT * FROM artists WHERE artistid='$artistid' ",$connect);
while($myrow = mysql_fetch_assoc($result))
{
$bandname = $myrow["bandname"];
$description = $myrow["description"];
$website_url = $myrow["website_url"];
$image_path = $myrow["image_path"];
?>
<br>
<h3>::Edit Artist</h3>
<form enctype="multipart/form-data" action="<?php echo $PHP_SELF ?>" method="POST">
<p>Please be careful not to delete any line break or paragraph break tags shown as <strong><p></strong> or <strong><br></strong>.<br>
These are paragraph formatting tags that have been dynamically generated by this software.</p>
<p>
<input type="hidden" name="artistid" value="<? echo $myrow['artistid']?>">
<p>Band Name:<br>
<input name="bandname" size="40" maxlength="255" value="<?php echo $bandname; ?>">
<br>
<br>
<p>Artist Image:<br>
<br>
<img src="../../artists/<?php echo $image_path; ?>" title="<?php echo $bandname; ?>">
<br>
<br>
Image File (required):<br />
<input name="uploadedfile" type="file" />
<br>
<br>
Description:<br>
<textarea name="description" rows="7" cols="30"><?php echo $description; ?></textarea>
<br>
<br>
Website URL: (with http://) <br>
<input name="website_url" size="40" maxlength="255" value="<?php echo $website_url; ?>">
<br>
<br>
<input type="submit" name="submit" value="Edit Artist >>">
<br>
<a href="index.php"><-- Go Back</a> </p>
</p>
</form>
<?
}//end of while loop
}//end else
?>