Jump to content

Help with PHP script please


Stevis2002

Recommended Posts

Thanks for the help.

I had a permissions and directory error after that, but i sorted that one out, but then i get this error and i don't know what this means ...

The file has been uploaded
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\admin\includes\add_plant.php:45) in C:\Program Files\xampp\htdocs\admin\includes\add_plant.php on line 69

BTW....All data is going into db correctly now, although the image still isn't being uploaded/moved.
Link to comment
Share on other sites

The problem i now with

header(sprintf("Location: %s", $insertGoTo));

You can't call header once  data has already been output to the browser. In your case you have sent the "Your file has been uploaded message"

I'd remove the message. As you immediately want to go to another page the user wouldn't see it anyway.

Or, instead of header(), output a meta-refresh tag with a delay of a couple of seconds so user can read message before it goes to the nex page.
Link to comment
Share on other sites

Thanks again.....I have removed the message, but the page doesn't get forwarded on, and the image still isn't getting uploaded.

[code]
    mysql_select_db($database_localhost, $localhost);
    $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
    $insertGoTo = "plants.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $insertGoTo));
    exit;
[/code]
Link to comment
Share on other sites

Are you getting an error message still?

The file isn't uploaded because that section of code is still using the non-existent 'image_name' index instead of 'name'

[quote]
    $uploaddir = '/plants/';
    $uploadfile = $uploaddir . basename($_FILES['userfile']['image_name']);

    if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir)) {
        echo "The file ".  basename( $_FILES['userfile']['image_name']).
        " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
[/quote]

On reading that bit of code again, you need to change code so that in the event the upload fails you do not update the db.
Link to comment
Share on other sites

Changed the layout so that if there is an error then it dies, but it still enters the info into the db, it doesn't mention any error, but the image still isn't in the correct directory :(

[code]
    $uploaddir = '\plants';
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

    if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir)) {


   
    $insertSQL = sprintf("INSERT INTO plants (image_name, image_type, image_size, path, plant_name, plant_type, planting_months, blooming_season, plant_description) VALUES ('%s', '%s', '%s', '%s', %s, %s, %s, %s, %s)",
    $fileImagename,
    $fileImagetype,
    $fileImagesize,
$uploaddir,
    GetSQLValueString($_POST['plant_name'], "text"),
    GetSQLValueString($_POST['plant_type'], "text"),
    GetSQLValueString($_POST['planting_months'], "text"),
    GetSQLValueString($_POST['blooming_season'], "text"),
    GetSQLValueString($_POST['plant_description'], "text"));

    mysql_select_db($database_localhost, $localhost);
    $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
    $insertGoTo = "plants.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $insertGoTo));
    exit;
    } else{
        echo "There was an error uploading the file, please try again!";
    }
}
?>
[/code]
Link to comment
Share on other sites

Barand....You my friend are a complete legend...a saint of all patient programmers!!!
With a little messing, i got rid of the error statement completely...don't need it, due to the fact that if there is a problem, the script wont go onto the forwarding page anyway, so i will now there is a prob, as the script is just to enter the info into the db anyway, and only i will be doing that!

I can manage the data layout and all that jazz myself for the users end.

So, Thanks once more for the patience and understanding you have with us [s]dunces[/s] newbies.

Steve
Link to comment
Share on other sites

  • 2 years later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.