Jump to content

How to avoid undefined index notices?


Fukushousha

Recommended Posts

Hello all.Remembers the checkboxes problem I had. Well even though it is solved and is working by having grouped checkboxes together with arrays I still have a minor problem.If the user does not select any of the checkboxes of a said group I do get an undefined index notice(not an error).For example :

//if we got any checked grp1	if(sizeof($_POST['grp1']) > 0)		loopthroughchecks($_POST['grp1'],"tablename",$user);

I tried to do this with a sizeof check ... but it can't be zero or null, since it exists if and only if the user has checked any boxes. So to avoid getting that annoying "Notice: Undefined index: " how can I do it? How can I check if it exists or not without getting a notice?EDIT: Also another completely unrelated question. Say I got in $conn a persistent sql connection returned by mysql_connect($chostname, $cusername, $cpassword ). How can I check if $conn is still active? Or if I need to reconnect?

Link to comment
Share on other sites

instead of if(sizeof($_POST['grp1'])>0) u can use if(isset($_POST['grp1'])) to see if any of the checkboxes is set$conn usually just stais active till the end of the script, but if u wanna check i think if($conn) would work, but not sure what happens when the connection closes during a script

Link to comment
Share on other sites

If you really need to know what happens if the connection closes, try mysql_close($conn) and print the result of if($conn). (If $conn was created with mysql_pconnect, this won't work.) EDIT: But mysql_connect will retrieve the old connection if it exists.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...