Jump to content

insert checkbox value to database


mdvignesh

Recommended Posts

Checkbox value has to inserted into database

 

Also I have JavaScript check box validation

 

I don't know what to give name for checkbox

 

register.php

<html>
<head>
<script type="text/javascript">
function regval()
{
//name validation
   var name_val=document.registration.uname.value;
   if(name_val=="")
   {
       alert("enter first name");
       document.registration.uname.focus();
       return false;
    }
    else if(name_val!='')
{
   var  name_re =/^[-A-Za-z. ]*$/;
   if(name_re.test(name_val) == false) 
   {
      alert("enter valid name");
      document.registration.uname.focus();
          return false;
        }
     } 
//email validation
 var mail_val=document.registration.email1.value;
 if(mail_val=="")
 {
    alert("enter email address");
    document.registration.email1.focus();
    return false;
 }
 else if(mail_val!="")
 {
   var mailcheck = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(mailcheck.test(mail_val)==false)
   {
      alert("enter valid email address");
      document.registration.email1.focus();
       return false;
   }
 }
//city validation 
var city_val=document.registration.ucity.value;
   if(city_val=="")
   {
       alert("enter city name");
       document.registration.ucity.focus();
      return false;
    }
    else if(city_val!='')
{
   var  city_re =/^[-A-Za-z. ]*$/;
   if(city_re.test(city_val) == false) 
   {
      alert("enter valid city name");
      document.registration.ucity.focus();
          return false;
        }
     }   

 //state validation 
   var state_val=document.registration.ustate.value;
   if(state_val=="")
   {
    alert("enter state name");
     document.registration.ustate.focus();
      return false;
    }
    else if(state_val!='')
{
   var  state_re =/^[-A-Za-z. ]*$/;
   if(state_re.test(state_val) == false) 
   {
      alert("enter valid state name");
      document.registration.ustate.focus();
          return false;
        }
     }   
//country validation 
var country_val=document.registration.ucountry.value;
   if(country_val=="")
   {
    alert("enter country name");
     document.registration.ucountry.focus();
      return false;
    }
    else if(country_val!='')
{
   var  country_re =/^[-A-Za-z. ]*$/;
   if(country_re.test(country_val) == false) 
   {
      alert("enter valid country name");
      document.registration.ucountry.focus();
          return false;
        }
     }
//login name validation
var lname_val=document.registration.lname.value;
   if(lname_val=="")
   {
      alert("enter username ");
      document.registration.lname.focus();
      return false;
    }
//password validation
 var pass_val=document.registration.pass.value;
 if(pass_val=="")
 {
    alert("enter password");
     document.registration.pass.focus();
     return false;
 }
 else if(pass_val!="")
 {
    var invalid = " "; 
        var minLength = 6;
	if (pass_val.length < minLength) 
	{
            alert("Your password must be at least " + minLength + " characters long");
		 document.registration.pass.focus();
             return false;
    }
    if (pass_val.indexOf(invalid) > -1) 
	{
            alert("Sorry, spaces are not allowed.");
	     document.registration.pass.focus();
               return false;
	}
     }

 //checkbox

 if (document.registration.chk[0].checked == false && document.registration.chk[1].checked == false && document.registration.chk[2].checked == false) {
	alert ("select checkbox");

	return false;
 }

}
</script>
</head>
<body>


<?php
include("data.php");
if(isset($_POST["reg"]))
{
$name=$_POST['uname'];
$mail=$_POST["email1"];
$city=$_POST['ucity'];
$state=$_POST['ustate'];
$country=$_POST['ucountry'];
$uname=$_POST['lname'];
$passwd=$_POST['pass'];
$inr=mysql_real_escape_string(implode(",",$_POST["chk"]));
if(mysql_query("insert into register(name,email,city,state,country,username,password,interest) values ('$name','$mail','$city','$state','$country','$uname','$passwd','$inr')"))

$good="You have successfully registered,you can login now";
else
$bad="error:".mysql_error();

}
mysql_close($cn);

?>
<br />

<strong style="background-color:#00CCFF"> 
REGISTRATION FORM</strong>
<br /><br />
<form action="register.php" method="post" name="registration">
<table border="0" width="600" height="600" align="left">
<tr><td>Name:</td><td><input type="text" name="uname"/></td></tr>
<tr><td>Email:</font></td><td><input type="text" name="email1" /></td></tr>
<tr><td>City:</font></td><td><input type="text" name="ucity" /></td></tr>
<tr><td>State:</td><td><input type="text" name="ustate" /></td></tr>
<tr><td>Country:</td><td><input type="text" name="ucountry" /></td></tr>
<tr><td>Username:</td><td><input type="text" name="lname" /></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" /></td></tr>
<tr><td>Intrest:
<input name="chk[]" id="chk[]" type="checkbox" value="reading" />Reading
<input name="chk[]" id="chk[]" type="checkbox" value="sports" />Sports
<input name="chk[]" id="chk[]" type="checkbox" value="travel" />Travel
</td></tr>

<tr><td>
<input type="submit" name="reg" value="ok" style="cursor:pointer;" onclick="return regval();" />   <?php
if(isset($good))
{?>
<input type="button" value="Login" onclick="javascript:window.location='loginpage.php'" style="cursor:pointer;" /><br /><br /><?php
}?>
</td></tr>
</table>
<?php
if(isset($good))
echo $good;
if(isset($bad))
echo $bad;
?></strong></font>
</form>
</div>
</body>

</html>

17377_.php

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.