issues writing a image path to mysql database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Glenn Coyle

    issues writing a image path to mysql database

    Hi

    I am having trouble writing the file path of a image to the
    database,also for some reason it is not uploading the images, anyone
    have any ideas?

    the code is below:

    if($_POST[Submit] == 'Submit')
    {
    $target_path = "../reviewImages/";
    $target_path = $target_path . basename(
    $_FILES['uploadFile']['name']);
    if(move_uploade d_file($_FILES['uploadFile']['tmp_name'],
    $target_path)) {
    echo "The file ". basename( $_FILES['uploadFile']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try
    again!";
    }
    echo $target_path;

    $text = $_POST[text];
    $press = $_POST[press];
    $logo = "reviewImag es/".basename( $_FILES['uploadFile']['name']);
    echo $logo;
    $title = $_POST[title];
    $author = $_POST[author];
    $date = $_POST['date'];

    $sql = "INSERT into reviews (press, title, author, date, text,
    imagePath) VALUES ('$press', '$title', '$author', '$date', '$text',
    '$logo')";
    mysql_query($sq l) or die(mysql_error ());

    echo "Informatio n added to the reviews table";
    }

    cheers

    Glenn
  • petersprc@gmail.com

    #2
    Re: issues writing a image path to mysql database

    Check if you're using enctype="multip art/form-data" on the form. More
    info here:



    Example:

    <form enctype="multip art/form-data" action="post.ph p" method="POST">
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
    </form>

    Glenn Coyle wrote:
    Hi
    >
    I am having trouble writing the file path of a image to the
    database,also for some reason it is not uploading the images, anyone
    have any ideas?
    >
    the code is below:
    >
    if($_POST[Submit] == 'Submit')
    {
    $target_path = "../reviewImages/";
    $target_path = $target_path . basename(
    $_FILES['uploadFile']['name']);
    if(move_uploade d_file($_FILES['uploadFile']['tmp_name'],
    $target_path)) {
    echo "The file ". basename( $_FILES['uploadFile']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try
    again!";
    }
    echo $target_path;
    >
    $text = $_POST[text];
    $press = $_POST[press];
    $logo = "reviewImag es/".basename( $_FILES['uploadFile']['name']);
    echo $logo;
    $title = $_POST[title];
    $author = $_POST[author];
    $date = $_POST['date'];
    >
    $sql = "INSERT into reviews (press, title, author, date, text,
    imagePath) VALUES ('$press', '$title', '$author', '$date', '$text',
    '$logo')";
    mysql_query($sq l) or die(mysql_error ());
    >
    echo "Informatio n added to the reviews table";
    }
    >
    cheers
    >
    Glenn

    Comment

    Working...