Jump to content

update database


garydt

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.