updatting user information

Discussion in 'PHP' started by tldmic, Feb 14, 2010.

  1. #1
    Hi everyone,
    I am amarture into this php programming,I am designing my website and I have already everything upto user profile.Now I have to tables
    table1=users
    table2= userlocation,

    users needs to submit their country,let say, they are in a new country and they want to change the country name, they need to update the country table, so the problem is that,each time I update the table, it erases all the information stored in the user and userlocation, I have tried the following code and it doing exactly what I just said, will you please help

    thanks
    tldmic



    mysql_query("UPDATE users,userlocation SET users.`name` = '$data[name]',userlocation.`country` = '$_post[country]' WHERE users.id='$_SESSION[user_id]'&& userlocation.id='$_SESSION[user_id]'");




    <?php while (($row_settings = mysql_fetch_array($rs_settings)) && ($rowloc_settings = mysql_fetch_array($loc_settings)) ) {?>
    <form action="mysettings.php" method="post" name="myform" id="myform">
    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="3" class="forms">


    <tr>
    <td colspan="2"> name<br> <input name="name" type="text" id="name" class="required" value="<?php echo $row_settings['name']; ?>" disabled size="50">
    </td>
    </tr>


    <tr>
    <td colspan="2"> country<br> <input name="country" type="text" id="country" class="required" value="<?php echo $rowloc_settings['country']; ?>" size="50">
    </td>
    </tr>

    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <p align="center">
    <input name="doSave" type="submit" id="doSave" value="Save">
    </p>
    </form>
    <?php } ?>
     
    tldmic, Feb 14, 2010 IP
  2. nadiralishah_webexpert

    nadiralishah_webexpert Guest

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    whenever you try to update the country table, u saying it erases all stored information.. but there is no any delete query, so it cannot erase the stored data, however, may be it is updating so many records or may be all records with the new data.. just try to make ur update query simple;

    mysql_query("UPDATE users SET name = '".$_POST[name]."' WHERE id=".$_SESSION[user_id]);

    please make sure, session variable is having a value that is user id.

    and next query will be;

    mysql_query("UPDATE userlocation SET country= '".$_POST[country]."' WHERE id=".$_SESSION[user_id]);
     
    nadiralishah_webexpert, Feb 14, 2010 IP
  3. Kirill120

    Kirill120 Greenhorn

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    for extra security:

    $id = $_SESSION[user_id];
    $country = $_POST[country];

    sprintf("UPDATE `userlocation` SET `country`=`%s` WHERE `id`='%s'")or die('error: <br />'.mysql_error());
    mysql_real_escape_string($country);
    mysql_real_escape_string($id);

    the mysql escape string 'escape' any 'bad' chars to be enter into the database. like '',"",& or things like that.
     
    Kirill120, Feb 14, 2010 IP
  4. tldmic

    tldmic Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thank you guys,
    its working so well,
    i was so stressed about it, am so passonate about programming,
    I will not take the credit of this design alone, am with you guys,
    thanks verl muc
    tldmic
    :):)
     
    tldmic, Feb 15, 2010 IP