NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP Amateur and Registration Script

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
6 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 03-28-2005, 07:03 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Dec 2004
Posts: 30
n0dice is an unknown quantity at this point
 



PHP Amateur and Registration Script


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");
????: NamePros.com http://www.namepros.com/programming/78326-php-amateur-and-registration-script.html
}

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@mail.com'' at line 1 (left out the actual email and username)
Last edited by n0dice; 03-28-2005 at 07:15 AM.
n0dice is offline  
Old 03-28-2005, 08:09 AM   #2 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer
change

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

to this

SELECT `username` FROM `users` WHERE `username` = '$username' and `email` = '$email'"
adam_uk is offline  
Old 03-28-2005, 10:08 AM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Dec 2004
Posts: 30
n0dice is an unknown quantity at this point
 



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 by n0dice; 03-28-2005 at 10:27 AM.
n0dice is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:51 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger