Results 1 to 3 of 3

Thread: Amend and Delete data from database

  1. #1
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Amend and Delete data from database

    Hello I can you help me with my amend code because is not working.Also if someone could give me a Delete.php code it would be great
    Here is my code:

    Amend.php

    <?php
    $con = mysql_connect("*****","*****","****");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("*****", $con);

    $sql="UPDATE Users
    SET name='$_POST[name]', username='$_POST[username]'
    WHERE name='$keywords' AND username='$keywords'";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "User details successfully updated";

    mysql_close($con)
    ?>

    Thanks in advance

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I think you should start with a tutorial to understand the basics of MySQL, such as DELETE. I like this tutorial:
    http://php-mysql-tutorial.com (note that you'll want to look for the oldest articles to start)

    As for your code above, it looks generally correct, but I see two problems:
    1. You must escape the user input data because if you don't it will be a huge security risk-- someone can inject MySQL code just by using syntax like '; DROP DATABASE `name`; (sent from the form).
    It's easy to do this, though:
    $variable = mysql_real_escape_string($variable);
    Do that for all of your $_POST variables (and maybe others) before the query. That will make the data secure (escape it so that it can't contain any commands).

    2. I don't see $keywords set anywhere. That's probably why nothing is happening.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Ok solved it thanks.
    Last edited by ntin0s; 11-29-2010 at 02:09 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •