Our Sponsors



PHP Nuke themes, stock photos, icons, drupal themes and more.
Custom jobs at low cost, free lancers and service buyers.



Western Studios :: View topic - Using PHP SELECT from etc etc for login validation.
Need Jobs done? Use our brand new Jobs Board to get your projects done at affordable prices.
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups     ProfileProfile   Log inLog in 


Using PHP SELECT from etc etc for login validation.



 
Post new topic   Reply to topicprinter friendly version    Western Studios Forum Index -> Web Design
Western Studios

WS Newbie
WS Newbie
~PHP Nuke User~


Posts: 41
Next Group: 9 posts
JRowe wrote:

I'm trying to put together a CMS shell for myself and I'm wondering if someone could give me a hand.

I want to check if a username has been taken during the registration process. The only problem is that there are two databases. One is the billing database (a generic subs manager i threw together) and the other is the game database. I want to check if a username has been taken in the games database, and if so, send the user back to the signup page.

Here's my code:
Code:
<html>
<head>
<title>Game Subscription</title>
</head>
<body>
<h1>Game Subscription</h1>
<?php

//HERE THERE BE GAMES
$_POST[gametitle] = 'Game Name Here';
//HERE THERE BE GAMES

//SET USER INFO
$firstname=$_POST[firstname];
$lastname=$_POST[lastname];
$address=$_POST[address];
$city=$_POST[city];
$state=$_POST[state];
$country=$_POST[country];
$zipcode=$_POST[zipcode];
$email=$_POST[email];
$username=$_POST[username];
$password=$_POST[password];
$gametitle=$_POST[gametitle];
$ccnumber=$_POST[ccnumber];
$ccexpmonth=$_POST[ccexpmonth];
$ccexpyear=$_POST[ccexpyear];
$ccCVN=$_POST[ccCVN];
//SET USER INFO

//GET DATE
$date=date("y-m-d H:i:s");
//GET DATE

//PARSE USER INFO FOR BLANK FORMS
if(!$firstname || !$lastname || !$address || !$city || !$state || !$country || !$zipcode || !$email || !$username || !$password || !$gametitle || !$ccnumber || !$ccexpmonth || !$ccexpyear || !$ccCVN)
{
   echo 'Please fill out all the required information. Press the back button on the browser, or hit Alt+Left, and fill out all the required information.';
   exit;
}
//PARSE USER INFO FOR BLANK FORMS

//PARSE USER INFO FOR EXISTING USERNAME

//PARSE USER INFO FOR EXISTING USERNAME

//SET DATABASE SERVER INFORMATION AND CONNECTION INTO BILLING DB
$link = mysql_connect('localhost', 'dadada', 'dadada');
//SET DATABASE SERVER INFORMATION AND CONNECTION INTO BILLING DB

//OPEN DATABASE INTO BILLING DB
$open = mysql_select_db("BillingDB");
//OPEN DATABASE INTO BILLING DB

//COMMAND TO INSERT INFORMATION INTO DATABASE INTO BILLING DB
$information = "insert into Customer(FirstName, LastName, Address, City, State, country, ZipCode, Email, Username, Password, Game, CardNumber, CardExpMonth, CardExpYear, CardCVN)  values('$firstname','$lastname','$address','$city','$state','$country','$zipcode','$email','$username','$password','$gametitle','$ccnumber','$ccexpmonth','$ccexpyear','$ccCVN')";
//COMMAND TO INSERT INFORMATION INTO DATABASE INTO BILLING DB

//COMPLETE INFORMATION UPDATE OR INSERTION INTO BILLING DB
mysql_query($information);
//COMPLETE INFORMATION UPDATE OR INSERTION INTO BILLING DB

//SET DATABASE SERVER INFORMATION AND CONNECTION INTO GAME DB
$link = mysql_connect('localhost', 'dadada', 'dadada');
//SET DATABASE SERVER INFORMATION AND CONNECTION INTO GAME DB

//OPEN DATABASE INTO GAME DB
$open = mysql_select_db("dadada");
//OPEN DATABASE INTO GAME DB

//COMMAND TO INSERT INFORMATION INTO DATABASE INTO GAME DB
$gameupdate = "insert into users(pay,idname, passwd,regi_date,enable,name,lastname,email,city,region,countryeic)  values('c','$username','$password','$date','1','$firstname','$lastname','$email','$city','$state','$country')";
//COMMAND TO INSERT INFORMATION INTO DATABASE INTO GAME DB

//COMPLETE INFORMATION UPDATE OR INSERTION INTO GAME DB
mysql_query($gameupdate);
//COMPLETE INFORMATION UPDATE OR INSERTION INTO GAME DB
?>
</body>
</html>


I need a function that checks whether $username already exists in the game database, and if so, tells you to go back and choose a different name.

So, this is what I came up with, and it doesnt work, heh.

Code:
$link = mysql_connect('xx.xx.xxx.xxx', 'Username', 'Password');   
$UNCheck = "SELECT * from game_db WHERE idname='$username'";
if(mysql_query($UNCheck)->num_rows>0)
{
   echo 'This username has been used already. Please hit the back button on your browser, or press Alt+Left, and choose a new Username.';
      exit;


Can someone clean that up for me, or show me what I did wrong? Much thanks for any assistance.

idname is the username within the game database.

Posted: Wed May 31, 2006 2:35 pm

Western Studios

Site Admin
Site Admin
~PHP Nuke User~

Platinum Subscriber

Posts: 3366
Staff
Next Group: 1634 posts
admin(Mark) wrote:

hi, something like this should work

Code:

//ACCESS DATABASE
$userName = 'USERNAME';
$userPass = 'PASSWORD';
$dbName = 'DATABASENAME';
$mysql_access = mysql_connect("localhost", $userName, $userPass);
mysql_select_db($dbName, $mysql_access);
//END DATABASE ACCESS

$query = "SELECT * FROM game_db WHERE idname='$username'";
$result = mysql_query($query, $mysql_access);
if(mysql_num_rows($result)) {
//THE USER EXIST SO ECHO SOMETHING HERE
echo 'USER EXIST';

} else {
//USER DOES NOT EXIST
echo 'YOUR ARE NOT A MEMBER';
}


Posted: Wed May 31, 2006 3:50 pm

Western Studios

WS Newbie
WS Newbie
~PHP Nuke User~


Posts: 41
Next Group: 9 posts
JRowe wrote:

awesomeness. Thanks much man Smile

Posted: Wed May 31, 2006 4:19 pm

Post new topic   Reply to topic    Western Studios Forum Index -> Web Design All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Related topics
 Topics   Replies   Author   Views   Last Post 
No new posts I'm back 1 xtrax 762 Sat Mar 04, 2006 7:18 pm
admin View latest post
No new posts Ajax - The past is back 0 admin 757 Wed Nov 16, 2005 2:53 pm
admin View latest post
No new posts We're back 0 admin 676 Thu May 05, 2005 8:04 am
admin View latest post
No new posts Site back online 2 admin 871 Tue Apr 05, 2005 10:36 am
admin View latest post
No new posts Downloads will be back soon 1 admin 806 Wed Feb 23, 2005 2:36 pm
admin View latest post
 
Forums ©