Jump to content

How to manadatory checkboxes without display Server error to user


ankit.pandeyc012

Recommended Posts

<?php
echo $error_msg='';
if(isset($_POST['submit']))
{
$LoginId=$_POST['LoginId'];
$Password1=$_POST['Password1'];
$Password2=$_POST['Password2'];
$Name=$_POST['Name'];
$Age=$_POST['Age'];
$BloodGroup=$_POST['BloodGroup'];
$Sex=$_POST['Sex'];
$Qualification=$_POST['Qualification'];
$Email=$_POST['Email'];
$Address=$_POST['Address'];
$AboutYourself=$_POST['AboutYourself'];
[b]$countCheck=count($_POST['checkbox']);
echo $countCheck;[/b]
//$checkbox=$_POST['checkbox'];
//$countCheck=count($checkbox);
if(empty($LoginId)){echo 'Please enter Login Id';}
elseif(empty($Password1)){echo 'Please enter Password';}
elseif(empty($Password2)){echo 'Please confirm Password';}
elseif($Password1!==$Password2){echo 'Password didn\'t match';}
	elseif(empty($Name)){echo 'Please enter Name';}
	elseif(empty($Age)){echo 'Please enter Age';}
	elseif(empty($Sex)){echo 'Please enter Sex';}
	elseif(empty($Qualification)){echo 'Please enter Qualification';}
	elseif(empty($Email)){echo 'Please enter Email';}
	elseif(empty($Address)){echo 'Please enter Address';}
	elseif(empty($AboutYourself)){echo 'Please enter About Yourself';}
	[b]elseif($countCheck==0){ echo 'You have to register at least one activity.';}[/b]
	else
	{
	$dbc=mysqli_connect('localhost','root','','nog');
	$query="select * from registration where LoginId='$LoginId'";
	$result=mysqli_query($dbc,$query);
	if(mysqli_num_rows($result)==0)	
	{		
	$checkbox=$_POST['checkbox'];
	$countCheck=count($_POST['checkbox']);
	$reg_id=' ';
	for($i=0;$i<$countCheck;$i++)
	{
	$reg_id=$reg_id.$checkbox[$i].',';
	}
	$query="insert into registration (LoginId,Password,Name,Age,BloodGroup,Sex,Qualification,Email,Address,AboutYourself,Activity)values ('$LoginId',SHA('$Password1'),'$Name','$Age','$BloodGroup','$Sex','$Qualification','$Email','$Address','$AboutYourself','$reg_id')";
	$result=mysqli_query($dbc,$query) or die("Not Connect");

	echo ' Dear '.$Name.'.<br>Your Account is waiting for approval<br>';
	echo "<a href='RegistrationAndActivity.php'>Back to Home</a>";
	//header('Location: index.php');
	//	header('Location: Registration.php');
	}
	else
	{
	echo 'Dear '.$Name. ' <br>Account already exist with Login Id '.$LoginId.' <br>Try another Login Id';
	}}	
}		
?>

<html>
<body>
<?php
echo $error_msg; ?>
<h3>New User?</h3>
<form action='<?php echo $_SERVER['PHP_SELF'];?>' method='post'>

Enter Login id<br><input type='text' name='LoginId' value='<?php if(!empty($LoginId))echo $LoginId;?>'/><br>
Enter Password<br><input type='password' name='Password1' value='<?php if(!empty($Password1))echo $Password1;?>'/><br>
Confirm Password<br><input type='password' name='Password2' value='<?php if(!empty($Password2))echo $Password2;?>'/><br>
Enter Name<br><input type='text' name='Name' value='<?php if(!empty($Name))echo $Name;?>'/><br>
Enter Age<br><HEAD>
   <SCRIPT language=Javascript>
      
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
  
  
     
   </SCRIPT>
   </HEAD>
<INPUT onkeypress='return isNumberKey(event)' type='text' name='Age' value='<?php if(!empty($Age))echo $Age;?>'><br/>
Enter Blood<br><input type='text' name='BloodGroup'value='<?php if(!empty($BloodGroup))echo $BloodGroup;?>'/><br>
Enter Sex<br><input type='text' name='Sex'value='<?php if(!empty($Sex))echo $Sex;?>'/><br/>
Enter Qualification<br><input type='text' name='Qualification' value='<?php if(!empty($Qualification))echo $Qualification;?>'/><br>
Enter Email<br><input type='text' name='Email' value='<?php if(!empty($Email))echo $Email;?>'/><br>
Enter Address<br><input type='text' name='Address' value='<?php if(!empty($Address))echo $Address;?>'/><br>
About Yourself<br/><textarea rows='10' cols='22' name='AboutYourself' value='<?php if(!empty($AboutYourself))echo $AboutYourself;?>'></textarea><br/>

<?php echo"
<b>Select fields for which you want to register</b><br/>";

$dbc=mysqli_connect('localhost','root','','nog');
$query="select * from activity";
$result=mysqli_query($dbc,$query);
while($row=mysqli_fetch_array($result)){
$Title=$row['Title'];
$ActivityId=$row['ActivityId'];
echo $Title;
//echo $ActivityId;
[b]echo "<input type='checkbox' name='checkbox[]' value=$ActivityId />"[/b];//value=$ActivityId tells ActivityId variable extracts with name="checkbox"
echo "<br/>";
}
echo "<input type='submit' value='Register' name='submit'/><br>";

echo "</form>
</body>
</html>";?>

 

 

 

Hi friends.........

In above code I want to manadatory the checkboxes which works properly as well but when user not select any checkbox it should display "You have to register at least one activity." according to above code but user get an extra server error also "Notice: Undefined index: checkbox in C:\wamp\www\NGOProject\RegistrationAndActivity.php on line 16

You have to register at least one activity. "

I don't want to display this extra server error "Notice: Undefined index: checkbox in C:\wamp\www\NGOProject\RegistrationAndActivity.php on line 16" to user...............

PLz help me ..........

Anyone???????????????

Thx in advance..................

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.