So forgive this dumb question. I’m a music teacher, not a programmer.
I am submitting a form. I have possibly checked checkboxes for “spoken languages”.
<input type="checkbox" id="speakEnglish" name="speakEnglish" value="yes" />
<input type="checkbox" id="speakGerman" name="speakGerman" value="yes" />
And then on form submit I have
$speakEnglish = $_POST['speakEnglish'];
$speakGerman = $_POST['speakGerman'];
And formulate my SQL query from that. It was submitting and INSERTing fine on my local host, but since uploading to a server I’m getting this when a checkbox is empty…
AN error occurred in the script '/home/berli/public_html/TEST/signup.php' on line 295:
Undefined index: speakGerman
This confuses me .. though I understand whats going on.
But why was my form submitting with empty checkboxes before, and now it throws an error?
What is the normal way to handle this?
Something like..?
if(isset($_POST[checkboxVar]) { $SQLcheckboxVar = $_POST[checkboxVar]} };
I just don’t understand why empty checkboxes didn’t hang me up on local host, but now they do. I cant think of anything else I could have done to cause that and I certainly wasn’t testing for the checkbox variables before… but I have a SQL table full of INSERTed entries.
Is there some kind of difference on how this would work locally vs on a server?
Your servers error reporting must show notices/warnings (not sure specifically which one that is).
You are correct in saying that
if(isset($_POST['checkboxVar']))is all you would need to hide that error if you can’t change your php configuration (php.ini). This is what you need on your online server (usually/etc/php.ini):