LeonLatex Posted August 26, 2022 Share Posted August 26, 2022 I got a text box called policy_number. If this is left empty on submission the data won't be sent is the idea. But this doesn't work. What is wrong here? <label>Polisenummer:</label> <input type="text" class="w3-input w3-border" name="boat[policy_number]"> This is the PHP script for check: <?php $policy_number= $_POST['policy_number']; $submitbutton= $_POST['submit']; if ($submitbutton){ if (empty($policy_number)) { echo 'Du må fylle inn et polisenummer.'; } else { echo 'Du har fylt ut polisenummer: ' . $fpolicy_number; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/315242-left-empty-control/ Share on other sites More sharing options...
Barand Posted August 26, 2022 Share Posted August 26, 2022 It will be in $_POST['boat']['policy_number']; Quote Link to comment https://forums.phpfreaks.com/topic/315242-left-empty-control/#findComment-1599868 Share on other sites More sharing options...
benanamen Posted August 26, 2022 Share Posted August 26, 2022 Small bit of code but several issues with it. Do not create variables for nothing. You already have the POST variables, just use them You need to check the REQUEST METHOD, not the name of a button. This can completely fail in certain cases. Also, in a properly coded form, ALL form elements save for checkboxes will be submitted (true) A blank space will get past your empty check. You need to trim the entire POST array all at once and THEN check for empty Never ever trust user supplied data. The code is vulnerable to an XSS Attack Quote Link to comment https://forums.phpfreaks.com/topic/315242-left-empty-control/#findComment-1599869 Share on other sites More sharing options...
LeonLatex Posted August 26, 2022 Author Share Posted August 26, 2022 (edited) Time for bed 🤪😴 better now: $_POST['member']['policy_number']; I forgot i had the policy_number in the member table. I Will check it out now. Edited August 26, 2022 by LeonLatex Quote Link to comment https://forums.phpfreaks.com/topic/315242-left-empty-control/#findComment-1599870 Share on other sites More sharing options...
benanamen Posted August 26, 2022 Share Posted August 26, 2022 (edited) Why are you adding another array to your post variables/form element names? Edited August 26, 2022 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/315242-left-empty-control/#findComment-1599871 Share on other sites More sharing options...
Barand Posted August 27, 2022 Share Posted August 27, 2022 His boat club registration form has two sections You Your boat So, in theory, after validating and preparing two insert queries, you can $member_insert->execute($_POST['member']); $boat_insert->execute($_POST['boat']); Quote Link to comment https://forums.phpfreaks.com/topic/315242-left-empty-control/#findComment-1599874 Share on other sites More sharing options...
LeonLatex Posted August 27, 2022 Author Share Posted August 27, 2022 10 hours ago, Barand said: His boat club registration form has two sections You Your boat So, in theory, after validating and preparing two insert queries, you can $member_insert->execute($_POST['member']); $boat_insert->execute($_POST['boat']); Now some peace's fell into place Quote Link to comment https://forums.phpfreaks.com/topic/315242-left-empty-control/#findComment-1599886 Share on other sites More sharing options...
LeonLatex Posted August 28, 2022 Author Share Posted August 28, 2022 On 8/27/2022 at 1:24 AM, benanamen said: Small bit of code but several issues with it. Do not create variables for nothing. You already have the POST variables, just use them You need to check the REQUEST METHOD, not the name of a button. This can completely fail in certain cases. Also, in a properly coded form, ALL form elements save for checkboxes will be submitted (true) A blank space will get past your empty check. You need to trim the entire POST array all at once and THEN check for empty Never ever trust user supplied data. The code is vulnerable to an XSS Attack The script was developed by Barand, and this was probably not the way he set it up in the first place when he developed it for me. I managed quite amazingly to sort of wipe it out when I had to familiarize myself with how it worked in relation to where everything was. Long story short. I was a little too smart-ass when I started on this and didn't back up the original files. Therefore, over time I have spent a lot of time getting it back to where I have come with it now. I have restored it from fragments and differently read solutions online and in books. Therefore, such moments of irritation as you experience can occur. I am sorry for that and apologize for it. What's important for me now is to get it 100% back up and running. Next is to clean it up so you don't have to worry about cosmetic errors anymore. Quote Link to comment https://forums.phpfreaks.com/topic/315242-left-empty-control/#findComment-1599898 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.