Website membership checkboxes and image upload

By hiroko - August 17, 2012

Hi,

I have some problems making single checkbox and multi value checkbox to update in my profile.php.
I tried fallowing the forum here

http://www.interactivetools.com/iforum/Products_C2/CMS_Builder%3A_Plugins_%26_Add-ons_F40/gforum.cgi?post=85879;search_string=membership%20checkbox;t=search_engine#85879
but I'm still not getting it to work.
I have also tried what was mentioned about this part
// prepopulate form with current user values foreach ($CURRENT_USER as $name => $value) { if (array_key_exists($name, $_REQUEST)) { continue; } $_REQUEST[$name] = $value; }

but it keeps on giving me the error checking message.
I can update other parts such as the texts and radio buttons except for the 'firstname' and 'lastname' text box.
Could you tell me what I am doing wrong?

I also need the member to upload several images, not just one. And would like an error message to show up when the image file is larger than 1MB or the file extension is other than .jpg, .gif, .png.
Is this possible?
I made an upload field for 'main_image' and 'sub1_image', 'sub2_image, 'sub3_image'.
'main_image' can only upload one image and it is required, but the sub images are option.
I fallowed the steps here
http://www.interactivetools.com/iforum/Products_C2/CMS_Builder%3A_Plugins_%26_Add-ons_F40/gforum.cgi?post=83228;search_string=website%20Membership%20upload;t=search_engine#83228
I just changed the field name and was able to upload 1 image but I cannot fallow the next step referring to multiple images.
In addition, after updating with another image, the old image still exists in my uploads folder. I would like to deleted them too.

Sorry for many questions at once. Please help me. Thank you!

Hiroko
Attachments:

profile_008.php 22K

Re: [hiroko] Website membership checkboxes and image upload

By Jason - August 17, 2012

Hi Hiroko,

It looks like you're pretty close.

For your first issue, it looks like you need to turn your array back into a string to put it back in the database.

try this change:



if (is_array(@$_REQUEST['degital_or_film'])) {
$degital_or_film = "\t". join("\t", $_REQUEST['degital_or_film']). "\t";
}
else {
$degital_or_film = "\t\t";
}

//
$query = "UPDATE `{$TABLE_PREFIX}" . @$GLOBALS['WSM_ACCOUNTS_TABLE'] . "` SET
firstname = '".mysql_escape( $_REQUEST['firstname'] )."',
lastname = '".mysql_escape( $_REQUEST['lastname'] )."',
email = '".mysql_escape( $_REQUEST['email'] )."',
username = '".mysql_escape( $_REQUEST['email'] )."',
password = '".mysql_escape( $passwordHash )."',
state = '".mysql_escape( $_REQUEST['state'] )."',
address = '".mysql_escape( $_REQUEST['address'] )."',
zip = '".mysql_escape( $_REQUEST['zip'] )."',
phone = '".mysql_escape( $_REQUEST['phone'] )."',
website_title = '".mysql_escape( $_REQUEST['website_title'] )."',
url = '".mysql_escape( $_REQUEST['url'] )."',
status = '".mysql_escape( $_REQUEST['status'] )."',
brand = '".mysql_escape( $_REQUEST['brand'] )."',
degital_or_film = '".mysql_escape( $degital_or_film )."',
category = '".mysql_escape( $_REQUEST['category'] )."',
bio = '".mysql_escape( $_REQUEST['bio'] )."',
premium = '".mysql_escape( $_REQUEST['premium'] )."',
mail_magazine = '".intval( @$_REQUEST['mail_magazine'] )."',
news_letter = '".intval( @$_REQUEST['news_letter'] )."',


updatedByUserNum = '".mysql_escape( $CURRENT_USER['num'] )."',
updatedDate = NOW()
WHERE num = '".mysql_escape( $CURRENT_USER['num'] )."'";
mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n");


For uploads, to make things easier, take a look at the following attachments. uploadForm2_edit.php is an example form showing you how to attach uploads to a preexisting record. It uses uploadForm2_iframe.php, which is the file where the actual upload takes place.

Give this a try and let me know if you run into any problem.s

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Website membership checkboxes and image upload

By hiroko - October 24, 2012

Thank you for your help and now I am finally able to work with this part again.

I tried the changes with the multi checkbox, but now I am getting error.

Notice: Undefined variable: camera in /public_html/user/profile.php on line 97 Notice: Undefined variable: genres in /public_html/user/profile.php on line 98 MySQL Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'updatedByUserNum = '54', updatedDate = NOW() ' at line 32

Did I write something wrong?

I am attaching the profile.php
Attachments:

profile_009.php 24K

Re: [Jason] Website membership checkboxes and image upload

By hiroko - October 24, 2012

Sorry I didn't write about the upload in the reply above.

I put the iframe in my profile.php, but I am getting error in the iframe.
Tablename 'Notice: Undefined variable: tableName in /user/profile.php on line 432' isn't in list of allowed tablenames!

I have
// SECURITY WARNING: BE SURE TO ADD SECURITY CHECKS BELOW TO ENSURE USERS CAN'T
// ADD OR MODIFY UPLOADS FROM ANY RECORDS THEY ARE NOT SUPPOSE TO.
$allowedTables = array('accounts');
$allowedFields = array('main_image');

in the uploadForm2_iframe.php
I guess this is the only part I need to change in this file?

Do I need to change something else like the access list?

Re: [hiroko] Website membership checkboxes and image upload

By Jason - October 24, 2012

Hi,

I've looked over your code and have noticed a couple of things. First $camera and $genres are not defined variables in your page. In your code, it looks like you assign the values of $_REQUEST['camera'] AND $_REQUEST['genres'] to the variable $degital_or_film. This variable then isn't used elsewhere. If camera and genre are different fields in your section, you will want to create 2 different tab separated strings to insert into the database.

For your upload iframe, you need to define $tableName and $preSaveTempId as variables like this:

if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }

$tableName = "accounts";
$recordNum = $CURRENT_USER['num'];
$preSaveTempId = null;


Hope this helps. Please let me know if you have any other questions.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Website membership checkboxes and image upload

By hiroko - October 24, 2012

Thank you Jason,
That was very stupid of me...
I changed the $degital_or_film to the correct field names.
Now I got rid of the first 2 errors, but it is showing
MySQL Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'updatedByUserNum = '54', updatedDate = NOW() ' at line 32

For the uplaod iframe, I get:
Invalid recordNum
in the frame.
I don't have any upload image yet. Could that be the problem?

hiroko

Re: [hiroko] Website membership checkboxes and image upload

By Jason - October 24, 2012

Hi Hiroko,

No problem. Your SQL error is because you're missing a comma after main_image_title

main_image_title = '".mysql_escape( $_REQUEST['main_image_title'] )."',

Your upload "error" is because of an extra security check. It will stop you if the CURRENT_USER isn't the person who created the original record. This doesn't really work when working with user accounts.

If you open up the PHP file, find this line:
if (!$record || $record['createdByUserNum'] != $CURRENT_USER['num']) { die("Invalid recordNum"); }

and replace it with this:

if (!$record ){
die("Invalid recordNum");
}
elseif ($tableName == @$GLOBALS['WSM_ACCOUNTS_TABLE'] && $CURRENT_USER != $record['num']) { //editing user table
die("Invalid recordNum");
}
elseif ($record['createdByUserNum'] != $CURRENT_USER['num']) {
die("Invalid recordNum");
}


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Website membership checkboxes and image upload

By hiroko - October 24, 2012

Thank you Jason,
I can move to my profile page now.
But I can't update my checkboxes when it is selected more than one. I am only able to update one of them.

I also have some textfields that are not updating, such as middle_name, favorite_artist, etc. Some are ok.

For upload, I'm still getting the "Invalid recordNum"
Is the replacement of the code at the iframe PHP?
I will attach the file.

I noticed that my birthday date is not working.
On my profile page, it only shows October for month and it will not update.
How can I make this work?
My field is set up as
Field type: date
field name: birthday
default value: none
year range: 1920 to 2010
no specific time

Re: [Jason] Website membership checkboxes and image upload

By hiroko - October 25, 2012

Hi,
I've found what's wrong with my text fields.
Very simple mistake...
I didn't change the field name of the <input name= > when I copied them.
Sorry to take your time.
I'm trying to figure out if I have any other mistake like that in the other parts that are not working. Please let me know if you find any.
Thank you.

hiroko