Jump to content

[SOLVED] update query


garydt

Recommended Posts

I'm trying to update a field of the record of the logged-in user and i'm getting this error-

garydtUnknown column 'garydt' in 'where clause'                             

garydt is the logged-in user ($user)

The code is-

 

<?php

session_start();

?>

<?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;

}

}

 

$user = $_SESSION['MM_Username'];

echo $user;

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

  $updateSQL = sprintf("UPDATE userinformation SET why=%s WHERE usernm=$user",

                      GetSQLValueString($_POST['textfield'], "text"),

                      GetSQLValueString($_POST['hiddenField'], "text"));

 

  mysql_select_db($database_elvisdb, $elvisdb);

  $Result1 = mysql_query($updateSQL, $elvisdb) or die(mysql_error());

 

  $updateGoTo = "usernmm.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

    $updateGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $updateGoTo));

}

?><!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>

    <input name="hiddenField" type="hidden" value="$user" />

  </p>

  <p>

    <label>

    <input type="submit" name="Submit" value="Submit" />

    </label>

</p>

  <input type="hidden" name="MM_update" value="form1">

</form>

</body>

</html>

 

Where am i going wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/40247-solved-update-query/
Share on other sites

I did  $updateSQL = sprintf("UPDATE userinformation SET why=%s WHERE usernm='$user'",  and the field did update but now i have this error-

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\epeople\hi3.php:36) in C:\Program Files\xampp\htdocs\epeople\hi3.php on line 56

 

Link to comment
https://forums.phpfreaks.com/topic/40247-solved-update-query/#findComment-194765
Share on other sites

By the way, what does the "%s" mean?

 

You can think of it as a placeholder that informs sprintf how it should interpret/convert the corresponding value. Read sprintf's manual page for more info.

 

I did  $updateSQL = sprintf("UPDATE userinformation SET why=%s WHERE usernm='$user'",  and the field did update but now i have this error-

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\epeople\hi3.php:36) in C:\Program Files\xampp\htdocs\epeople\hi3.php on line 56

 

 

Remove the "echo $user;" on line 36. Header Errors

Link to comment
https://forums.phpfreaks.com/topic/40247-solved-update-query/#findComment-194774
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.