[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

mysql insert query problem

Asked by dk4210 in PHP and Databases

Tags: insert, mysql, query

Hello Experts,
I am having a problem with my form results INSERTing into the database. I have a mysql INSERT stmt that I have tried to get working. BAsically, it gives me the error from !sql

if (!$sql) {
            echo 'There has been an error creating you account, please conact the site manager.';

Here is my entire page with the query.. I think something is wrong with my query but not sure how to trouble it..

Thanks for your help...

<?PHP
include('.db.php');
include('common.php');

// Let's Grab the post vars


$status = "1";
$user_level = $_POST['user_level'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$business_name = $_POST['business_name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$account = $_POST['account'];
$newsletter = $_POST['newsletter'];


// Used for debugging. Turn on and off in the common.php file
if ($debug == "ON") {
      echo "the status is"           .$status .     "<br/>";
      echo "the user level is"       .$user_level .     "<br/>";
      echo "the first name is"       .$first_name .     "<br/>";
      echo "the last name is"       .$last_name .      "<br/>";
      echo "the email addy is"       .$email_address .  "<br/>";
      echo "the username is"         .$username    .    "<br/>";
      echo "the business name is" .$business_name .  "<br/>";
      echo "the address is"           .$address       .  "<br/>";
      echo "the city  is"           .$city    .        "<br/>";
      echo "the state is"           .$state    .       "<br/>";
      echo "the zip is"             .$zip    .         "<br/>";
      echo "the phone is"           .$phone  .         "<br/>";
      echo "the account is"         .$account .        "<br/>";
      echo "the newsletter is"       .$newsletter .      "<br/>";
}

// Strip slashes


$first_name    = stripslashes($first_name);
$last_name     = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username      = stripslashes($username);
$business_name = stripslashes($business_name);
$address       = stripslashes($address);
$city          = stripslashes($city);
$state         = stripslashes($state);
$zip           = stripslashes($zip);
$phone         = stripslashes($phone);



// Error checking goes here




// Make sure that the email address hasn't been taken

$sql_email_check = mysql_query("SELECT email_address FROM members
      WHERE email_address ='$email_address'");

// Check to make sure user name hasn't been taken

 $sql_username_check = mysql_query("SELECT username FROM members
 WHERE username = '$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

// If stmt to echo user a messsage telling them that the email / uername exist

if (($email_check > 0) || ($username_check > 0 )) {
      echo "<span class=\"maintext\"> Please fix the following errors:</span> <br/>";
      if ($email_check > 0) {
            echo "<span class=\"maintext\"> <strong> Your email address has already been used by another
            member <br> in our database. Please submit a different email address!</strong></span><br/>";
            unset($email_address);
      }
      if ($username_check > 0) {
            echo "<span class=\"maintext\"><strong>The username that you have selected has already been used by
            another member<br/>in our database. Please choose a different username!</strong></span><br/>";
            unset($username);
            
      }
      echo "<br><br>";
      echo "<a href=\"index.php?content=join2\">Go Back</a>";
      
// Exit the script so that we don't create this account      
      exit();

}


// if everything is successfull let's set up the account

// Random password generator

function makeRandomPassword() {
 $salt = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvXxYyZz0123456789";
 srand((double)microtime()*1000000);
 $i = 0;
 while ($i <= 7) {
  $num = rand() % strlen($salt);
  $tmp = substr($salt, $num, 1);
  $pass = $pass . $tmp;
  $i++;
 }
 return $pass;
 
}

$random_password = makeRandomPassword();
$db_password = md5($random_password);






$sql = mysql_query("INSERT INTO `members` (`id`, `status`, `first_name`, `last_name`,
`address`, `city`, `state`, `zip`, `phone`, `business_name`, `email_address`,
`signup_date`, `verified`, `last_login`, `bio`, `admin_access`, `username`,
 `password`, `account`, `user_level`, `newsletter`) VALUES ('$id', '$status', '$first_name', '$last_name',
'$address', '$city', '$state', '$zip', '$phone', '$business_name', '$email_address', '$signup_date', 'verified', '$last_login', '$bio', '$admin_access',
 '$username', '$db_password', '$account', '$user_level', '$newsletter', now()  
        or die (mysql_error()");
       
       

      if (!$sql) {
            echo 'There has been an error creating you account, please conact the site manager.';
            }else{
                  
                  $id = mysql_insert_id();
                  // Let's mail the user
                  $subject = "Your membership at Bell Plantation!";
                  $message = "Dear $first_name $last_name, \n
                  Thank you for registering at our website, http://www.bellplantation.com!
                  You are ywp steps away from logging in and accessing our exclusive member's area.
                  \n To activate your membership, Please click here http://www.dannykelly.com/bell/index.php?content=activate&id=$id&code=$db_password
                   Once you activate your memebership, you will be able to login
                with the following information:
                Username: $username
                Password: $random_password
                Thanks!
                  Thanks!
    The Bell Plantation Team
    This is an automated response, please do not reply!";  
    mail($email_address, $subject, $message,  
        "From: Bell Plantation Webmaster< registrations@bellplantation.com>\n
        X-Mailer: PHP/" . phpversion());
       
        // Email the administrator
        $mailer = &new Email;
        $mailer->ToMail = "dk4210@planttel.net";
        $mailer->FromMail = "System@bellplantation.com";
        $mailer->FromName = "Bell Plantation Administrator";
        $mailer->Subject = "New Member at bellplantation.com [$username]";
        $mailer->Message = "Hi,\n\n".
                                      "A new member has just signed up ".
                                      "at BellPlantation.com! Here's their ".
                                      " information:\n\n".
                                      "=====================\n".
                                      "First Name: $_POST[first_name]\n".
                                      "Last name: $_POST[last_name]\n\n".
                                      "Email Address: ".
                                      "$_POST[email_address]\n\n".
                                      "UserID: $username\n\n".
                                      "This user is from $city, $state\n\n".
                                      "=====================\n\n".
                                      "Thank you,\n\n".
                                      "Bell Plantation System notification\n";
                                      
                                      
                                      
                                      
        $mailer->SendMail();
                                      
             
       
        ?>
    <br><br><center><br><br><div class="boxheader">Congratulations!!</div><br><div class="maintext"> Your membership information has been mailed to your email address!
    Please check it and follow the directions!</div></center>
   
   
   <br><br><center><a href="index.php"><div class="maintext"> Click here to go back home<div></a></center><br><br>
    <?
}
?>




 
Related Solutions
Keywords: mysql insert query problem
 
Loading Advertisement...
 
[+][-]08/02/06 08:16 PM, ID: 17238842Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/02/06 08:19 PM, ID: 17238847Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP and Databases
Tags: insert, mysql, query
Sign Up Now!
Solution Provided By: sajuks
Participating Experts: 2
Solution Grade: A
 
[+][-]08/03/06 03:34 AM, ID: 17240409Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/06/06 06:52 AM, ID: 17258859Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81