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

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.