RedLineIT
10-22-2004, 02:08 PM
Hi ,
i know this is also related to mysql but i think the problem is actually with my PHP code.
anyway here s the problem.
i have a table containing text fields etc and that contains the data stored for the member in the DB
when the submit button is hit the db should get updated but all im getting is duplicate entry for " key 2
here is the query
<?php
$currentPage = $_SERVER["PHP_SELF"];
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE members SET memid=%, password=%s, realname=%s, age=%s, location=%s, sex=%s, country=%s, starsign=%s, sexuality=%s, profession=%s, marital_status=%s, hair=%s, eyes=%s, height=%s, body_type=%s, race=%s, lookingfor=%s, seeking=%s, likes=%s, dislikes=%s, emailaddress=%s, pwdreminder=%s, my2cents=%s WHERE username='$_SESSION[MM_Username]'",
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['realname'], "text"),
GetSQLValueString($_POST['age'], "int"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['starsign'], "text"),
GetSQLValueString($_POST['sexuality'], "text"),
GetSQLValueString($_POST['profession'], "text"),
GetSQLValueString($_POST['marital_status'], "text"),
GetSQLValueString($_POST['hair'], "text"),
GetSQLValueString($_POST['eyes'], "text"),
GetSQLValueString($_POST['height'], "text"),
GetSQLValueString($_POST['body_type'], "text"),
GetSQLValueString($_POST['race'], "text"),
GetSQLValueString($_POST['lookingfor'], "text"),
GetSQLValueString($_POST['seeking'], "text"),
GetSQLValueString($_POST['likes'], "text"),
GetSQLValueString($_POST['dislikes'], "text"),
GetSQLValueString($_POST['emailaddress'], "text"),
GetSQLValueString($_POST['pwdreminder'], "text"),
GetSQLValueString($_POST['my2cents'], "text"),
GetSQLValueString($_POST['memid'], "int"));
mysql_select_db($database_OnlineFlirting, $OnlineFlirting);
$Result1 = mysql_query($updateSQL, $OnlineFlirting) or die(mysql_error());
$updateGoTo = "myaccount.php?messages=Profile Successfully Updated";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
?>
my HTML form is fine so the probelm lies in the above code
i need this solved asap as i have already passed my deadline
any help would be greatly appreciated
thanks
i know this is also related to mysql but i think the problem is actually with my PHP code.
anyway here s the problem.
i have a table containing text fields etc and that contains the data stored for the member in the DB
when the submit button is hit the db should get updated but all im getting is duplicate entry for " key 2
here is the query
<?php
$currentPage = $_SERVER["PHP_SELF"];
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE members SET memid=%, password=%s, realname=%s, age=%s, location=%s, sex=%s, country=%s, starsign=%s, sexuality=%s, profession=%s, marital_status=%s, hair=%s, eyes=%s, height=%s, body_type=%s, race=%s, lookingfor=%s, seeking=%s, likes=%s, dislikes=%s, emailaddress=%s, pwdreminder=%s, my2cents=%s WHERE username='$_SESSION[MM_Username]'",
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['realname'], "text"),
GetSQLValueString($_POST['age'], "int"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['starsign'], "text"),
GetSQLValueString($_POST['sexuality'], "text"),
GetSQLValueString($_POST['profession'], "text"),
GetSQLValueString($_POST['marital_status'], "text"),
GetSQLValueString($_POST['hair'], "text"),
GetSQLValueString($_POST['eyes'], "text"),
GetSQLValueString($_POST['height'], "text"),
GetSQLValueString($_POST['body_type'], "text"),
GetSQLValueString($_POST['race'], "text"),
GetSQLValueString($_POST['lookingfor'], "text"),
GetSQLValueString($_POST['seeking'], "text"),
GetSQLValueString($_POST['likes'], "text"),
GetSQLValueString($_POST['dislikes'], "text"),
GetSQLValueString($_POST['emailaddress'], "text"),
GetSQLValueString($_POST['pwdreminder'], "text"),
GetSQLValueString($_POST['my2cents'], "text"),
GetSQLValueString($_POST['memid'], "int"));
mysql_select_db($database_OnlineFlirting, $OnlineFlirting);
$Result1 = mysql_query($updateSQL, $OnlineFlirting) or die(mysql_error());
$updateGoTo = "myaccount.php?messages=Profile Successfully Updated";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
?>
my HTML form is fine so the probelm lies in the above code
i need this solved asap as i have already passed my deadline
any help would be greatly appreciated
thanks