homer.favenir Posted July 29, 2008 Share Posted July 29, 2008 hi, can anyone please kindly check my script. it has an error "Column count doesn't match value count at row 1" <pre> <?php include('lib/functions.php'); include ('lib/connect.php'); $file = file('accma-raw.txt'); $count = 1; $x = 1; foreach($file as $str) { $name = ucfirst(substr($str, 4, 39)); $code1 = trim(substr($str,45, 3)); $code2 = trim(substr($str,49, 3)); $code3 = trim(substr($str,53, 3)); $code4 = trim(substr($str,57, 3)); $code5 = trim(substr($str,61, 3)); $code6 = trim(substr($str,65, 3)); $univ = trim(substr($str,68, 69)); $lic = trim(substr($str,139, 9)); $byr = trim(substr($str,149, 4)); $grp = trim(substr($str,154, 73)); //level2 $fax = trim(substr($str,0, 15)); $add = trim(substr($str,16, 40)); $city = trim(substr($str,57, 20)); $zc= trim(substr($str,78, 10)); $ph= trim(substr($str,89, 12)); $email= trim(substr($str,103, 123)); $level = substr($str, 215, 20); if($level == 1) { $field = array("idnum" , "name", "code1" , "code2" , "code3" , "code4" , "code5" , "code6" , "univ" , "lic" , "byr" , "grp"); $lvl1 = array($x,$name,$code1,$code2,$code3,$code4,$code5,$code6,$univ,$lic,$byr,$grp); for( $i = 0; $i <= 11; $i++) { $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($lvl1[$i]))); $str = title_upcase($text); $sql = "INSERT INTO level1 ($field[$i]) VALUES ($str)"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; echo $str; } echo "<br>"; } $x++; } ?> thanks for help ??? Link to comment https://forums.phpfreaks.com/topic/117116-column-count-doesnt-match-value-count-at-row-1/ Share on other sites More sharing options...
trq Posted July 29, 2008 Share Posted July 29, 2008 echo the $sql variable prior to calling mysql_query() so you can see exactly what is being sent to mysql. Link to comment https://forums.phpfreaks.com/topic/117116-column-count-doesnt-match-value-count-at-row-1/#findComment-602401 Share on other sites More sharing options...
homer.favenir Posted July 29, 2008 Author Share Posted July 29, 2008 INSERT INTO level1 (idnum) VALUES (1)1 record added1INSERT INTO level1 (name) VALUES (Abarquez-Agcaoili, Carmencita ) Link to comment https://forums.phpfreaks.com/topic/117116-column-count-doesnt-match-value-count-at-row-1/#findComment-602407 Share on other sites More sharing options...
scottybwoy Posted July 29, 2008 Share Posted July 29, 2008 You can rewrite your SQL statement to do it in one go : INSERT INTO level1 ('idnum', 'name') VALUES (1, 'Abarquez-Agcaoili, Carmencita') Link to comment https://forums.phpfreaks.com/topic/117116-column-count-doesnt-match-value-count-at-row-1/#findComment-602481 Share on other sites More sharing options...
homer.favenir Posted July 29, 2008 Author Share Posted July 29, 2008 now i know the problem,the query only insert 1 column per loop bcause it is an array. and my script is $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($x))); $x = title_upcase($text); $x = mysql_real_escape_string($x); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($name))); $name = title_upcase($text); $name = mysql_real_escape_string($name); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($code1))); $code1 = title_upcase($text); $code1 = mysql_real_escape_string($code1); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($code2))); $code2 = title_upcase($text); $code2 = mysql_real_escape_string($code2); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($code3))); $code3 = title_upcase($text); $code3 = mysql_real_escape_string($code3); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($code4))); $code4 = title_upcase($text); $code4 = mysql_real_escape_string($code4); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($code5))); $code5 = title_upcase($text); $code5 = mysql_real_escape_string($code5); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($code6))); $code6 = title_upcase($text); $code6 = mysql_real_escape_string($code6); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($univ))); $univ = title_upcase($text); $univ = mysql_real_escape_string($univ); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($lic))); $lic = title_upcase($text); $lic = mysql_real_escape_string($lic); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($byr))); $byr = title_upcase($text); $byr = mysql_real_escape_string($byr); $text = preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($grp))); $grp = title_upcase($text); $grp = mysql_real_escape_string($grp); echo $sql = "INSERT INTO level1 (idnum, name,code1,code2,code3,code4,code5,code6,univ,lic,byr,grp) VALUES ('$x','$name','$code1','$code2','$code3','$code4','$code5','$code6','$univ','$lic','$byr','$grp')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; now, my problem is simplificaiton....?...whewwww thanks guys Link to comment https://forums.phpfreaks.com/topic/117116-column-count-doesnt-match-value-count-at-row-1/#findComment-602519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.