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 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2010
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mysql update in php not working

    TRYING TO UPDATE MYSQL DATABASE TABLE IN PHP.
    IT IS NOT WORKING.




    if ( $_SESSION['ACTION'] == "EDIT" ) {
    $LABELNAM = mysql_real_escape_string($_POST['LABELNAM']);
    $LABELCOD = mysql_real_escape_string($_POST['LABELCOD']);
    ?>

    <FORM METHOD="POST" ACTION="<?php $PHPURL ?>">
    <TABLE BORDER='10' WIDTH='400' BGCOLOR='BROWN'>
    <tr BGCOLOR="YELLOW">
    <TD><B><FONT FACE="ALGERIAN" COLOR="#9900FF" SIZE="6">LABEL NAME </FONT></B></TD>
    <td><INPUT TYPE="TEXT" NAME="LABELNAM" SIZE="50" MAXLENGTH="30" VALUE="<?php echo($LABELNAM) ?>"></td>
    <INPUT TYPE="HIDDEN" NAME="LABELCOD" VALUE="<?php echo($LABELCOD) ?>">
    <INPUT TYPE="HIDDEN" NAME="ACTION" VALUE="UPDATE">
    <TD><INPUT TYPE="SUBMIT" VALUE="UPDATE LABEL"></TD>
    </tr>
    </TABLE>
    </FORM>
    <?php
    }

    if ( $_SESSION['ACTION'] == "UPDATE" ){
    UPDATE_LABEL();

    }


    function UPDATE_LABEL(){
    $hostname ="localhost";
    $password ="";
    $username ="root";
    $CON =mysql_connect ($hostname, $username, $password) ;
    mysql_select_db("reggaedbf", $CON);
    $LABELCOD =mysql_real_escape_string( $_POST['LABELCOD'] );
    $LABELNAM =mysql_real_escape_string( $_POST['LABELNAM'] );
    $SQLLABEL =" UPDATE LABEL
    SET LABELNAM =" . $LABELNAM .
    " WHERE LABELCOD =" . $LABELCOD ;
    $RESULTS = mysql_query( $SQLLABEL, $CON );
    $_SESSION['ACTION'] = "ADD";
    }

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    I don't know if this is the issue, but try putting ' around the values, and ` around the fields

    Also, wrap your code in PHP tags, makes it easier to read.

    PHP Code:
    $SQLLABEL =" UPDATE `LABEL` SET `LABELNAM` = '" $LABELNAM "' WHERE `LABELCOD` ='" $LABELCOD "'; 


  •  

    Posting Permissions

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