<?
include "config.php";
$db = mysql_connect($db_host,$db_user,$db_pass)or die (mysql_error());
mysql_select_db ($db_name) or die ("Cannot connect to database")or die (mysql_error());
// Define post fields into simple variables
$name = $_POST['name'];
$cpanel = $_POST['cpanel'];
$username = $_POST['username'];
$domain = $_POST['domain'];
/* Let's strip some slashes in case the user entered
any escaped characters. */
$name = stripslashes($name);
$username = stripslashes($username);
$domain = stripslashes($domain);
$cpanel = stripslashes($cpanel);
/* Do some error checking on the form posted fields */
if((!$name) || (!$domain) || (!$username) || (!$cpanel)){
echo 'You did not submit the following required information! <br />';
if(!$name){
echo "Your Name is a required field. Please enter it below.<br />";
}
if(!$domain){
echo "Your Domain Name is a required field. Please enter it below.<br />";
}
if(!$username){
echo "Username / Email Address is a required field. Please enter it below.<br />";
}
if(!$cpanel){
echo "Cpanel Username is a required field. Please enter it below.<br />";
}
include 'register.php'; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}
/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$username_check = mysql_num_rows($sql_username_check);
if(($username_check > 0)){
echo "Please fix the following errors: <br />";
if($username_check > 0){
echo "The Username you have selected has already been used by another member
in our database. Please choose a different username!<br>";
unset($username);
}
include 'register.php'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}
/* Everything has passed both error checks that we have done.
It's time to create the account! */
/*We'll generate a random password for the
user and encrypt it, email it and then enter it into the db.
*/
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
// Enter info into the Database.
$sql = mysql_query("INSERT INTO users (name, email, username, password,cpanel) VALUES('$name', '$username', '$username', '$db_password','$cpanel'") or die (mysql_error());
if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster on <a href=\"admin@domain.com\">admin@domain.com</a>';
} else {
$id = mysql_insert_id();
// Let's mail the user!
$subject = "Your Helpdesk Account on domain";
$message = "Dear $name,
You have now signed up for your account at [url]http://domain.com[/url]!
In order to use your account, two more steps must be completed.
The first step is for you to activate your account. Do this by clicking below;
please click here: [url]http://www.domain.com/activate.php?id=[/url]$id&code=$db_password
You will need the following info to login.
Username: $username
Password: $random_password
The administrator will also need to activate your account.
You will be notified when this happens.
Thanks!
The Admin
---------------------------------------------------
This is an automated response, please do not reply!
---------------------------------------------------
";
mail($emailad, $subject, $message,
"From: Domain Admin<admin@domain>");
echo 'Your membership information has been mailed to your email address!
Please check it and follow the directions!';
}
?>
i keep getting
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
i know it will be something small, but i cant see why.
can anyone help?
Cheers