Hi there guys, I seem to be having a silly issue and I cant figure out why, my code is working fine for uploading and storing the image name in the datebase, but my issue come about when the form gets sumitted with no file selected I do want this to happen! but I would like a hidden field to be used as the file name that is update the database with "spacer.png"

if $photoname = empty then use this string "spacer.jpg"

Carry on and insert into datebase

Any help would be appreciated?

thanks in advance


//This is the directory where images will be saved
$target = "memberFiles/$userid/blessings/";
$target = $target . basename( $_FILES['photo']['name']);
$spacer = "spacer.png";
//This gets all the other information from the form

//Connect to the database through our include 
include_once "connect_to_mysql.php";

// Place Session variable 'id' into local variable
$id = $_SESSION['id'];
// Process the form if it is submitted
if ($_POST['blessing1']) {

    $blessing1 = mysql_real_escape_string(     $_POST['blessing1']);
    $userid = $_POST['userid'];

    $sql1 = mysql_query("INSERT INTO blessings (userid, blessing1, photo, datepublished) 
        VALUES('$userid','$blessing1','$photoname', now())") or die (mysql_error());

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
else {

//Gives and error if its not
header('Location: view_blessings.php');

        header('Location: view_blessings.php');

} // close if post
5 Years
Discussion Span
Last Post by richlacey

i didn't use php for a long time but i guess if you put this code in line 20 would work it out if you mean with your question to change the empty name with 'spacer.png'

if ($_FILES['photo']['name']!=""){$photoname=$_FILES['photo']['name'];}
else {$photoname=$spacer;}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.