mysql - how to avoid duplicating in php -
i new in terms of php. creating simple program similar login page. may please me coding, have mysql table named user has 3 column userid, email , password. primary userid , auto increment. how can have code is, column email should no duplication or no same email. have code avoiding empty fields don't know how duplication.. here sample code:
<?php if(isset($_post['submit'])){ $dbhost = 'localhost'; $dbuser = 'root'; $conn = mysql_connect($dbhost, $dbuser); mysql_select_db('dtr'); if(! $conn ){ die('could not connect: ' . mysql_error()); } if(! get_magic_quotes_gpc() ){ $email = addslashes ($_post['email']); $password = addslashes ($_post['password']); } else{ $email = $_post['email']; $password = $_post['password']; } //validation if($email == ''){ echo "empty ang email" ?></br><?php ; return false; } if($password == ''){ echo "kailangan may password ka\n" ?></br><?php ; return false; } ---------------------->//select * table username=user { $sql = "insert user "."(email, password) "."values('$email','$password')"; $retval = mysql_query( $sql, $conn ); } if(! $retval ){ die('could not enter data: ' . mysql_error()); } echo "entered data successfully\n"; mysql_close($conn); } else { } ?>
help me plz..
you can try:
$sql = "select userid users email = ". $_post["email"]; if (mysql_num_rows(mysql_query($sql, $con)) >= 1) { echo "that email provided seems used"; return; }
and please thing using different db extension since mysql deprecated of php v. 5.5. give better security features binding , prepared statements.
Comments
Post a Comment