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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Duplicate entry error

    Hi ,

    i know this is also related to mysql but i think the problem is actually with my PHP code.

    anyway here s the problem.

    i have a table containing text fields etc and that contains the data stored for the member in the DB
    when the submit button is hit the db should get updated but all im getting is duplicate entry for " key 2

    here is the query
    PHP Code:
    <?php
    $currentPage 
    $_SERVER["PHP_SELF"];

    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }

    $editFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset(
    $_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
      
    $updateSQL sprintf("UPDATE members SET memid=%, password=%s, realname=%s, age=%s, location=%s, sex=%s, country=%s, starsign=%s, sexuality=%s, profession=%s, marital_status=%s, hair=%s, eyes=%s, height=%s, body_type=%s, race=%s, lookingfor=%s, seeking=%s, likes=%s, dislikes=%s, emailaddress=%s, pwdreminder=%s,  my2cents=%s WHERE username='$_SESSION[MM_Username]'",
                           
    GetSQLValueString($_POST['password'], "text"),
                           
    GetSQLValueString($_POST['realname'], "text"),
                           
    GetSQLValueString($_POST['age'], "int"),
                           
    GetSQLValueString($_POST['location'], "text"),
                           
    GetSQLValueString($_POST['sex'], "text"),
                           
    GetSQLValueString($_POST['country'], "text"),
                           
    GetSQLValueString($_POST['starsign'], "text"),
                           
    GetSQLValueString($_POST['sexuality'], "text"),
                           
    GetSQLValueString($_POST['profession'], "text"),
                           
    GetSQLValueString($_POST['marital_status'], "text"),
                           
    GetSQLValueString($_POST['hair'], "text"),
                           
    GetSQLValueString($_POST['eyes'], "text"),
                           
    GetSQLValueString($_POST['height'], "text"),
                           
    GetSQLValueString($_POST['body_type'], "text"),
                           
    GetSQLValueString($_POST['race'], "text"),
                           
    GetSQLValueString($_POST['lookingfor'], "text"),
                           
    GetSQLValueString($_POST['seeking'], "text"),
                           
    GetSQLValueString($_POST['likes'], "text"),
                           
    GetSQLValueString($_POST['dislikes'], "text"),
                           
    GetSQLValueString($_POST['emailaddress'], "text"),
                           
    GetSQLValueString($_POST['pwdreminder'], "text"),
                           
    GetSQLValueString($_POST['my2cents'], "text"),
                           
    GetSQLValueString($_POST['memid'], "int"));

      
    mysql_select_db($database_OnlineFlirting$OnlineFlirting);
      
    $Result1 mysql_query($updateSQL$OnlineFlirting) or die(mysql_error());

      
    $updateGoTo "myaccount.php?messages=Profile Successfully Updated";
      if (isset(
    $_SERVER['QUERY_STRING'])) {
        
    $updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
        
    $updateGoTo .= $_SERVER['QUERY_STRING'];
      }
      
    header(sprintf("Location: %s"$updateGoTo));
    }
    ?>
    my HTML form is fine so the probelm lies in the above code
    i need this solved asap as i have already passed my deadline
    any help would be greatly appreciated

    thanks

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it's a dataaseproblem. Check the table you are updating. There is an index with unique values and your updatestatement tries to update a record and give it an already existing value for that index.

    It could help to echo out $updateSQL and then look for the duplicate value.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Oct 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Raf your a life saver...
    it made me realise that the emailaddress was a hiddenfield and that it was being passed empty ( theres already 1 Null filed in the db ) hence the error



    thanks so much !!!

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you're welcome
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

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