Jump to content

new mysql entry overwriting existing entry


Go to solution Solved by 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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.