I having problem updating User Records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • underground
    New Member
    • Sep 2006
    • 41

    I having problem updating User Records

    Hi, everyone I've been trying to figure out a way for a user to update there information. I'm using sections to identify the specific user..Here is the form

    [HTML]
    <?
    include("includ e/session.php");
    ?>
    <?
    $username="xxxx xx";
    $password="xxxx xxx";
    $database="xxxx x";
    mysql_connect(l ocalhost,$usern ame,$password);

    $query=" SELECT * FROM pix WHERE username='$sess ion->username'";
    $result=mysql_q uery($query);
    $num=mysql_numr ows($result);
    mysql_close();

    $i=0;
    while ($i < $num) {
    $whatsit=mysql_ result($result, $i,"whatsit");
    $firstname=mysq l_result($resul t,$i,"firstname ");
    $lastname=mysql _result($result ,$i,"lastname") ;
    $phonenumber=my sql_result($res ult,$i,"phonenu mber");
    $address=mysql_ result($result, $i,"address");
    $retail=mysql_r esult($result,$ i,"retail");
    $city=mysql_res ult($result,$i, "city");
    $state=mysql_re sult($result,$i ,"state");
    $zip=mysql_resu lt($result,$i," zip");

    ++$i;
    }
    ?>

    <html>
    <head>
    <title>Untitled </title>
    <style>
    body {
    font: 81% verdana, arial, sans-serif;
    background-color: #fff;
    margin: 10px;
    padding: 4px;
    }
    </style>
    </head>
    <body>
    <?php
    if($session->logged_in){
    echo "<table align=LEFT width=670 height=350 bgcolor=ffffff BORDER=1 BORDERCOLOR=eae aea cellpadding=5>" ;
    echo "<tr>";
    echo " <td bgcolor=#dddddd ><img src=\"http://www.atlantasund ergroundhitseco mmerce.com/flash_mp3_playe r/store copy.jpg\" width=667 height=128 alt= border=1><br>
    </td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td align=center bgcolor=#dddddd ><b><font color=gray size=1>Register s (Personal)Payme nt Information</font></b><br>
    </td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td bgcolor=eaeaea> <font color=gray size=1>All payments from Atlanta's UnderGround Hits to the register will be mailed to the following address. It is the responsiblity of the
    register to contact Atlanta's UnderGround Hits should their address change during the distribution period. <br><font color=red>It is important this information is valid.</font>
    </td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>
    <form enctype=multipa rt/form-data action=\"update _artistinfo.php \" method=\"post\" >
    <font color=gray size=2>First Name :&nbsp;&nbsp; </font><input name=\"ud_first name\" value=\"$firstn ame\">&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; <font color=gray size=2>E-Mail: <input name=\"ud_email \" value=\"$email\ ">
    </td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td><font color=gray size=2>Last Name :&nbsp;&nbsp; </font><input name=\"ud_lastn ame\"value=\"$l astname\">&nbsp ;&nbsp;&nbsp;&n bsp;<font color=gray size=2>Phone Number :&nbsp;</font><input name=\"ud_phone number\" value=\"$phonen umber\"></td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td><font color=gray size=2>Address :</font>&nbsp;&nbs p;&nbsp;&nbsp;< input name=\"ud_addre ss\" value=\"$addres s\">&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;<font color=gray size=2>Album Retail:&nbsp;</font><input name=\"ud_retai l\" value=\"$retail \"></td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td><font color=gray size=2>City :<font>&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ; <input name=\"ud_city\ " value=\"$city\" >
    </td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td><font color=gray size=2>State :&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;</font><SELECT name=\"ud_state \">
    <option>$stat e</option>
    <option value=\"AL\">AL ABAMA</option>
    </select></td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td><font color=gray size=2>ZIP CODE:<font>&nbs p;&nbsp;<input name=\"ud_zip\" value=\"$zip\"> </td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td bgcolor=>
    <br><br><font size=2 color=gray><b>U ser:</b>&nbsp;&nbsp;& nbsp;</font>
    <SELECT name=\"ud_usern ame\">
    <option>$sessio n->username</option>
    </select></td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td bgcolor=><hr color=eaeaea><f ont color=gray size=1>Once you have completed the above your will be ready to submit your information. You will then be direct to the album upload section of the Online Registartion.
    Your total album upload can be no more than 50 megs. Click the below submit to proceed. </font></td>";
    echo "</tr>";
    echo "<td>
    <input type=submit value=Submit>
    </form>
    </td>";
    echo "</tr>";
    echo "</table>";
    }
    else{
    ?>
    <TABLE>
    <TR>
    <Td>
    <h1>Login</h1>
    <?
    /**
    * User not logged in, display the login form.
    * If user has already tried to login, but errors were
    * found, display the total number of errors.
    * If errors occurred, they will be displayed.
    */
    if($form->num_errors > 0){
    echo "<font size=\"2\" color=\"#ff0000 \">".$form->num_errors." error(s) found</font>";
    }
    ?>
    <form action="process .php" method="POST">
    <table align="left" border="0" cellspacing="0" cellpadding="3" >
    <tr><td>Usernam e:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user" ); ?>"></td><td><? echo $form->error("user" ); ?></td></tr>
    <tr><td>Passwor d:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass" ); ?>"></td><td><? echo $form->error("pass" ); ?></td></tr>
    <tr><td colspan="2" align="left"><i nput type="checkbox" name="remember" <? if($form->value("remembe r") != ""){ echo "checked"; } ?>>
    <font size="2">Rememb er me next time &nbsp;&nbsp;&nb sp;&nbsp;
    <input type="hidden" name="sublogin" value="1">
    <input type="submit" value="Login"></td></tr>
    <tr><td colspan="2" align="left"><b r><font size="2">[<a class=T1 href="forgotpas s.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
    <tr><td colspan="2" align="left"><b r>Not registered? <a class=T1 href="register. php">Sign-Up!</a></td></tr>
    </table>
    </form>

    <?
    }

    /**
    * Just a little page footer, tells how many registered members
    * there are, how many users currently logged in and viewing site,
    * and how many guests viewing site. Active users are displayed,
    * with link to their user information.
    */
    echo "</td></tr><tr><td align=\"center\ " class=T1><br><b r>";
    echo "<b>Update your profile information <br>";
    ?>
    </td></tr>
    </table>
    </body>
    </html>
    [/HTML]
    The form displays the current information the user has stored in the DB. Once the user makes changes this is the PHP SCRIPT that should update the database.

    [PHP]
    <?php
    // check to see if the form was posted with the correct id's
    if (isset($_POST['_submit']) AND isset($_REQUEST['ud_username']) ) {
    $ud_username = intval($_REQUES T['ud_username']);
    if ($ud_username < 0) {

    # escape data and set variables
    $ud_username = addslashes($_PO ST["ud_usernam e"]);
    $ud_firstname = addslashes($_PO ST["ud_firstna me"]);
    $ud_email = addslashes($_PO ST["ud_email"]);
    $ud_lastname = addslashes($_PO ST["ud_lastnam e"]);
    $ud_phonenumber = addslashes($_PO ST["ud_phonenumber "]);
    $ud_address = addslashes($_PO ST["ud_address "]);
    $ud_retail = addslashes($_PO ST["ud_retail"]);
    $ud_city = addslashes($_PO ST["ud_city"]);
    $ud_state = addslashes($_PO ST["ud_state"]);
    $ud_zip = addslashes($_PO ST["ud_zip"]);

    $usr = "xxxxxxx";
    $pwd = "xxxxx";
    $db = "xxxxx";
    $host = "xxxx";
    // connect to database server
    $cid = mysql_connect($ host,$usr,$pwd)
    or die("Server connnect ERROR: " . mysql_error());
    // select the database
    mysql_select_db ($db)
    or die("Database select ERROR: " . mysql_error());
    $query="UPDATE pix SET firstname='$ud_ firstname', email='$ud_emai l', lastname='$ud_l astname', phonenumber='$u d_phonenumber', address='$ud_ad dress', retail='$ud_ret ail', city='$ud_city' , state='$ud_stat e', zip='$ud_zip' WHERE username= '$ud_username'" ;
    mysql_query($qu ery);
    echo "Record Updated";
    mysql_close();
    ++$i;
    }
    ?>
    [/PHP]

    but when clicked nothing happens. The information is not being updated in the database. Could a brotha get a little help on this one!!!! It seems simply so I know I making a small mistake.

    Thank You
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    1. why don't you append the mysql_error() to the UPDATE statement[php]mysql_query($qu ery) or die
    "Update error: ".mysql_error() ;[/php] so you know it is / or not an update error

    2. when the form is not submitted correctly, i.e. where is the ELSE branch of this statement[php]if (isset($_POST['_submit']) AND isset($_REQUEST['ud_username']) ) {[/php]

    3. I cannot find the close brace of the IF statement nor the ELSE of that statement.

    In cases 2 and 3 your script ends without action or message.

    Ronald :cool:

    Comment

    • underground
      New Member
      • Sep 2006
      • 41

      #3
      Problemed solved..Thanks again Ronald !

      Comment

      Working...