PHP and MySQL question (ENCODE and DECODE)
Posted: Mon Oct 10, 2005 10:08 pm
Hey All,
What I'm trying to do, in a nutshell, us update a table row with some new info that has to be encoded, then retrieve the correct info.
I'm having the dickens of a time trying to figure out why I'm having so much trouble with DECODE(ing) info kept in a mysql column. I use two different keys to access the information. Key1 seems to return the correct data (decoded properly) while info using Key2 returns garbled info.
I should probably preface this with the confession of being a PHP and MySQL noob.
Maybe my code will make more sense...
a simplified sample of the original form (apply.php):
when the form is submitted it goes to add_proc.php:
On it's successful completion it goes back to the original form and fills out the text fields, but the data is garbled. Does anyone see where I messed up or could offer some troubleshooting tips or solutions? I'm about out of my mind on this... 
Thanks!
HG
What I'm trying to do, in a nutshell, us update a table row with some new info that has to be encoded, then retrieve the correct info.
I'm having the dickens of a time trying to figure out why I'm having so much trouble with DECODE(ing) info kept in a mysql column. I use two different keys to access the information. Key1 seems to return the correct data (decoded properly) while info using Key2 returns garbled info.
Maybe my code will make more sense...
a simplified sample of the original form (apply.php):
Code: Select all
$key = 'key';
$intMemberID = $_GET['intMemberID'];
$selMember = "SELECT intMemberID,
DECODE(strNameFirst, '$key'),
DECODE(strNameLast, '$key'),
DECODE(strNameMI, '$key'),
DECODE(strAddStreet1, '$key'),
DECODE(strAddStreet2, '$key'),
DECODE(strModelPhone, '$key')
strAddCity,
strAddState,
strAddZIP,
FROM Member WHERE intMemberID = '$intMemberID'";
$qryMember = mysql_query($selMember);
$resMember = mysql_fetch_array($qryMember);
<form action="add_proc.php" method="post">
<input type="hidden" name="intMemberID" value="<?=$intMemberID; ?>">
First Name : <input type="text" name="strNameFirst" value="<?=$resMember['strNameFirst']; ?>">
Last Name : <input type="text" name="strNameLast" value="<?=$resMember['strNameLast']; ?>">
Middle Name : <input type="text" name="strNameMI" value="<?=$resMember['strNameMI']; ?>">
Street Address 1 : <input type="text" name="strAddStreet1" value="<?=$resMember['strAddStreet1']; ?>">
Street Address 2 : <input type="text" name="strAddStreet2" value="<?=$resMember['strAddStreet2']; ?>">
City : <input type="text" name="strAddCity" value="<?=$resMember['strAddCity']; ?>">
State : <input type="text" name="strAddState" value="<?=$resMember['strAddState']; ?>">
ZIP : <input type="text" name="strAddZIP" value="<?=$resMember['strAddZIP']; ?>">
<input type="submit" value="save">
</form>Code: Select all
$key = 'key';
$updateApplicant = "UPDATE Member SET
strNameFirst = 'ENCODE ($_POST[strNameFirst], $key)',
strNameLast = 'ENCODE ($_POST[strNameLast], $key)',
strNameMI = 'ENCODE ($_POST[strNameMI], $key)',
strAddStreet1 = 'ENCODE ($_POST[strAddStreet1], $key)',
strAddStreet2 = 'ENCODE ($_POST[strAddStreet2], $key)',
strAddCity = '$_POST[strAddCity]',
strAddState = '$_POST[strAddState]',
strAddZIP = '$_POST[strAddZIP]'
WHERE intMemberID = '$_POST[intMemberID]'";
if ( mysql_query($updateApplicant) ) {
header ("Location: apply.php?intMemberID=".$_POST[intMemberID]);
exit;
} else {
echo 'error : '.mysql_error();
}Thanks!
HG