Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with PHP Registration Form
Old 03-12-2008, 03:39 PM Help with PHP Registration Form
Junior Talker

Posts: 1
Trades: 0
Hi all,

Hi all,

I was looking for a little help with my PHP script. I am trying to create a registration form and login script on my website to keep track of users accounts on my web site. I am currently having a lot of issues getting these scripts to work. When I enter data in the registration form, I get a socket error and it says the registration cannot be completed. I researched the issue on Google and saw that a socket error indicates a problem with SQL server which is hosted on Godaddy. I have contact GoDaddy technical support three times and they continue to insist that even though I am getting a socket error that I have a problem with the script, not an issue on their end with SQL or anything else. Here are the steps I followed and here is my script. If anyone could help, it would be most appreciated.

I created a table on godaddy using their SQL software. I then found a script online which I modified to match the information I need to get from the form. I created the database.php with all of my database information (database name, login name, password etc) and here is the registration script:


PHP Code:
<?
session_start
(); 
include(
"database.php");

/**
 * Returns true if the username has been taken
 * by another user, false otherwise.
 */
function usernameTaken($username){
   global 
$conn;
   if(!
get_magic_quotes_gpc()){
      
$username addslashes($username);
   }
   
$q "select username from users where username = '$username'";
   
$result mysql_query($q,$conn);
   return (
mysql_numrows($result) > 0);
}

/**
 * Inserts the given (username, password) pair
 * into the database. Returns true on success,
 * false otherwise.
 */
function addNewUser($username$password){
   global 
$conn;
   
$q "INSERT INTO users VALUES ('$username', '$password')";
   return 
mysql_query($q,$conn);
}

/**
 * Displays the appropriate message to the user
 * after the registration attempt. It displays a 
 * success or failure status depending on a
 * session variable set during registration.
 */
function displayStatus(){
   
$uname $_SESSION['reguname'];
   if(
$_SESSION['regresult']){
?>

<h1>Registered!</h1>
<p>Thank you <b><? echo $uname?></b>, your information has been added to the database, you may now <a href="main.php" title="Login">log in</a>.</p>

<?
   
}
   else{
?>

<h1>Registration Failed</h1>
<p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname?></b>, could not be completed.<br>
Please try again at a later time.</p>

<?
   
}
   unset(
$_SESSION['reguname']);
   unset(
$_SESSION['registered']);
   unset(
$_SESSION['regresult']);
}

if(isset(
$_SESSION['registered'])){
/**
 * This is the page that will be displayed after the
 * registration has been attempted.
 */
?>

<html>
<title>Registration Page</title>
<body>

<? displayStatus(); ?>

</body>
</html>

<?
   
return;
}

/**
 * Determines whether or not to show to sign-up form
 * based on whether the form has been submitted, if it
 * has, check the database for consistency and create
 * the new account.
 */
if(isset($_POST['subjoin'])){
   
/* Make sure all fields were entered */
   
if(!$_POST['Username'] || !$_POST['Password']){
      die(
'You didn\'t fill in a required field.');
   }

   
/* Spruce up username, check length */
   
$_POST['Username'] = trim($_POST['Username']);
   if(
strlen($_POST['Username']) > 30){
      die(
"Sorry, the username is longer than 30 characters, please shorten it.");
   }

   
/* Check if username is already in use */
   
if(usernameTaken($_POST['Username'])){
      
$use $_POST['Username'];
      die(
"Sorry, the username: <strong>$use</strong> is already taken, please pick another one.");
   }

   
/* Add the new account to the database */
   
$md5pass md5($_POST['pass']);
   
$_SESSION['reguname'] = $_POST['Username'];
   
$_SESSION['regresult'] = addNewUser($_POST['Username'], $md5pass);
   
$_SESSION['registered'] = true;
   echo 
"<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
   return;
}
else{
/**
 * This is the page with the sign-up form, the names
 * of the input fields are important and should not
 * be changed.
 */
?>

<html>
<title>Registration Page</title>
<body>
<h1>Registration</h1>
<form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>First Name:</td><td><input type="First Name" name="First Name" maxlength="30"></td></tr>
<tr><td>Last Name:</td><td><input type="Last Name" name="Last Name" maxlength="30"></td></tr>
<tr><td>Email address:</td><td><input type="Email address" name="Email address" maxlength="30"></td></tr>
<tr><td>Username:</td><td><input type="text" name="Username" maxlength="30"></td></tr>
<tr><td>Password:</td><td><input type="Password" name="Password" maxlength="30"></td></tr>
<tr><td>Phone Number:</td><td><input type="Phone Number" name="Phone Number" maxlength="30"></td></tr>
<tr><td>Street Address:</td><td><input type="Street Address" name="Street Address" maxlength="30"></td></tr>
<tr><td>City:</td><td><input type="City" name="City" maxlength="30"></td></tr>
<tr><td>State:</td><td><input type="State" name="State" maxlength="30"></td></tr>
<tr><td>Zip Code:</td><td><input type="Zip Code" name="Zip Code" maxlength="30"></td></tr>
<tr><td>Request:</td><td><input type="Request" name="Request" maxlength="30"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Register"></td></tr>
</table>
</form>
</body>
</html>


<?
}
?>
Yoccosfan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-12-2008, 07:08 PM Re: Help with PHP Registration Form
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
PHP Code:
 $q "INSERT INTO users VALUES ('$username', '$password')"
There might be other problems, but I'm pretty sure you might be running into some trouble here. You have two values, but you don't specify where to insert them beyond the table name.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 03-12-2008, 10:05 PM Re: Help with PHP Registration Form
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
Okay you said SQL, does that equal MySQL? MSSQL or just SQL? It just may be that everything is communicating incorrectly with godaddy servers. It just may be that your script isnt designed for 1 db and godaddy uses another.

That and with socket errors, may be that your user may not be allowed for mysql access remotely (meaning from another machine different than that of the SQL Server itself)
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Reply     « Reply to Help with PHP Registration Form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11894 seconds with 12 queries