Does anyone know how to do an else or if statement if no image is uploaded to a folder and only the filename (not the image itself) is placed into the mysql database when a user updates his or her information via a webpage?
I tried it and I keep getting errors spat at me by mysql... I tried doing my upload image code followed by an update table code with the echo of thankyou your image has been updated, then under it I had an else for an error statement (if the image is too big or the file not an image), then under that I put an if statement for no image and now all I get is a complete bunch of errors...
Here's one version of the code (I've been fiddling with taking out error statements and altering things around)
$sql_result2 = mysql_query("SELECT COUNT(*) FROM $table WHERE username = '" . mysql_real_escape_string($_POST['username']) . "' AND pw = '" . mysql_real_escape_string(md5($_POST['oldpw'])) . "'");
$count = mysql_result($sql_result, 0);
if ($count == 0) {
problem('You do not have permission to update this profile.');
}
elseif( isset($_FILES['image']) && $_FILES['image']['size']>0 ){
$directory = "$abs_path".$_FILES['image']['name'];
$t=0;
while(file_exists($filename)){
$filename = "$abs_path".$_FILES['image']['name'];
$filename = substr($filename,0,strpos($filename,"."))."_$t".strstr($filename,".");
$t++;
$uploaded = move_uploaded_file($_FILES['image']['tmp_name'], $filename);
if( $uploaded ) {
chmod($directory.$filename,0644);
$query = "UPDATE $table SET imagefile = '$filename' WHERE username = '$username' LIMIT 1";
$result3 = mysql_query($query) or problem('Cannot query the database.' . mysql_error());
}
echo "<p align=\"center\"><b>Image updated. . .</b></p>
<p align=\"center\"><font color=green>Thank you, $username. Your image has successfully been uploaded!</font></p>";
} else {
problem('Only images are allowed to be uploaded');
}
if ($filename !== "$uploaded")
{
echo "<p align=\"center\">Thank you, $username. Your information has successfully been updated!</p>";
}
else {
problem('There was an error updating your information');
}
$result4 = mysql_query($sql_result2) or problem('Cannot query the database.' . mysql_error());
All I want is for the user to be able to change their picture or just their information (the code for my update information works perfectly, it's just the option to update an image >_<) HELP!!!