Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    PHP/MYSQL overwrite HELP

    -code copyright-
    Last edited by terter2000; 01-14-2010 at 02:28 AM.

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ohio
    Posts
    254
    Thanks
    1
    Thanked 63 Times in 63 Posts
    Is the code you're writing part of the registration process?
    If so, have you even considered what would happen if somebody tries to register on your site using either "Username" or "jacson" (from your DB snippet) as their username when some other registered user already registered with those exact usernames?

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,541
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    not to mention sql injections.

    but I just don't have the time right now to give him/her the correct code,
    so i won't rip into it too much.

    Terter,
    You'll have to explain more about what your script is all about.

  • #4
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by shadowmaniac View Post
    Is the code you're writing part of the registration process?
    If so, have you even considered what would happen if somebody tries to register on your site using either "Username" or "jacson" (from your DB snippet) as their username when some other registered user already registered with those exact usernames?
    thats what i want?
    its like basically a script to update?
    if someone typed jacson in the username field and some data in the data field , it will overwrite.

  • #5
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    not to mention sql injections.

    but I just don't have the time right now to give him/her the correct code,
    so i won't rip into it too much.

    Terter,
    You'll have to explain more about what your script is all about.
    i am actually working on a shopping directory ,
    you enter your name and data,
    it will update the exisiting data.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,541
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    So there's way more to the script than what you show?
    There must be something there that makes sure the person
    is already logged in?

    And you're coding the whole thing from scratch?

  • #7
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    -code copyright-
    Last edited by terter2000; 01-14-2010 at 02:28 AM.

  • #8
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    So there's way more to the script than what you show?
    There must be something there that makes sure the person
    is already logged in?

    And you're coding the whole thing from scratch?
    no need , just replace with the text field
    the username textfield will check if there is identical , if there is just replace without any warning or what soever

    i know what i am doing , i am like combining 5 kinds of script together , this is 1 of the part.

  • #9
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    To replace an existing record or insert a new record if none exists, look at REPLACE (MySQL)
    John

  • #10
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by PappaJohn View Post
    To replace an existing record or insert a new record if none exists, look at REPLACE (MySQL)
    don't think i can do that with flash as3?

  • #11
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    please help experts !

  • #12
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    now i thought of a better example
    imagine if i login as "hellokitty"
    i decided to change the username to "hellopanda"

    how am i going to achieve that , because the above thingy is like what i wanted to do.

    isnt that using REPLACE in mysql using php?
    Last edited by terter2000; 01-13-2010 at 06:44 PM.

  • #13
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,541
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    $name=$_POST['username'];
    $entry=$_POST['entryname'];
    $query="UPDATE entries SET entry_name=`$entry` WHERE user_name=$name";
    $result = mysql_query($query) or die( "An error has ocured: " .mysql_error (). ":" .mysql_errno ());

  • Users who have thanked mlseim for this post:

    terter2000 (01-14-2010)

  • #14
    New Coder
    Join Date
    Jan 2010
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    +rep +thank , thanks a lot it works !

  • #15
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,541
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    Terter ...

    You should also "sanitize" all variables that go into an SQL query ...
    as a minimum, to avoid SQL injections.

    See this example:
    PHP Code:
    $name mysql_real_escape_string($_POST['username']);
    $entry mysql_real_escape_string($_POST['entryname']);
    $query "UPDATE entries SET entry_name=`$entry` WHERE user_name=$name"
    $result mysql_query($query) or die( "An error has ocured: " .mysql_error (). ":" .mysql_errno ()); 


  •  

    Posting Permissions

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