NameSilo

PHP Amateur and Registration Script

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

n0dice

Established Member
Impact
0
Hey guys,

Just got into PHP a week or so ago and I'm really enjoying it. Up to this point, with my network of (unstyled pages) I've created an index page with a login/logout page which will interact with the database appropriately - I figured out how to get my sessions working as well as getting the sha1 encryption going for the passwords. Problem being I can't figure out how to get my registration script working. I want it to check the username/email values and perform an if/else to say "someone already has this username" if they exist before running the registration script and I can't figure it out at all.

Heres the code:

register.php

<?
session_start();
header("Cache-control: private");
require ('db_connect.php');

if (isset($_SESSION['logged'])) {
?>
<p>You are already logged in</p>

<?

}
else {
?>

<form action="verify.php" method="post">
First Name:<input type="text" name="firstname"><br>
Last Name:<input type="text" name="lastname"><br>
Email:<input type="text" name="email"><br>
User Name:<input type="text" name="username"><br>
Password:<input type="password" name="password"><br>
Adress:<input type="text" name="adress"><br>
City:<input type="text" name="city"><br>
Region:<input type="text" name="region"><br>
Country: <input type="text" name="country"><br>
Phone Number:<input type="text" name="phone"><br>
<input type="submit" value="submit" name="submit">

</form>

<?
}
?>






verify.php:

<?
session_start();
header("Cache-control: private");


$firstname = $_POST ['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$username = $_POST['username'];
$emailpassword = $_POST['username'];
$password = sha1($_POST['password']);
$adress = $_POST['adress'];
$city = $_POST['city'];
$region = $_POST['region'];
$country = $_POST['country'];
$phone = $_POST['phone'];
require ('db_connect.php');

$query = mysql_query("SELECT username FROM users WHERE username ! '$username' and email ! '$email'");
if(!$query) {
print mysql_error();
exit();
}
if(mysql_affected_rows()==0){
print("Registration Script");
}

else {
print ("Invalid Username / Password");
}
?>


Am I headed in the right direction with this? Any help is much appreciated

edit: typo, the $query tag was not actually mislabled on my machine.

The error message it gives me is:
Y
ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '! 'username' and email ! '[email protected]'' at line 1 (left out the actual email and username)
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
change

SELECT username FROM users WHERE username ! '$username' and email ! '$email'

to this

SELECT `username` FROM `users` WHERE `username` = '$username' and `email` = '$email'"
 
0
Close
Ahh, it works - thanks very much.

edit: figured out my new problem, evedently you can't imput to a field with two words. Renamed it to word_word and it worked.
 
Last edited:
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back