Lamez Posted January 30, 2008 Share Posted January 30, 2008 When I run my PHP script I get this error: Column count doesn't match value count at row 1 INSERT INTO `1` VALUES ('1', 'ReagionName', '77', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '99', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'TeamNeame', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '') what does it mean? How do I fix it? Quote Link to comment Share on other sites More sharing options...
valtido Posted January 30, 2008 Share Posted January 30, 2008 you have said insert bla bla bla but u havent specified where you want to save it to. In the database Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted January 30, 2008 Share Posted January 30, 2008 Look at this article: http://htmlfixit.com/cgi-tutes/tutorial_MySQL_Error_Invalid_Query_Column_Count_Does_Not_Match_Value_Count.php Quote Link to comment Share on other sites More sharing options...
Lamez Posted January 30, 2008 Author Share Posted January 30, 2008 yes I did, I made a function: function add($id, $region, $w1a, $w2a, $w3a, $w4a, $w5a, $w6a, $w7a, $w8a, $w9a, $w10a, $w11a, $w12a, $w13a, $w14a, $w15a, $w16a, $l1a, $l2a, $l3a, $l4a, $l5a, $l6a, $l7a, $l8a, $l9a, $l10a, $l11a, $l12a, $l13a, $l14a, $l15a, $l16a, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12, $a13, $a14, $a15, $a16){ $q = "INSERT INTO `1` VALUES ('$id', '$region', '$w1a', '$w2a', '$w3a', '$w4a', '$w5a', '$w5a', '$w6a', '$w7a', '$w8a', '$w9a', '$w10a', '$w11a', '$w12a', '$w13a', '$w14a', '$w15a', '$w16a', '$l1a', '$l2a', '$l3a', '$l4a', '$l5a', '$l6a', '$l7a', '$l8a', '$l9a', '$l10a', '$l11a', '$l12a', '$l13a', '$l14a', '$l15a', '$l16a', '$a1', '$a2', '$a3', '$a4', '$a5', '$a6', '$a7', '$a8', '$a9', '$a10', '$a11', '$a12', '$a13', '$a14', '$a15', '$a16')"; if ($result = mysql_query($q)) { return $result; } else { die(mysql_error() . "<br />" . $q); } } and it calls in here: $q = "Select count(*) as row_count from `1` where id=1"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $query = "DELETE FROM `1` WHERE id = 1"; $result = mysql_query($query); add($id, $region, $w1a, $w2a, $w3a, $w4a, $w5a, $w6a, $w7a, $w8a, $w9a, $w10a, $w11a, $w12a, $w13a, $w14a, $w15a, $w16a, $l1a, $l2a, $l3a, $l4a, $l5a, $l6a, $l7a, $l8a, $l9a, $l10a, $l11a, $l12a, $l13a, $l14a, $l15a, $l16a, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12, $a13, $a14, $a15, $a16); } else{ add($id, $region, $id, $w1a, $w2a, $w3a, $w4a, $w5a, $w6a, $w7a, $w8a, $w9a, $w10a, $w11a, $w12a, $w13a, $w14a, $w15a, $w16a, $l1a, $l2a, $l3a, $l4a, $l5a, $l6a, $l7a, $l8a, $l9a, $l10a, $l11a, $l12a, $l13a, $l14a, $l15a, $l16a, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12, $a13, $a14, $a15, $a16); } where did I go wrong? The table name is 1 Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted January 30, 2008 Share Posted January 30, 2008 Check your table 1, whether there are 51 columns are there or not. coz in your insert query there are 51 values are specified. Quote Link to comment Share on other sites More sharing options...
Lamez Posted January 30, 2008 Author Share Posted January 30, 2008 ah that is what it is, I have 50 cols in my table, and I have 51 listed here, alright I will have a look see Quote Link to comment Share on other sites More sharing options...
Lamez Posted January 30, 2008 Author Share Posted January 30, 2008 I cannot find the my mistake, maybe a pair of fresh eyes will help here is how my table is setup Table Name: 1 id region w1a - w16a (w1a, w2a, etc..) l1a - l16a (l1a, l2a, etc..) 1-16 (1, 2, etc..) <?php /*Connect, and define user*/ include ("../../style/include/session.php"); error_reporting(E_ALL); /*Define Variables*/ $region = $_POST['region1']; $id = $_POST['id1']; $w1a = $_POST['w1a']; $w2a = $_POST['w2a']; $w3a = $_POST['w3a']; $w4a = $_POST['w4a']; $w5a = $_POST['w5a']; $w6a = $_POST['w6a']; $w7a = $_POST['w7a']; $w8a = $_POST['w8a']; $w9a = $_POST['w9a']; $w10a = $_POST['w10a']; $w11a = $_POST['w11a']; $w12a = $_POST['w12a']; $w13a = $_POST['w13a']; $w14a = $_POST['w14a']; $w15a = $_POST['w15a']; $w16a = $_POST['w16a']; $l1a = $_POST['l1a']; $l2a = $_POST['l2a']; $l3a = $_POST['l3a']; $l4a = $_POST['l4a']; $l5a = $_POST['l5a']; $l6a = $_POST['l6a']; $l7a = $_POST['l7a']; $l8a = $_POST['l8a']; $l9a = $_POST['l9a']; $l10a = $_POST['l10a']; $l11a = $_POST['l11a']; $l12a = $_POST['l12a']; $l13a = $_POST['l13a']; $l14a = $_POST['l14a']; $l15a = $_POST['l15a']; $l16a = $_POST['l16a']; $a1 = $_POST['1a']; $a2 = $_POST['2a']; $a3 = $_POST['3a']; $a4 = $_POST['4a']; $a5 = $_POST['5a']; $a6 = $_POST['6a']; $a7 = $_POST['7a']; $a8 = $_POST['8a']; $a9 = $_POST['9a']; $a10 = $_POST['10a']; $a11 = $_POST['11a']; $a12 = $_POST['12a']; $a13 = $_POST['13a']; $a14 = $_POST['14a']; $a15 = $_POST['15a']; $a16 = $_POST['16a']; function add($id, $region, $w1a, $w2a, $w3a, $w4a, $w5a, $w6a, $w7a, $w8a, $w9a, $w10a, $w11a, $w12a, $w13a, $w14a, $w15a, $w16a, $l1a, $l2a, $l3a, $l4a, $l5a, $l6a, $l7a, $l8a, $l9a, $l10a, $l11a, $l12a, $l13a, $l14a, $l15a, $l16a, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12, $a13, $a14, $a15, $a16) { $q = "INSERT INTO `1` VALUES ('$id', '$region', '$w1a', '$w2a', '$w3a', '$w4a', '$w5a', '$w5a', '$w6a', '$w7a', '$w8a', '$w9a', '$w10a', '$w11a', '$w12a', '$w13a', '$w14a', '$w15a', '$w16a', '$l1a', '$l2a', '$l3a', '$l4a', '$l5a', '$l6a', '$l7a', '$l8a', '$l9a', '$l10a', '$l11a', '$l12a', '$l13a', '$l14a', '$l15a', '$l16a', '$a1', '$a2', '$a3', '$a4', '$a5', '$a6', '$a7', '$a8', '$a9', '$a10', '$a11', '$a12', '$a13', '$a14', '$a15', '$a16')"; if ($result = mysql_query($q)) { return $result; } else { die(mysql_error() . "<br />" . $q); } } $q = "Select count(*) as row_count from `1` where id=1"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ //Delete Row $query = "DELETE FROM `1` WHERE id = 1"; //Add to DB $result = mysql_query($query); add($id, $region, $w1a, $w2a, $w3a, $w4a, $w5a, $w6a, $w7a, $w8a, $w9a, $w10a, $w11a, $w12a, $w13a, $w14a, $w15a, $w16a, $l1a, $l2a, $l3a, $l4a, $l5a, $l6a, $l7a, $l8a, $l9a, $l10a, $l11a, $l12a, $l13a, $l14a, $l15a, $l16a, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12, $a13, $a14, $a15, $a16); } else{ //No rows, so add add($id, $region, $w1a, $w2a, $w3a, $w4a, $w5a, $w6a, $w7a, $w8a, $w9a, $w10a, $w11a, $w12a, $w13a, $w14a, $w15a, $w16a, $l1a, $l2a, $l3a, $l4a, $l5a, $l6a, $l7a, $l8a, $l9a, $l10a, $l11a, $l12a, $l13a, $l14a, $l15a, $l16a, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12, $a13, $a14, $a15, $a16); } ?> anyone see it? Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted January 30, 2008 Share Posted January 30, 2008 Use the query as follows <?php $q = "INSERT INTO `1` VALUES ('$id', '$region', '$w1a', '$w2a', '$w3a', '$w4a', '$w5a', '$w6a', '$w7a', '$w8a', '$w9a', '$w10a', '$w11a', '$w12a', '$w13a', '$w14a', '$w15a', '$w16a', '$l1a', '$l2a', '$l3a', '$l4a', '$l5a', '$l6a', '$l7a', '$l8a', '$l9a', '$l10a', '$l11a', '$l12a', '$l13a', '$l14a', '$l15a', '$l16a', '$a1', '$a2', '$a3', '$a4', '$a5', '$a6', '$a7', '$a8', '$a9', '$a10', '$a11', '$a12', '$a13', '$a14', '$a15', '$a16')"; ?> Cheers Quote Link to comment Share on other sites More sharing options...
Philip Posted January 30, 2008 Share Posted January 30, 2008 Yeah, you have "'...$w5a', '$w5a', '$w6a',..." Quote Link to comment Share on other sites More sharing options...
Lamez Posted January 30, 2008 Author Share Posted January 30, 2008 I still get this error Column count doesn't match value count at row 1 INSERT INTO `1` VALUES ('1', 'ReagionName', '77', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '99', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'TeamNeame', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '') Quote Link to comment Share on other sites More sharing options...
trq Posted January 30, 2008 Share Posted January 30, 2008 If your only looking to insert data into four rows, specify them. its best practice to always do this anyway. God only knows why you would have a field called 1. INSERT INTO tbl (fld1,fld2,fld3,fld4) VALUES ('val1','val2','val3','val4'); Quote Link to comment Share on other sites More sharing options...
Lamez Posted January 31, 2008 Author Share Posted January 31, 2008 lol was on the wrong page when I test this, sorry it works great Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.