Jump to content

Column count doesn't match value count at row 1


homer.favenir

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.