I need help with register

Hello this is my registration form I need to without @ and .com badges could not register because now p.v.z. enters the login name and any subsequent email adsasdasdqwd and they can register to do or which one you can perasyti this code that should be added to normal email with @ and .com badges, and otherwise prevent register if missing @ and .

[php]<?php

require(‘config.php’);

$tbl_name=“forum_user”;

mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

$username=str_replace($invalidchars,"",$_POST[‘username’]);
$password=md5($_POST[‘password’]);
$email=str_replace($invalidchars,"",$_POST[‘email’]);
$metai=str_replace($invalidchars,"",$_POST[‘metai’]);
$realname=str_replace($invalidchars,"",$_POST[‘realname’]);

if (!$username) { die(‘Uzpildei nevisus laukus’); }
if (!$password) { die(‘Uzpildei nevisus laukus’); }
if (!$email) { die(‘Uzpildei nevisus laukus’); }

$sql = mysql_query(“SELECT * FROM $tbl_name WHERE username=’$username’”);
$num_rows = mysql_num_rows($sql);

if ($num_rows > 0) {
die (‘Sis prisijungimo vardas jau uzimtas’);
}

$sql2=“INSERT INTO $tbl_name(username, metai, password, email, realname)VALUES(’$username’, ‘$metai’, ‘$password’, ‘$email’, ‘$realname’)”;
$result2=mysql_query($sql2);

if($result2){
header(“Location: created_user.php”);
}
else {
echo “ERROR”;
}
mysql_close();
?>
[/php]

Lukx, I am not really sure what your question is. First, you should not use MySQL functions anymore as they are not in the
latest version of PHP and will not work on some servers. You should update your code to either MySQLi or PDO. Updating
to MySQLi is easy and would only need a few minor changes.

Next, you really should not use the DIE() functions as the page will stop at that point and no longer function. That is not good
for the user as they do not get a very good display of the error. Each step in your code should display an error if found and if
not, it should continue thru the program steps.

Next, you replace unwanted chars in your fields by removing them. This is not a very good way to validate your inputs. There
are many many good ways to validate inputs from users, but, that is not one of them. Here are some sites that explain ways
to handle this. Hope this helps you find the way you prefer to use…
http://www.tutorialspoint.com/php/php_validation_example.htm
http://www.w3schools.com/php/php_form_validation.asp
https://www.sitepoint.com/form-validation-with-php/

Sponsor our Newsletter | Privacy Policy | Terms of Service