Jump to content

new mysql entry overwriting existing entry


cloudll

Recommended Posts

I am using php to upload a file to my server, and at the same time inserting the files name and url into my mysql database.

$sql = "UPDATE uploads SET name = '$name', url='$target_path'";
    $statement = $dbh->prepare($sql); 
    $statement->execute();

This is working, however, when I upload a new file, rather than making a new entry in my database, it just overwrites the first one.

I'm quite new at mysql so was wondering how I would make it add new entrys instead of overwriting the current one?

What are the columns in the uploads table?  Does it have a primary key?

 

Also, you are not doing your prepared statements correct!  You do not put the values in the query but add placeholders in the query (either ? or :name), and pass the values as an array to the execute method.  Yes, your query will work, but it is not escaping anything.

Archived

This topic is now archived and is 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.