garydt Posted February 25, 2007 Share Posted February 25, 2007 I have a registration page that lets the user register and log on. On the next page i have another form where the user enters more information. I want to store this information in the same row as where their username is stored but i'm at a lost as to how to do it. Do I have some hidden fields on the registration page so that I can update them on the second page? How do i search the database for the username so that it will update the fields of that particular row? Any help would be very much appreciated. Link to comment https://forums.phpfreaks.com/topic/40027-update-database/ Share on other sites More sharing options...
Barand Posted February 25, 2007 Share Posted February 25, 2007 On successful login, store the username in a session variable. Use this to identify the row to be updated <?php session_start(); $user = $_SESSION['username']; $sql = "UPDATE mytable SET colA = '$dataA', colB = '$dataB' WHERE id = '$user' "; mysql_query ($sql); ?> Link to comment https://forums.phpfreaks.com/topic/40027-update-database/#findComment-193581 Share on other sites More sharing options...
rameshfaj Posted February 25, 2007 Share Posted February 25, 2007 The above idea is also great.But lets have a new idea. Let in pageA u get the values like username and pwd.Set the action field of the pageA to the page where other informations are to be entered.(let pageB). In pageB get the values entered in the pageA via get or post method. Ex: $username=$_GET['username'];//username on rightside is the name of the field in pageA where name is //entered Similarly for password. Now in pageB make a form that expects the other details like address,security questions etc Store them in variables.The action of the pageB be set to itself. Then follow: $mode=$_GET['mode']; f($mode=="submit") { //store user entered values in variables and then write the query. } Link to comment https://forums.phpfreaks.com/topic/40027-update-database/#findComment-193594 Share on other sites More sharing options...
garydt Posted February 25, 2007 Author Share Posted February 25, 2007 Thank you both. I will try the first suggestion. Where you got colA = '$dataA'; if i have a formfield called 'address' and i want to put it into the data field called 'adres' would i write adres = 'address'; ? Link to comment https://forums.phpfreaks.com/topic/40027-update-database/#findComment-193613 Share on other sites More sharing options...
Barand Posted February 25, 2007 Share Posted February 25, 2007 The address to be inserted will be stored in a variable, say, $address, so it would be addres = '$address' Link to comment https://forums.phpfreaks.com/topic/40027-update-database/#findComment-193620 Share on other sites More sharing options...
garydt Posted February 25, 2007 Author Share Posted February 25, 2007 I tried it but it entered the new data as part of a new record, it didn't enter the data into the same record as the username. Here's the code- <?php require_once('Connections/elvisdb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO userinformation (why) VALUES (%s)", GetSQLValueString($_POST['textfield'], "text")); mysql_select_db($database_elvisdb, $elvisdb); $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error()); $insertGoTo = "usernmm.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } session_start(); $user = $_SESSION['MM_Username']; $sql = "UPDATE userinformation SET colWHY = '$textfieldWHY', WHERE usernm = '$user' "; mysql_query ($sql); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <label> <input type="text" name="textfield" /> </label> <p> <label> <input type="submit" name="Submit" value="Submit" /> </label> </p> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/40027-update-database/#findComment-193644 Share on other sites More sharing options...
garydt Posted February 25, 2007 Author Share Posted February 25, 2007 I'm still having problems getting to work. Can someone give me some more help please? Link to comment https://forums.phpfreaks.com/topic/40027-update-database/#findComment-193827 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.