So on my checkout page when I push final checkout I want to store my users address and shipping address into a database. I am wondering if this could be shorter. Currently, users have multiple options:
- Logged in where they use same or other shipping address.
- Not logged in and they want to create account with same or different shipping address.
- Not logged in where they create a guest account again with same or different address.
I know I can put my $_POST
values direct in the $createlines
but its just for making it clear now as I am still coding it.
Just wondering if theres some sort of function to get all values and fields from my database.
if (isset($_POST['final_checkout'])) {
$createuser = new User();
$createaddress = new Address();
$createshipping = new Shipping_address();
if (!empty($logged_in)) {
/*als same addres is aangevinkt bij ingelogde user*/
if ($_POST['shipping'] == 'same' ) {
$oldaddress = trim($_POST['oldaddress']);
$oldcity = trim($_POST['oldcity']);
$oldpostal = trim($_POST['oldpostal']);
$oldcountry = trim($_POST['oldcountry']);
$createshipping->user_id = $logged_in->id;
$createshipping->address = $oldaddress;
$createshipping->city = $oldcity;
$createshipping->postal = $oldpostal;
$createshipping->country = $oldcountry; //in tabel addresses nog kolom country maken en dan inputfield ook readonly stap 1
/*als different adres is aangevinkt bij ingelogde user*/
} else{
$othershippingaddress = trim($_POST['create_otheraddress']);
$othershippingcity = trim($_POST['create_othercity']);
$othershippingpostal = trim($_POST['create_otherpostal']);
$othershippingcountry = trim($_POST['create_othercountry']);
$createshipping->user_id = $logged_in->id;
$createshipping->address = $othershippingaddress;
$createshipping->city = $othershippingcity;
$createshipping->postal = $othershippingpostal;
$createshipping->country = $othershippingcountry;
}/*end else shippingaddress*/
/*if user is !logged in*/
}else{
/*create account*/
if ($_POST['optradio'] == 'create') {
/*variabelen maken van de post*/
$newusername = trim($_POST['create_username']);
$newpassword = trim($_POST['create_password']);
$newfirst = trim($_POST['create_first']);
$newlast = trim($_POST['create_last']);
$newmail = trim($_POST['create_mail']);
$newaddress = trim($_POST['create_address']);
$newcity = trim($_POST['create_city']);
$newpostal = trim($_POST['create_postal']);
$newcountry = trim($_POST['create_country']);
/*usertabel invullen*/
$createuser->username = $newusername;
$createuser->first_name = $newfirst;
$createuser->last_name = $newlast;
$createuser->password = $newpassword;
$createuser->user_mail = $newmail;
$createuser->user_image = 'guest';
$createuser->role_id = '4';
/*adresses tabel invullen*/
$createaddress->address = $newaddress;
$createaddress->postal = $newpostal;
$createaddress->city = $newcity;
$createaddress->country = $newcountry;
$createaddress->user_id = '';
/*shipping adres same or different in de create account*/
if ($_POST['shipping'] == 'same') {
/*als same addres is aangevinkt bij nieuwe user*/
$oldaddress = $newaddress;
$oldcity = $newcity;
$oldpostal = $newpostal;
$oldcountry = $newcountry;
/*shipping addres invoeren*/
$createshipping->user_id = $createuser->id;
$createshipping->address = $oldaddress;
$createshipping->city = $oldcity;
$createshipping->postal = $oldpostal;
$createshipping->country = $oldcountry; //in tabel addresses nog kolom country maken en dan inputfield ook readonly stap 1
} else{
/*als different adres is aangevinkt bij nieuwe user*/
$othershippingaddress = trim($_POST['create_otheraddress']);
$othershippingcity = trim($_POST['create_othercity']);
$othershippingpostal = trim($_POST['create_otherpostal']);
$othershippingcountry = trim($_POST['create_othercountry']);
/*shipping addres invoeren*/
$createshipping->user_id = $logged_in->id;
$createshipping->address = $othershippingaddress;
$createshipping->city = $othershippingcity;
$createshipping->postal = $othershippingpostal;
$createshipping->country = $othershippingcountry;
}/*end else different addres*/
}else{
/*als guestaccount is aangevinkt*/
$guestnumber = User::number_guest();
$newusername = 'guest' . $guestnumber;
$newpassword = '';
$newfirst = trim($_POST['create_first']);
$newlast = trim($_POST['create_last']);
$newmail = trim($_POST['create_mail']);
$newaddress = trim($_POST['create_address']);
$newcity = trim($_POST['create_city']);
$newpostal = trim($_POST['create_postal']);
$newcountry = trim($_POST['create_country']);
/*usertabel invullen*/
$createuser->username = $newusername;
$createuser->first_name = $newfirst;
$createuser->last_name = $newlast;
$createuser->password = $newpassword;
$createuser->user_mail = $newmail;
$createuser->user_image = 'guest';
$createuser->role_id = '4';
/*hier al saven om id te krijgen*/
/*adresses tabel invullen*/
$createaddress->address = $newaddress;
$createaddress->postal = $newpostal;
$createaddress->city = $newcity;
$createaddress->country = $newcountry;
$createaddress->user_id = '';
if ($_POST['shipping'] == 'same') {
/*als same addres is aangevinkt bij guest*/
$oldaddress = $newaddress;
$oldcity = $newcity;
$oldpostal = $newpostal;
$oldcountry = $newcountry;
/*shipping addres invoeren*/
$createshipping->user_id = $createuser->id;
$createshipping->address = $oldaddress;
$createshipping->city = $oldcity;
$createshipping->postal = $oldpostal;
$createshipping->country = $oldcountry; //in tabel addresses nog kolom country maken en dan inputfield ook readonly stap 1
} else{
/*als different adres is aangevinkt bij guest*/
$othershippingaddress = trim($_POST['create_otheraddress']);
$othershippingcity = trim($_POST['create_othercity']);
$othershippingpostal = trim($_POST['create_otherpostal']);
$othershippingcountry = trim($_POST['create_othercountry']);
/*shipping addres invoeren*/
$createshipping->user_id = $createuser->id;
$createshipping->address = $othershippingaddress;
$createshipping->city = $othershippingcity;
$createshipping->postal = $othershippingpostal;
$createshipping->country = $othershippingcountry;
}/*end elseif (guestaccount ->sameaddres)*/
}/*end else (guestaccount)*/
} /*end else (!logged in)*/
}/*end isset post*/
if (!empty($logged_in)){
), can you fix that please. \$\endgroup\$}
as you can see. That should be aligned with the code formatted section. It's either one too much from a missing opening brace, or you missed the code balance correctly. \$\endgroup\$