mrsoul Posted March 10, 2009 Share Posted March 10, 2009 i have here a registration code which i've done already but i'm thinking how to update records from my previous data in my registration form?(for example,when you are going to registered in a yahoo account and when i'm going to change or update some of my records, i'm going to login and edit my account and you will notice that you are doing the same thing when you are signing in but the different for now is you are going only to update or change some information their)Just something like that....Here is my already done code : //register.php <?php // Connects to your Database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("store") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'", $conn) or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = ($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } // now we insert it into the database $insert = "INSERT INTO users (username,password,password2,familyname,firstname,middlename,registeredname,status,gender,datebirth,placebirth,nationality,address,office,telephone,mobile,presentposition,email,elementary,highschool,college,educationalgrowth,schoolwhereobtained,year,nameofspouse,dateofmarriage,numberofchildren,graduate,department) VALUES ('".$_POST['username']. "','".$_POST['pass']. "','".$_POST['pass2']. "','".$_POST['familyname']. "','".$_POST['firstname']. "','".$_POST['middlename']. "','".$_POST['registeredname']. "','".$_POST['status,']. "','".$_POST['gender']. "','".$_POST['datebirth']. "','".$_POST['placebirth']. "','".$_POST['nationality']. "','".$_POST['address']. "','".$_POST['office']. "','".$_POST['telephone']. "','".$_POST['mobile']. "','".$_POST['presentposition']. "','".$_POST['email']. "','".$_POST['elementary']. "','".$_POST['highschool']. "','".$_POST['college']. "','".$_POST['educationalgrowth']. "','".$_POST['schoolwhereobtained']. "','".$_POST['year']. "','".$_POST['nameofspouse']. "','".$_POST['dateOfmarriage']. "','".$_POST['numberofchildren']. "','".$_POST['graduate']. "','".$_POST['department']."')"; $add_member = mysql_query($insert); ?> <h1>Registered</h1> <p>Thank you, you have registered. You want to see you account,click</a>.</p> <?php echo "<a href=members.php>My Profile</a>"; ?> <?php } else { ?> <h1><p align="center"> Welcome to registration page.</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table align="center" border="0"> <tr><td width="310">Username:</td><td> <input type="text" name="username" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><td>Family Name:</td><td> <input type="text" name="familyname" maxlength="60"> </td></tr> <tr><td>First Name:</td><td> <input type="text" name="firstname" maxlength="60"> </td></tr> <tr><td>Middle Name:</td><td> <input type="text" name="middlename" maxlength="60"> </td></tr> <tr><td>Registered Name as a Student:</td><td> <input type="text" name="registeredname" maxlength="60"> </td></tr> <tr><td>Status:</td><td> <select name="status"> <option value=0>Select</option> <option value=Marriage>Marriage</option> <option value=Devorce>Devorce</option> <option value=Single>Single</option> </select></td></tr> <tr><td>Gender:</td><td> <select name="gender"> <option value=0>Select</option> <option value=Male>Male</option> <option value=Female>Female</option> </select></td></tr> <tr><td>Date of Birth:</td><td> <input type="text" name="datebirth" maxlength="60"> </td></tr> <tr><td>Place of Birth:</td><td> <input type="text" name="placebirth" maxlength="60"> </td></tr> <tr><td>Nationality:</td><td> <input type="text" name="nationality" maxlength="60"> </td></tr> <tr><td>Address:</td><td> <input type="text" name="address" maxlength="60"> </td></tr> <tr><td>Office:</td><td> <input type="text" name="office" maxlength="60"> </td></tr> </table><br> <table align="center" border="4"> <td width="450"><b>Contact Number</td></b> </table> <table align="center" border="0"> <tr><td width="310">Telephone:</td><td> <input type="text" name="telephone" maxlength="60"> </td></tr> <tr><td>Office:</td><td> <input type="text" name="office" maxlength="60"> </td></tr> <tr><td>Mobile:</td><td> <input type="text" name="mobile" maxlength="60"> </td></tr> <tr><td>Present Position:</td><td> <input type="text" name="presentposition" maxlength="60"> </td></tr> <tr><td>Email:</td><td> <input type="text" name="email" maxlength="60"> </td></tr> </table><br> <table align="center" border="4"> <td width="450"><b>As a graduate of Aklan College/Aklan Catholic College, please specify facts:</b></td> </table> <table align="center" border="0"> <tr><td width="310">Elementary (Year graduated):</td><td> <input type="text" name="elemntary" maxlength="60"> </td></tr> <tr><td>High School (Year Graduated):</td><td> <input type="text" name="highschool" maxlength="60"> </td></tr> <tr><td>College (Department and Year graduated):</td><td> <input type="text" name="college" maxlength="60"> </td></tr> </table><br> <table align="center" border="4"> <td width="450"><b>Educational Growth</td></b> </table> <table align="center" border="0"> <tr><td width="310">Educational Growth (Degrees and Year graduated):</td><td> <input type="text" name="educationalgrowth" maxlength="60"> </td></tr> <tr><td>School where obtained:</td><td> <input type="text" name="schoolobtained" maxlength="60"> </td></tr> <tr><td>Year school where obtained:</td><td> <input type="text" name="year" maxlength="60"> </td></tr> </table><br> <table align="center" border="0"> <tr><td width="310">Name of Spouse (if married):</td><td> <input type="text" name="nameofspouse" maxlength="60"> </td></tr> <tr><td>Date of Marriage:</td><td> <input type="text" name="dateofmarriage" maxlength="60"> </td></tr> <tr><td>Number of Children:</td><td> <input type="text" name="numberofchildren" maxlength="60"> </td></tr> <tr><td>Is your spouse an AC/ACC graduate:</td><td> <select name="graduate"> <option value=0>Select</option> <option value=Yes>Yes</option> <option value=No>No</option> </select></td></tr> <tr><td>Department and Year:</td><td> <input type="text" name="department" maxlength="60"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> <div align="center"> <?php echo "Already a member? <a href=login.php> Click here to login </a>"; ?> </div> </form> <?php } ?> //login.php <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("store") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = ($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: members.php"); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> <div> Not a member yet? <?php echo "<a href=register.php>Click here to register.</a>"; ?> </div> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/148730-how-to-update-records/ Share on other sites More sharing options...
waynew Posted March 10, 2009 Share Posted March 10, 2009 Oh man, please, use the code tags! Link to comment https://forums.phpfreaks.com/topic/148730-how-to-update-records/#findComment-780977 Share on other sites More sharing options...
revraz Posted March 10, 2009 Share Posted March 10, 2009 Use a $_GET clause, and use a name in your URL like ?update=true. Then in your code you can check that, have their ROW ID stored in a session, retrieve their info and display it on a form, let them update it, hit submit, then just use a SQL UPDATE statement to write it back. Link to comment https://forums.phpfreaks.com/topic/148730-how-to-update-records/#findComment-781124 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.