database - On update, PHP is making all fields empty -
i using following code. whenever form used update, php empty fields in db. know happen if field_names don't match, have triple checked them, work. first time getting error. not sure do.
code:
//getting unique id $sql = "select `person_id` `accounts` `username` = '$username'"; $query = mysql_query($sql) or die ("error: ".mysql_error()); while ($row = mysql_fetch_array($query)){ $pid = $row['person_id']; } mysql_free_result($query); $newname = mysql_real_escape_string($_post['full_name']); $newgender = mysql_real_escape_string($_post['patient_gender']); $newmonth = mysql_real_escape_string($_post['month']); $newday = mysql_real_escape_string($_post['day']); $newyear = mysql_real_escape_string($_post['year']); $newacctss = mysql_real_escape_string($_post['acct_ss']); $newaddress = mysql_real_escape_string($_post['address']); $newaddress2 = mysql_real_escape_string($_post['address2']); $newcity = mysql_real_escape_string($_post['city']); $newstate = mysql_real_escape_string($_post['state']); $newzipcode = mysql_real_escape_string($_post['zip_code']); $newhomephone = mysql_real_escape_string($_post['home_phone']); $newcellphone = mysql_real_escape_string($_post['cell_phone']); $neworkphone = mysql_real_escape_string($_post['work_phone']); $newsure = mysql_real_escape_string($_post['sure']); $newfav = mysql_real_escape_string($_post['favorite']); $newcars = mysql_real_escape_string($_post['cars']); $newdrinks = mysql_real_escape_string($_post['drinks']); $newmoi = mysql_real_escape_string($_post['about_moi']); //update name $sql = "update accounts set `full_name` = '$newname' username = '$username'"; $query1 = mysql_query($sql) or die ("error: ".mysql_error()); //everything else being udpated here $sql2 = "update profile set `patient_gender` = '$newgender', `month` = '$newmonth', `day` = '$newday', `year` = '$newyear', `acct_ss` = '$newacctssn', `address` = '$newaddress', `address2` = '$newaddress2', `city` = '$newcity', `state` = '$newstate', `zip_code` = '$newzipcode', `home_phone` = '$newhomephone', `cell_phone` = '$cellphone', `work_phone` = '$neworkphone', `sure` = '$newsure', `favorite` = '$newfav', `cars` = '$newcars', `drinks` = '$newdrinks', `about_moi` = '$newmoi' person_id = '$pid'"; $query2 = mysql_query($sql2) or die ("error: ".mysql_error());
array keys case sensitive in php. you're querying database person_id
, fetching person_id
. want check you're getting result set checking $pid
empty after fetch call , bail out if so.
as well, assuming query fetches single row, not need while()
construct.
beyond that, check $newname
being created properly. if form isn't submitting properly, or name field called else, you'll inserting blank database because variable never filled-in properly. check what's being submitted doing var_dump($_post)
.
Comments
Post a Comment