1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

MySQL is Updating With the Wrong Number... somehow

Discussion in 'MySQL' started by jdoerr, Dec 24, 2010.

  1. #1
    I am completely confused on how this could happen, but here are the lines of code that matter:

    $sent_phone_number = $_POST['phone_number'];
    
    $result = mysql_query("UPDATE customer_register SET customer_number='$sent_phone_number' 
    WHERE customer_key='$customer_key'") or DIE(mysql_error());
    
    echo "Your number is ". $sent_phone_number;
    PHP:
    I enter my phone number into the form that posts to this PHP file and then this file says my phone number correctly AFTER it's supposed to put it in the database, but for some reason it keeps putting a different number into the database and then outputting the correct one. It always adds the same number to the database, but it's not even close to my number. Does anyone know how this could happen or how to fix it?

    Thank you very much if you can help
     
    jdoerr, Dec 24, 2010 IP
  2. Minimal Hank

    Minimal Hank Peon

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Most probably it happends due to an invalid MySQL field data type - change it to varchar ( just an example ) and see how things change.
     
    Minimal Hank, Dec 24, 2010 IP
  3. mcfc4eva

    mcfc4eva Well-Known Member

    Messages:
    602
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    110
    #3
    I had a similar problem. It seemed to be an error with the Database rather than the programming.

    I had to change the field type of the phone number to "VARCHAR" rather than "NUMBER" and it worked fine after that.

    Unfortunately I don't know the reason behind it, just managed to figure out the solution.

    Hope this helps
    --Mike
     
    mcfc4eva, Dec 24, 2010 IP
  4. jdoerr

    jdoerr Active Member

    Messages:
    121
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #4
    It worked! Thank you!! :)
     
    jdoerr, Dec 24, 2010 IP
  5. mcfc4eva

    mcfc4eva Well-Known Member

    Messages:
    602
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Okay so we've established a solution for the problem but can anybody actually explain why this happens? It baffled me.
     
    mcfc4eva, Dec 24, 2010 IP
  6. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #6
    mastermunj, Dec 27, 2010 IP
    mcfc4eva likes this.
  7. mcfc4eva

    mcfc4eva Well-Known Member

    Messages:
    602
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    110
    #7
    Ahh! Of course!
    I should have guessed that one I was using a signed INT data type where the maximum value is 2147483647. Every time a user entered a number above this maximum value, it would automatically change to 2147483647. This of course produced problems because the field was a primary key!

    Thanks mastermunj, reputation added :)
     
    mcfc4eva, Dec 27, 2010 IP