![]() |
How do I keep my form updates from overwriting data?
I have a form my customers fill out that I'm having some difficutly with. Whenever they re-visit to update their information they have to fill in every field all over again or the data is overwritten to the new (null) values.
I'm fairly new to MySQL and don't know how to keep this from happening. Any ideas/suggestions? Thank you, FaShUnPhOtOg |
Two ways to do it:
1. Check the database to see if there is data there. If there is, and the form field pertaining to that data is empty, simply readd the existing data. 2. Better yet, check each form variable and ONLY update the form fields that have values. I am not suggesting doing 3 or 4 update queries. I am suggesting that you write your query so that it is dynamic. For example: Code:
if ($formnamefield) |
Quote:
thank you for your quick response. Are you available for PM for some one-on-one? I really need to get this thing working. Mike |
Post some more info (code snippets, table layout, etc) and i will try to help.
|
It's kinda long but here's the code for the form I'm using (a snippet from the included .php file is in the reply below this:
HTML Code:
<form action="vbportfolio.php" method="post" enctype="multipart/form-data"> Thank you for whatever help you can provide. Mike And here's the code snippet from the included .php file: [sql] // ################################################## ########################## // ############################### EDIT PORTFOLIO ################################ // ################################################## ########################## if ($_REQUEST['do'] == 'editportfolio') { if (can_administer() && $_REQUEST[id]) { $id = $_REQUEST[id]; } else { $id = $bbuserinfo['userid']; } $user = fetch_userinfo($id); if (!$bbuserinfo['userid']) { print_no_permission(); } if ($permissions['genericpermissions'] & CANVBPORTFOLIO) { $result_data = $DB_site->query(" SELECT firstname,lastname,text,gender,age,email,bmonth,bd ay,byear,talent,address,address2,city,state,postal ,country,phone,phone2,phone3,phone4,website,inssta tus,aftra,sag,natas,experience,breast,cup,waist,he ight,weight,hips,dress,shoes,chest,inseam,ethnic,s tone,hcolor,ecolor,hstyle,piercings,glasses,braces ,handicap,hearing,marks,beard,moustache,tattoos,ru nway,fashion,printmedia,casual,commercial,editoria l,tradeshow,spokesmodel,sports,swimwear,artmodel,f ineartphoto,fineart,photomodel,perfart,internet,bo dyart,lingerie,glamour,acting,singing,dance,voiceo ver,stage,film,television,language,language2,flyin g,swimming,horse,skydiving,scuba,climbing,noagent, likeagent,agencyname,address3,address4,agentname,a gencycity,agencystate,agencypostal,agencycountry,p hone5,phone6,maillist,newsletter FROM " . TABLE_PREFIX . "vbportfolio_users WHERE userid = $id "); $count = 0; $data = $DB_site->fetch_Array($result_data); $result_image = $DB_site->query(" SELECT vbportfolioid,name FROM " . TABLE_PREFIX . "vbportfolio_images WHERE userid = $id "); while ($image = $DB_site->fetch_Array($result_image)) { $count++; eval('$editimagebits .= "' . fetch_template('vbportfolio_editimagebits') . '";'); } $navbits = construct_navbits(array('' => 'vBPortfolio')); eval('$navbar = "' . fetch_template('navbar') . '";'); eval('print_output("' . fetch_template('vbportfolio_editportfolio') . '");'); } else { print_no_permission(); } } if ($_REQUEST['do'] == 'edit') { globalize($_POST, array('firstname','lastname','text','gender','age' ,'email','bmonth','bday','byear','talent','address ','address2','city','state','postal','country','ph one','phone2','phone3','phone4','website','insstat us','aftra','sag','natas','experience','breast','c up','waist','height','weight','hips','dress','shoe s','chest','inseam','ethnic','stone','hcolor','eco lor','hstyle','piercings','glasses','braces','hand icap','hearing','marks','beard','moustache','tatto os','runway','fashion','printmedia','casual','comm ercial','editorial','tradeshow','spokesmodel','spo rts','swimwear','artmodel','fineartphoto','fineart ','photomodel','perfart','internet','bodyart','lin gerie','glamour','acting','singing','dance','voice over','stage','film','television','language','lang uage2','flying','swimming','horse','skydiving','sc uba','climbing','noagent','likeagent','agencyname' ,'address3','address4','agentname','agencycity','a gencystate','agencypostal','agencycountry','phone5 ','phone6','maillist','newsletter')); if (can_administer() && $_REQUEST[id]) { $id = $_POST[id]; } else { $id = $bbuserinfo['userid']; } if (!$bbuserinfo['userid']) { print_no_permission(); } /* if ($permissions['genericpermissions'] & CANVBPORTFOLIO) { if (empty($firstname) OR empty($lastname) OR empty($id)) { eval (print_standard_error('error_requiredfields')); } */ if ($permissions['genericpermissions'] & CANVBPORTFOLIO) { if (empty($id)) { eval (print_standard_error('error_requiredfields')); } if (!empty($_FILES['src']['tmp_name'])) { $name = $_FILES['src']['name']; $data = addslashes(fread(fopen($_FILES['src']['tmp_name'], "r"), filesize($_FILES['src']['tmp_name']))); $type = $_FILES['src']['type']; $DB_site->query(" INSERT INTO " . TABLE_PREFIX . "vbportfolio_images (userid, name, data, type) VALUES ($id, '$name', '$data', '$type') "); } $result_user = $DB_site->query(" SELECT * FROM " . TABLE_PREFIX . "vbportfolio_users WHERE userid = $id "); $user = $DB_site->fetch_Array($result_user); /*my hack if ($firstname) { $nameupdate = "name = '" . addslashes($firstname) . "'," } else { $nameupdate = ''; } */ if (empty($user)) { $DB_site->query(" INSERT INTO " . TABLE_PREFIX . "vbportfolio_users (userid, firstname, lastname, text, gender, age, email, bmonth, bday, byear, talent, address, address2, city, state, postal, country, phone, phone2, phone3, phone4, website, insstatus, aftra, sag, natas, experience, breast, cup, waist, height, weight, hips, dress, shoes, chest, inseam, ethnic, stone, hcolor, ecolor, hstyle, piercings, glasses, braces, handicap, hearing, marks, beard, moustache, tattoos, runway, fashion, printmedia, casual, commercial, editorial, tradeshow, spokesmodel, sports, swimwear, artmodel, fineartphoto, fineart, photomodel, perfart, internet, bodyart, lingerie, glamour, acting, singing, dance, voiceover, stage, film, television, language, language2, flying, swimming, horse, skydiving, scuba, climbing, noagent, likeagent, agencyname, address3, address4, agentname, agencycity, agencystate, agencypostal, agencycountry, phone5, phone6, maillist, newsletter, lastactivity) VALUES ($id, '" . addslashes($firstname) . "', '" . addslashes($lastname) . "', '" . addslashes($text) . "', '" . addslashes($gender) . "', '" . addslashes($age) . "', '" . addslashes($email) . "', '" . addslashes($bmonth) . "', '" . addslashes($bday) . "', '" . addslashes($byear) . "', '" . addslashes($talent) . "', '" . addslashes($address) . "', '" . addslashes($address2) . "', '" . addslashes($city) . "', '" . addslashes($state) . "', '" . addslashes($postal) . "', '" . addslashes($country) . "', '" . addslashes($phone) . "', '" . addslashes($phone2) . "', '" . addslashes($phone3) . "', '" . addslashes($phone4) . "', '" . addslashes($website) . "', '" . addslashes($insstatus) . "', '" . addslashes($aftra) . "', '" . addslashes($sag) . "', '" . addslashes($natas) . "', '" . addslashes($experience) . "', '" . addslashes($breast) . "', '" . addslashes($cup) . "','" . addslashes($waist) . "', '" . addslashes($height) . "', '" . addslashes($weight) . "', '" . addslashes($hips) . "', '" . addslashes($dress) . "', '" . addslashes($shoes) . "', '" . addslashes($chest) . "', '" . addslashes($inseam) . "', '" . addslashes($ethnic) . "', '" . addslashes($stone) . "', '" . addslashes($hcolor) . "', '" . addslashes($ecolor) . "', '" . addslashes($hstyle) . "', '" . addslashes($piercings) . "', '" . addslashes($glasses) . "', '" . addslashes($braces) . "', '" . addslashes($handicap) . "', '" . addslashes($hearing) . "', '" . addslashes($marks) . "', '" . addslashes($beard) . "', '" . addslashes($moustache) . "', '" . addslashes($tattoos) . "', '" . addslashes($runway) . "', '" . addslashes($fashion) . "', '" . addslashes($printmedia) . "', '" . addslashes($casual) . "', '" . addslashes($commercial) . "', '" . addslashes($editorial) . "', '" . addslashes($tradeshow) . "', '" . addslashes($spokesmodel) . "', '" . addslashes($sports) . "', '" . addslashes($swimwear) . "', '" . addslashes($artmodel) . "', '" . addslashes($fineartphoto) . "', '" . addslashes($fineart) . "', '" . addslashes($photomodel) . "', '" . addslashes($perfart) . "', '" . addslashes($internet) . "', '" . addslashes($bodyart) . "', '" . addslashes($lingerie) . "', '" . addslashes($glamour) . "', '" . addslashes($acting) . "', '" . addslashes($singing) . "', '" . addslashes($dance) . "', '" . addslashes($voiceover) . "', '" . addslashes($stage) . "', '" . addslashes($film) . "', '" . addslashes($television) . "', '" . addslashes($language) . "', '" . addslashes($language2) . "', '" . addslashes($flying) . "', '" . addslashes($swimming) . "', '" . addslashes($horse) . "', '" . addslashes($skydiving) . "', '" . addslashes($scuba) . "', '" . addslashes($climbing) . "', '" . addslashes($noagent) . "', '" . addslashes($likeagent) . "', '" . addslashes($agencyname) . "', '" . addslashes($address3) . "', '" . addslashes($address4) . "', '" . addslashes($agentname) . "', '" . addslashes($agencycity) . "', '" . addslashes($agencystate) . "', '" . addslashes($agencypostal) . "', '" . addslashes($agencycountry) . "', '" . addslashes($phone5) . "', '" . addslashes($phone6) . "', '" . addslashes($maillist) . "', '" . addslashes($newsletter) . "', '" . time() . "') "); } else { $DB_site->query(" UPDATE " . TABLE_PREFIX . "vbportfolio_users SET firstname = '" . addslashes($firstname) . "', lastname = '" . addslashes($lastname) . "', text = '" . addslashes($text) . "', gender = '" . addslashes($gender) . "', age = '" . addslashes($age) . "', email = '" . addslashes($email) . "', bmonth = '" . addslashes($bmonth) . "', bday = '" . addslashes($bday) . "', byear = '" . addslashes($byear) . "', talent = '" . addslashes($talent) . "', address = '" . addslashes($address) . "', address2 = '" . addslashes($address2) . "', city = '" . addslashes($city) . "', state = '" . addslashes($state) . "', postal = '" . addslashes($postal) . "', country = '" . addslashes($country) . "', phone = '" . addslashes($phone) . "', phone2 = '" . addslashes($phone2) . "', phone3 = '" . addslashes($phone3) . "', phone4 = '" . addslashes($phone4) . "', website = '" . addslashes($website) . "', insstatus = '" . addslashes($insstatus) . "', aftra = '" . addslashes($aftra) . "', sag = '" . addslashes($sag) . "', natas = '" . addslashes($natas) . "', experience = '" . addslashes($experience) . "', breast = '" . addslashes($breast) . "', cup = '" . addslashes($cup) . "', waist = '" . addslashes($waist) . "', height = '" . addslashes($height) . "', weight = '" . addslashes($weight) . "', hips = '" . addslashes($hips) . "', dress = '" . addslashes($dress) . "', shoes = '" . addslashes($shoes) . "', chest = '" . addslashes($chest) . "', inseam = '" . addslashes($inseam) . "', ethnic = '" . addslashes($ethnic) . "', stone = '" . addslashes($stone) . "', hcolor = '" . addslashes($hcolor) . "', ecolor = '" . addslashes($ecolor) . "', hstyle = '" . addslashes($hstyle) . "', piercings = '" . addslashes($piercings) . "', glasses = '" . addslashes($glasses) . "', braces = '" . addslashes($braces) . "', handicap = '" . addslashes($handicap) . "', hearing = '" . addslashes($hearing) . "', marks = '" . addslashes($marks) . "', beard = '" . addslashes($beard) . "', moustache = '" . addslashes($moustache) . "', tattoos = '" . addslashes($tattoos) . "', runway = '" . addslashes($runway) . "', fashion = '" . addslashes($fashion) . "', printmedia = '" . addslashes($printmedia) . "', casual = '" . addslashes($casual) . "', commercial = '" . addslashes($commercial) . "', editorial = '" . addslashes($editorial) . "', tradeshow = '" . addslashes($tradeshow) . "', spokesmodel = '" . addslashes($spokesmodel) . "', sports = '" . addslashes($sports) . "', swimwear = '" . addslashes($swimwear) . "', artmodel = '" . addslashes($artmodel) . "', fineartphoto = '" . addslashes($fineartphoto) . "', fineart = '" . addslashes($fineart) . "', photomodel = '" . addslashes($photomodel) . "', perfart = '" . addslashes($perfart) . "', internet = '" . addslashes($internet) . "', bodyart = '" . addslashes($bodyart) . "', lingerie = '" . addslashes($lingerie) . "', glamour = '" . addslashes($glamour) . "', acting = '" . addslashes($acting) . "', singing = '" . addslashes($singing) . "', dance = '" . addslashes($dance) . "', voiceover = '" . addslashes($voiceover) . "', stage = '" . addslashes($stage) . "', film = '" . addslashes($film) . "', television = '" . addslashes($television) . "', language = '" . addslashes($language) . "', language2 = '" . addslashes($language2) . "', flying = '" . addslashes($flying) . "', swimming = '" . addslashes($swimming) . "', horse = '" . addslashes($horse) . "', skydiving = '" . addslashes($skydiving) . "', scuba = '" . addslashes($scuba) . "', climbing = '" . addslashes($climbing) . "', noagent = '" . addslashes($noagent) . "', likeagent = '" . addslashes($likeagent) . "', agencyname = '" . addslashes($agencyname) . "', address3 = '" . addslashes($address3) . "', address4 = '" . addslashes($address4) . "', agentname = '" . addslashes($agentname) . "', agencycity = '" . addslashes($agencycity) . "', agencystate = '" . addslashes($agencystate) . "', agencypostal = '" . addslashes($agencypostal) . "', agencycountry = '" . addslashes($agencycountry) . "', phone5 = '" . addslashes($phone5) . "', phone6 = '" . addslashes($phone6) . "', maillist = '" . addslashes($maillist) . "', newsletter = '" . addslashes($newsletter) . "', lastactivity = '" . time() . "' WHERE userid = $id "); } $result_image = $DB_site->query(" SELECT vbportfolioid,name FROM " . TABLE_PREFIX . "vbportfolio_images WHERE userid = $id "); if (!empty($result_image)) { while ($image = $DB_site->fetch_Array($result_image)) { if ($_POST['delete'.$image['vbportfolioid']]) { $DB_site->query(" DELETE FROM " . TABLE_PREFIX . "vbportfolio_images WHERE vbportfolioid = $image[vbportfolioid] LIMIT 1 "); } } } Header("Location: $vboptions[bburl]/vbportfolio.php?do=editportfolio&id=$id"); } else { print_no_permission(); } } if ($_REQUEST['do'] == 'delportfolio') { globalize($_REQUEST, array('id' => INT)); if (!$bbuserinfo['userid'] OR $bbuserinfo['usergroupid']!=6) { print_no_permission(); } if (empty($id)) { eval (print_standard_error('error_requiredfields')); } $DB_site->query(" DELETE FROM " . TABLE_PREFIX . "vbportfolio_users WHERE userid = $id "); $DB_site->query(" DELETE FROM " . TABLE_PREFIX . "vbportfolio_images WHERE userid = $id "); $DB_site->query(" DELETE FROM " . TABLE_PREFIX . "vbportfolio_comments WHERE vbportfolioid = $id "); Header("Location: $vboptions[bburl]/vbportfolio.php?do=list"); } [/sql] |
Please use bb-codes like [php] [html] [sql] & [code]
|
Sorry, I'm new to this vB thing and didn't realize I needed to use codes. Did I edit it correctly? There should be section with
HTML Code:
... M |
This is gonna be very easy.
In your template you have already this line: HTML Code:
<input type="text" class="bginput" name="firstname" size="20" maxlength="30" /> HTML Code:
<input type="text" class="bginput" name="firstname" size="20" maxlength="30" value="$data[firstname]"/> Some more, the following: PHP Code:
PHP Code:
PHP Code:
|
Would this work for the radio button inputs and menu/list input boxes as well?
M Ok, I tried that and am getting these messages: Code:
Database error in vBulletin 3.0.7: Code:
Parse error: parse error, unexpected T_STRING in /home/chicagot/public_html/forums/vbportfolio.php on line 177 Ok, I figured out what I did wrong - first, I modified the original code which already had what I needed built in! Talk about creating my own problem! Next, I put the code you suggested in the wrong place! Once I realized that I was able to take care of the problems and get it working. The only problems I'm having now is that I can no longer use checkboxes and radio buttons 'cause I can't figure out how to assign the variable value and the other is the pictures are expanding to the right. I don't know how to layer them in rows. Any suggestions? Mike PS - Give me the url you'd like me to use on my credits page and I'll be sure to give you the credit you deserve! |
All times are GMT. The time now is 10:57 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|