Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Column count doesn't match value count at row 1

    I'm getting Column count doesn't match value count at row 1 error when trying to register..

    This is the code
    PHP Code:
    <?php
    session_start
    ();
    require (
    "connect.php");
    require (
    "functions.php");
    include (
    "template/template.class.php");
    include (
    "inc/ipconv.php");
    $setsql mysql_query("SELECT * FROM settings");
    $setres mysql_fetch_array($setsql);
    $adminemail $setres['adminemail'];
    $baseurl $setres['baseurl'];
    $gifts intval($_GET['gifts']);


    $ip getip();

    /* Initiate duplicate I.P check
    ==------------------------------*/
    if (isset($_POST['submit'])) { 
        
    $ipsql mysql_query("SELECT ip FROM users WHERE ip='$ip'");
        if(
    mysql_num_rows($ipsql)!=0)
        {
            
    $error 'Your I.P. is already in use by another member.<br />
            <br />If you are having problems with your account <br />or think this is incorrect, please contact support!<br /><br />'
    ;
            
                
    mysql_query("INSERT INTO iplog (id, ip) VALUES('', '$ip')"
                or die(
    mysql_error());
        }
        else { echo 
    ''; }
    }


    $template = new Template;
    $template->load("template/header.php");
    $template->replace("Login"file_get_contents("template/includes/login.php"));
    $template->publish();

    echo 
    '<script language="javascript">
        function focuson()
          { document.regform.number.focus()}
        function check()
            {
            if(document.regform.number.value==0)
                {
                alert("Please enter the captcha code");
                document.regform.number.focus();
                return false;
                }
            }
        </script>'
    ;

    if(isset(
    $_POST['submit'])){
       
    $username mysql_real_escape_string($_POST['username']);
       
    $email mysql_real_escape_string($_POST['email']);
       
    $password mysql_real_escape_string($_POST['password']);
       
    $forename mysql_real_escape_string($_POST['forename']);
       
    $surname mysql_real_escape_string($_POST['surname']);
       
    $address1 mysql_real_escape_string($_POST['address1']);
       
    $address2 mysql_real_escape_string($_POST['address2']);
       
    $postcode mysql_real_escape_string($_POST['postcode']);
       
    $country mysql_real_escape_string($_POST['country']);
       
    $agree mysql_real_escape_string($_POST['agree']);
       
    $refer mysql_real_escape_string($_POST['referal']);
       
    $captcha mysql_real_escape_string($_POST['captcha']);
       
       
    $gifts intval($_GET['gifts']);
       
    $gvalue1 mysql_query("SELECT * FROM gifts WHERE id='$gifts'");
       
    $gvalue2 mysql_fetch_array($gvalue1);
       
    $gtitle $gvalue2['title'];
       
    $greff $gvalue2['referrals'];
       
       
    $date date('Y-m-d H:i:s');
       
    $cpass mysql_real_escape_string($_POST['confirmpassword']);
       
    $uresult mysql_query("SELECT * FROM users");
       
    $unum mysql_num_rows($uresult);
       if(
    $unum == 0){
          
    $status "2";
          }else{
             
    $status "1";
          }
       
       if(
    $password != $cpass){
          
    $error "The passwords entered do not match!<br />";
       }
       if(
    $username == 'admin'){
          
    $error "Invalid Username.<br />";
       }
       if(
    $captcha == ''){
          
    $error "Enter Captcha.<br />";
       }
       if(
    $agree != 'Yes'){
          
    $error "Please agree to out Terms Of Service<br />";
       }
       if(isset(
    $captcha)){
          
    $key=substr($_SESSION['key'],0,5);
          
    $captcha $_REQUEST['captcha'];
          if(
    $captcha!=$key){
                
    $error 'Incorrect Captcha code.<br />';
               }
         }
         

         

       if(empty(
    $username) || empty($email) || empty($password)){
          
    $error $error 'All fields need to be filled out.<br />';
       }
       if(!isset(
    $error)){
       if(isset(
    $password)){
       if(
    strlen($password) <= 5){
          
    $error "Your password needs to be at least 6 characters in length!";
       }}}
       
    $result mysql_query("SELECT * FROM users WHERE username = '$username'");
       
    $num mysql_num_rows($result);
       if(
    $num == 1){
          
    $error $error "The username $username is already in use! Please select another!<br />";
       }
       
    $result mysql_query("SELECT * FROM users WHERE email = '$email'");
       
    $num mysql_num_rows($result);
       if(
    $num == 1){
          
    $error $error "The email $email is already in use! Please use another!<br />";
       }
       
       if(isset(
    $error)){
       echo 
    "<h2 class='delicious-heavy'>Error!</h2>
       <p class='delicious-heavy'><br />$error</p>"
    ;
       }
       
       else {
       
    $password sha1($password);
       
    mysql_query("INSERT INTO users VALUES(NULL, '$username', '$email', '$password', '$forename', '$surname', '$status', '0', '0', '0', '0', '$address1', '$address2', '$postcode', '$country', '$gifts', '$gtitle', '$greff', '$refer', '0', '$agree', '$ip', '0', '0')") or die(mysql_error());
           
    // Now, finally, as the registration has been sucessful we credit the referer :D
        
    $result mysql_query("SELECT * FROM users WHERE id = '$refer'") or die(mysql_error());
        
    $num mysql_num_rows($result);
        if(
    $num == 0){
        
    // No referal with that ID exists, or there just isn't one selected //
            
    $refer "none";
        } else {
        
    credituser($refer);
        }
        
        
        
        
        
        
        
    //1
        
    $result mysql_query("SELECT * FROM users WHERE ip='$ip' LIMIT 1"
        or die(
    mysql_error()); 
        while(
    $row mysql_fetch_array$result )) {
            
    $nuid $row['id'];
        }
        
        
    //2
        
    $mailvervar md5($email 'Hu6Dedi8Bj7ff32sS');
        
        
    //3
        
    mysql_query("INSERT INTO emailcheck 
        (id, user, keycheck) VALUES('', '$nuid', '$mailvervar') "

        or die(
    mysql_error());  


        
    //4
        
    $to $email;
        
    $subject "RewardCrazy.com Email Validation";
        
    $message "Hi $username,\nWelcome to www.rewardcrazy.com\n\nPlease visit the link below to validate your email address!\n
    "
    .$baseurl."/index.php?ekey=$mailvervar
    "
    ;

        
    $from $adminemail;
        
    $headers "From: $from";
        if (
    mail($to,$subject,$message,$headers)) {
            echo(
    "<h2 class='delicious-heavy'>Registration successful!</h2>
            <p class='delicious-heavy'>Please validate your email before you login!</p>"
    );
        } 
        else {
            echo(
    "<h2 class='delicious-heavy'>Error!</h2>
            <p class='delicious-heavy'>Registration failed...<br />There was a problem sending the registration email.</p>"
    );
        }
        
        
        
          }
          } else {
             
    $referal intval($_SESSION['refer']);
    ?>   


    <?php 
    if (!empty($gifts)) { echo '<div id="myaccount" style="width:550px; float:left;position:relative;left:50px">'; }
    else { echo 
    '<div id="myaccount">' ;} ?>
          <h2 class="delicious-heavy" style="text-decoration:underline;padding-bottom:5px">Register</h2>
          <form method="POST" action="" onSubmit="return check();" name="regform">
             <div class="myaccdiv">
             <p class="delicious-heavy">Username:</p>
             <div class="i-left"></div>
             <input type="text" name="username" class="i-bg" />
             <div class="i-right"></div><br style="clear:both" />
             </div>
             
             <div class="myaccdiv">
             <p class="delicious-heavy">E-mail:</p>
             <div class="i-left"></div>
             <input type="text" name="email" class="i-bg" />
            <div class="i-right"></div><br style="clear:both" />
            </div>
             
             <div class="myaccdiv">
             <p class="delicious-heavy">Password:</p>
             <div class="i-left"></div><input type="password" name="password" class="i-bg" />
            <div class="i-right"></div><br style="clear:both" />
            </div>
             
             <div class="myaccdiv">
             <p class="delicious-heavy">Confirm Password:</p>
             <div class="i-left"></div>
             <input type="password" name="confirmpassword" class="i-bg" />
            <div class="i-right"></div><br style="clear:both" />
            </div>
             
             <div class="myaccdiv">
             <p class="delicious-heavy">First Name:</p>
             <div class="i-left"></div>
             <input type="text" name="forename" class="i-bg" />
            <div class="i-right"></div><br style="clear:both" />
            </div>
             
             <div class="myaccdiv">
             <p class="delicious-heavy">Surname:</p>
             <div class="i-left"></div>
             <input type="text" name="surname" class="i-bg" />
            <div class="i-right"></div><br style="clear:both" />
            </div>
             
             <div class="myaccdiv">
             <p class="delicious-heavy">Address 1:</p>
             <div class="i-left"></div>
             <input type="text" name="address1" class="i-bg" />
            <div class="i-right"></div><br style="clear:both" />
            </div>
             
             <div class="myaccdiv">
             <p class="delicious-heavy">Address 2:</p>
             <div class="i-left"></div>
             <input type="text" name="address2" class="i-bg" />
            <div class="i-right"></div><br style="clear:both" />
            </div>
             
             <div class="myaccdiv">
             <p class="delicious-heavy">Postcode:</p>
             <div class="i-left"></div>
             <input type="text" name="postcode" class="i-bg" />
             <div class="i-right"></div><br style="clear:both" />
             </div>
             
             <input type="hidden" name="country" value="<?php echo iptoc($ip); ?>" />
             
             
            <div class="myaccdiv">
             <p class="delicious-heavy"><img src="contact/php_captcha.php"></p>
             <div class="i-left"></div>
             <input name="captcha" type="text" class="i-bg" id="number" />
            <div class="i-right"></div><br style="clear:both" />
            </div>
             
             <div class="delicious-heavy" style="width:500px">
             <input type="checkbox" name="agree" value="Yes" />
             I have read, understood and 
             agree to the <a href="terms.php">Terms &amp; Conditions.</a>
             </div>
             
             <br/>
             <input type="hidden" name="referal" value="<?php echo $_SESSION['refer']; ?>" />
             <input type="submit" name="submit" value="" class="register-acc" />
          </form>
          
          
         
    </div>


    <?php 
    if (!empty($gifts)) { echo '<div style="width:300px;float:left;">
          <h2 class="delicious-heavy" style="text-decoration:underline;padding-bottom:5px">Chosen Gift</h2>'
    ;
          
          
          
          
          
          
        echo 
    '<div id="tooltip">';
        
    $result mysql_query("SELECT * from gifts WHERE id = $gifts");    
        while(
    $list mysql_fetch_array$result )){
            
            echo 
    '<div>
            
            <script type=\'text/javascript\'>
    function createDemos() {
        //<![CDATA[
        new Tip(
            \'prototip'
    .$list['id'].'\', 
            \'<span class="delicious-heavy" style="font-size:1.2em;">'
    .$list['description'].'</span><br /><br /><span class="delicious-heavy" style="font-size:1.2em;float:right;color:#c0c0c0">('.$list['referrals'].' points needed)</span>\',
            
            {title: \'<span class="delicious-heavy" style="font-size:1.8em;color:#fff">'
    .$list['title'].'</span>\',
            style: \'protogrey\',
            closeButton: true,
        hideOthers: true,
            hideOn: { element: \'closeButton\', event: \'click\' },
            hook: { target: \'middleTop\', tip: \'bottomMiddle\' },
            offset: { x: 90, y: -120 },
            stem: \'bottomMiddle\'}
        );
        //]]>
    }
    document.observe(\'dom:loaded\', createDemos);
    </script>
            
            
            
            
            <div class="hpslide" style="position:relative;left:40px;text-align:left;">
            <a href="register.php?gifts='
    .$list['id'].'" class="btn-slide" id="prototip'.$list['id'].'" rel="show[prototip]">
            <img style="z-index: 32; left: 8px; position: relative;" alt="" src="/admin/images/gifts/'
    .$list['image'].'">
        </a>
        </div>
     
    </div>'
    ;
            
        }
        echo 
    '</div>';

          
          
          
          
          
          
          echo 
    '</div>';
    }
    else { echo 
    '' ;} ?>



    <?php
          
    }
    include(
    "template/footer.php");
    ?>
    Can someone help me to fix this? I really don't know how to do it.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Presumably that would be this one here: mysql_query("INSERT INTO users VALUES(NULL, '$username', '$email', '$password', '$forename', '$surname', '$status', '0', '0', '0', '0', '$address1', '$address2', '$postcode', '$country', '$gifts', '$gtitle', '$greff', '$refer', '0', '$agree', '$ip', '0', '0')") or die(mysql_error());

    Can't really help on this though since we haven't a clue what the users table schema is. All this error tells us is that you do not have 24 properties within the users table. A simple query of DESC users; will return a list of the properties within the users table.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Another way to fix it is to list the field names you are inserting into:
    Code:
    $sql = "INSERT INTO users "
         . " ( username, email, password, forename, surname, status ) "
         . " VALUES(  '$username', '$email', '$password', '$forename', '$surname', '$status' )";
    I only showed a few of the fields and even then I am *guessing* that the DB field names match your PHP variable names.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    May 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you for you who has replied to this post. But I still can not find a solution. I'm still very new at this.

    Here's my users table schema
    Attached Thumbnails Attached Thumbnails Column count doesn't match value count at row 1-users.jpg  

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    One more time: List the fields from the DB table, by name, between parentheses ( ), and *THEN* list the VALUES, again in parentheses, in the same order.

    I *GAVE* you the answer already!!!
    Code:
    $sql = "INSERT INTO users "
         . " ( username, email, password, forename, surname, status, ...other field names... ) "
         . " VALUES(  '$username', '$email', '$password', '$forename', '$surname', '$status', ...other values... )";
    But I think your table design is very bad. *SURELY* the field points should be a NUMBER. You have it as VARCHAR(50), a *STRING*!!!

    And, judging from the SQL code in your first post, MANY MANY others of those fields in that table should be numbers. Almost surely INT.

    If you persist in using the wrong datatype for your fields, you *WILL* have problems in the future, I guarantee it!

    Before you go any further, fix your table design. Change all the fields that will hold only integer numbers to INT. If there are any fields that need to hold numbers with decimal points, then tell us what kinds of numbers they are and we can recommend a datatype.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    XiangLong (05-09-2013)

  • #6
    New to the CF scene
    Join Date
    May 2013
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you. It solved now. I don't know how to edit my to post to mark it as solved because there is no Edit Post button.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •