SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: Why is this

  1. #1
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Why is this

    Hello i got a register script it works fine but in phpmyadmin when i add another field in phpmyadmin then register without changing any files i get an error saying Could not insert data because Column count doesn't match value count at row 1


    why is this?

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Post your code, it is probably to do with the muber of fields you have in the table not matching the number of variables you are inserting.

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my register code:


    <?php
    include("config.php");

    // connect to the mysql server
    $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());

    // check if the username is taken
    $check = "select id from $table where username = '".$_POST['username']."';";
    $qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
    $num_rows = mysql_num_rows($qry);
    if ($num_rows != 0) {
    echo "Sorry, there the username $username is already taken.<br>";
    echo "<a href=register.html>Try again</a>";

    exit;

    } else {

    // insert the data
    $insert = mysql_query("insert into $table values ('".$_POST['username']."', '','".$_POST['password']."','','','','','','', '', '', '', '', '')")
    or die("Could not insert data because ".mysql_error());


    // print a success message
    echo "Your user account has been created!<br>";
    echo "Please <a href=activate.html>Click Here To Continue</a>";
    }

    }

    ?>

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Tidal Wave
    Hello i got a register script it works fine but in phpmyadmin when i add another field in phpmyadmin then register without changing any files i get an error saying Could not insert data because Column count doesn't match value count at row 1


    why is this?
    What do you mean by 'i add another field in phpmyadmin'? Did you add a new field to the table? And did you not change your script?

    The error tells you that the number of fields in your 'insert' statement and the number of fields in the table are not the same. So if you did add a new field to the table, you'll have to add it to your 'insert' statement as well.

  5. #5
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i mean i added new fields to the table and i didnt edit my script

  6. #6
    orange pips! orange pips!
    Join Date
    Oct 2001
    Location
    Its all about location
    Posts
    652
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your insert query is inserting 14 values. If you added a new column in phpmyadmin, then it needs to insert 15 values.

  7. #7
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got that ok thank you

  8. #8
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah where would i change 14 to 15?

  9. #9
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Tidal Wave
    ah where would i change 14 to 15?
    In your insert-statement. If you added the new field at the end of the table, and if the field is alfanumeric, the insert statement might become something like this:

    PHP Code:
    $insert mysql_query("insert into $table values ('".$_POST['username']."', '','".$_POST['password']."','','','','','','', '', '', '', '', '', '')"

  10. #10
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so what did you add there :s

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    another '', to the fields...
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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