Jump to content

[SOLVED] check box


janim

Recommended Posts

hey guys hello

i want to insert checkbox into mysql like when someone insert his e-mail i would give him option to keep his email private by check box

how can i insert it into mysql and when i show his information print "you can't see the email" or something

many thanks for all

Link to comment
Share on other sites

ok this is the check box

<input name="Check_hphone" type="checkbox" value="Check_hphone" />

and here it;s my insert code

 $insert = mysql_query("insert into $table values ('NULL', '".$_POST['name']."', '".$_POST['check_mail']."')")

thank you for your pleasure 

Link to comment
Share on other sites

ok i explain it

 

add a field in your db for the hide or not

<input name="Check_hphone" type="checkbox" value="Check_hphone" />

value for that should only Y or N to save space

 

heres how to view

 

while($x=mysql_fetch_assoc($query)):

  if ($x[hideORnot]==y)

//show email

endwhile;

 

something like that

 

 

Link to comment
Share on other sites

include("config.php");

$link=mysql_connect($server,$datauser,$datapass)
or die("connection faild becouse".mysql_error());
mysql_select_db($database)
or die("No database".mysql_error());
$check = "select id from $table where email = '".$_POST['email']."';";
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, this E-mail $email is registered before.";exit;}
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['name']."', '".$_POST['email']."', '".$_POST['con']."', '".$_POST['hphone']."', '".$_POST['mphone']."','".$_POST['key']."','".$_POST['sex']."','".$_POST['town']."','".$_POST['position']."','".$_POST['min_salary']."','".$_POST['min_hourly']."','".$_POST['user']."','".$_POST['check_mail']."')")
or die("Could not insert data because ".mysql_error());

 

<input name="check_mail" type="checkbox" value="1"/>

Link to comment
Share on other sites

have your coding this way

include("config.php");
$link=mysql_connect($server,$datauser,$datapass)or die("connection faild becouse".mysql_error());
mysql_select_db($database)or die("No database".mysql_error());
$check = "select id from $table where email = '".$_POST['email']."';";
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, this E-mail $email is registered before.";exit;}
	$insert = mysql_query("insert into $table values 
					('NULL', 
					'".$_POST['name']."', 
					'".$_POST['email']."', 
					'".$_POST['con']."', 
					'".$_POST['hphone']."', 
					'".$_POST['mphone']."',
					'".$_POST['key']."',
					'".$_POST['sex']."',
					'".$_POST['town']."',
					'".$_POST['position']."',
					'".$_POST['min_salary']."',
					'".$_POST['min_hourly']."',
					'".$_POST['user']."',
					'".$_POST['check_mail']."')") or die("Could not insert data because ".mysql_error());
}
if you can insert others why not in this field its just the same to check echo the post for that check if it really has a value or echo your query to know if the DB or PHP code is the prob

Link to comment
Share on other sites

using post in any mysql statement is bad programming add each condition to a varable and use mysql_reel_escape_string()

 

example

 

<?php
$redarrow=mysql_reel_escape_string($_POST['redarrow']);
?>

 

then use the varable $redarrow in the insert

Link to comment
Share on other sites

example u need to add the database insert names values ok.


<?php
include("config.php");

$link=mysql_connect($server,$datauser,$datapass)or die("connection faild becouse".mysql_error());

mysql_select_db($database)or die("No database".mysql_error());

$check = "select id from $table where email = '".$_POST['email']."';";

$qry = mysql_query($check)

or die ("Could not match data because ".mysql_error());

$num_rows = mysql_num_rows($qry);

if ($num_rows != 0) {

echo "Sorry, this E-mail $email is registered before.";

exit;

}
$name=mysql_real_escape_string($_POST['name']); 
$email=mysql_real_escape_string($_POST['email']); 
$con=mysql_real_escape_string($_POST['con']); 
$hphone=mysql_real_escape_string($_POST['hphone']); 
$key=mysql_real_escape_string($_POST['key']); 
$sex=mysql_real_escape_string($_POST['sex']); 
$town=mysql_real_escape_string($_POST['town']); 
$postion=mysql_real_escape_string($_POST['postion']); 
$min_salary=mysql_real_escape_string($_POST['min_salary']); 
$min_hourly=mysql_real_escape_string($_POST['min_hourly']); 
$user=mysql_real_escape_string($_POST['user']); 
$check_mail=mysql_real_escape_string($_POST['check_mail']); 

$insert = mysql_query("insert into $table values 
					('NULL', 
					'$name', 
					'$email', 
					'$con', 
					'$hphone', 
					'$mphone',
					'$key',
					'$sex',
					'$town',
					'$position',
					'$min_salary',
					'$min_hourly',
					'$user',
					'$check_mail' ") or die("Could not insert data because ".mysql_error());
?>

Link to comment
Share on other sites

aha thank you i got the idea

but how can i insert Y or NO into database when i tried '".$POST['check_mail']."' i foubd the field empty in mysql

so how can i insert it  ??? ??? ??? ??? :D :D ;D ;D

 

One thing to be aware of with checkboxes - only checked values are posted. If you want Y/N values to write to db then

$check_mail = isset($POST['check_mail']) ? 'Y' : 'N' ;

 

and write $check_mail to the db table.

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.