edavo
asked on
Combine form values to populate a field in MySQL
I want to combine several posted fields and make it the value for a single field. Below is what I have tested with no luck.
<tr>
<td style="padding:10px;border:1px solid"><label>* Gender</label></td>
<td style="padding:10px;border:1px solid"><input type="text" name="gender" value="<?php echo @$user['gender']?>"></td>
</tr>
<tr>
<td style="padding:10px;border:1px solid"><label>* Year of Birth</label></td>
<td style="padding:10px;border:1px solid"><input type="text" name="dob" value="<?php echo @$user['dob']?>"></td>
</tr>
<tr>
<td style="padding:10px;border:1px solid"><label>* Country</label></td>
<td style="padding:10px;border:1px solid"><input type="text" name="country" value="<?php echo @$user['country']?>"></td>
</tr>
<tr>
<td style="padding:10px;border:1px solid"><label>* Postal Code</label></td>
<td style="padding:10px;border:1px solid"><input type="text" name="zip" value="<?php echo @$user['zip']?>"></td>
</tr>
<? $mpxid = @$user['dob'].@$user['country'].@$user['zip']; ?>
<input type="hidden" name="combine" value="<?php echo $mpxid; ?>">
+1 for Dave's comment about error_reporting() and the short-open tag.
See also: http://php.net/manual/en/ini.core.php#ini.short-open-tag
HEREDOC notation is useful for templates like this.
Before you spend too long on this, make sure you have the variable values you expect. You can use PHP var_dump($user) to print out the $user array.
The timeline of the request and response may be in play here, too. When does $user get populated with its data?
PHP also allows for short open tag <? which is discouraged since it is only available if enabled...The safe way is to always use the explicit tag, and always avoid the close-php tag and other anti-practices, wherever possible.
See also: http://php.net/manual/en/ini.core.php#ini.short-open-tag
HEREDOC notation is useful for templates like this.
Before you spend too long on this, make sure you have the variable values you expect. You can use PHP var_dump($user) to print out the $user array.
The timeline of the request and response may be in play here, too. When does $user get populated with its data?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Used Javascript and it worked. Pulled values from forms, did a simple "combined = a+b+c."
xmpxid = a + b + c + d;
document.getElementById('x mpxid').va lue = xmpxid;
then......
<input type="hidden" name="mpxid" id="xmpxid">
Thank You all - dM
xmpxid = a + b + c + d;
document.getElementById('x
then......
<input type="hidden" name="mpxid" id="xmpxid">
Thank You all - dM
And you are using '<?' in one place and '<?php' in another place for opening tags. I recommend that you be consistent and use '<?php' in all places.