Jump to content

registration form with postgre database, need some help


iNko

Recommended Posts

Hello, iv got a code that validates form fields:

////////////////////duomenys is regform.php
$username = $_POST['regname'];
$email= $_POST['regemail'];
$password1 = $_POST['regpass1'];
$password2 = $_POST['regpass2'];
///////////////////////////////////////////



ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
$result = pg_query('SELECT 1 FROM duom WHERE LOWER(name)=\''.strtolower(pg_escape_string($username)).'\'')or exit(pg_last_error());



if(isset($_POST['regsubmit'])){
////////////////////////////////////tikrina ar viskas uzpildyta
if($username !="" && $email !="" && $password1 !="" && $password2 !="" && $password1 == $password2) {
///////////////////////////////////////////////////////////////

	if (pg_num_rows($result)) {
	exit('Toks vartotojas jau egzistuoja, pasirinkite kita vartotojo varda');
    
    } else
///////////////////ideda duomenys is regform.php i duomenu baze
$insert = "INSERT into duom(name, email, pass) VALUES('".$username."','".$email."','".$password1."')";
pg_query($insert);
echo "Registracija pavyko!";
///////////////////////////////////////////////////////////////
} else
echo "Blogai uzpildyti domenys!";
}	

 

everything is working but i need to add 1 more thing to this - to see if email already exists in the databse. I did it for username but idk how to add the same code for email.

Heres the code to check if username already exists:

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
$result = pg_query('SELECT 1 FROM duom WHERE LOWER(name)=\''.strtolower(pg_escape_string($username)).'\'')or exit(pg_last_error());
if (pg_num_rows($result)) {
exit('Username already exists);

 

Thx in advance

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.