grazzman Posted December 25, 2006 Share Posted December 25, 2006 So, below is the script I'm trying to use to import a CSV data. the clsuser.php contains my mysql connection information an is working on all my other pages, so im sure its not in their. When I run the script the "mysql_query($sql, $mysql_conn);" in the middle is not working. It keeps showing the error message that I put in their and none of the information is added to the database. If anyone can help and can see what little thing is causing this, it would be a big help. Thanks[code]<?phprequire_once "clsuser.php";$a=new Auth($mysql_conn);$csvfile="pm.csv";$csv=file($csvfile);foreach($csv as $csvline){ $csvdat=QuoteExplode($csvline); $userinfo=array(); $userinfo['Username']=$csvdat[0]; $userinfo['Password']=$csvdat[2]; $userinfo['Email']=$csvdat[10]; $userinfo['FirstName']=$csvdat[8]; $userinfo['Location']=$csvdat[11]; $userinfo['SignupTime']=date("Y-m-d H:i:s", strtotime($csvdat[4])); $userinfo['LastLogin']=date("Y-m-d H:i:s", strtotime($csvdat[3])); $userinfo['RegistrationIP']=ip2long($csvdat[5]); $userinfo['LastName']=$csvdat[9]; $userinfo['BirthDay']=$csvdat[12]; $userinfo['BirthMonth']=$csvdat[13]; $userinfo['BirthYear']=$csvdat[14]; $userinfo['Gender']=$csvdat[15]; $userinfo['Xfire']=$csvdat[16]; $userinfo['GameName']=$csvdat[18]; $userinfo['Recruiter']=$csvdat[20]; $userinfo['LastClan']=$csvdat[21]; $userinfo['Connection']=$csvdat[23]; $userinfo['PCType']=$csvdat[24]; $userinfo['Status']=$csvdat[34]; $userinfo['ForumsID']=$csvdat[35]; $userinfo['Rank']=$csvdat[31]; $userinfo['RankType']=$csvdat[32]; $userinfo['RegTeam']=$csvdat[27]; $userinfo['RegTitle']=$csvdat[30]; $userinfo['CICTeam']=$csvdat[38]; $userinfo['CICTitle']=$csvdat[39]; $userinfo['MPTeam']=$csvdat[26]; $userinfo['MPTitle']=$csvdat[29]; $userinfo['SFTeam']=$csvdat[40]; $userinfo['SFTitle']=$csvdat[41]; $userinfo['CTeam']=$csvdat[25]; $userinfo['CTitle']=$csvdat[28]; $userinfo['AUTHSKEY']=$a->sKeyGenerate($userinfo['Username']); $dbtime=date(DBdateformat); //var_dump($userinfo); //continue; $sql="INSERT INTO User SET Username='" . $userinfo['Username'] . "', Password='" . $userinfo['Password'] . "', Email='" . $userinfo['Email'] . "', FirstName='" . $userinfo['FirstName'] . "', Location='" . $userinfo['Location'] . "', EmailVerified=1, AUTHSKEY='" . $userinfo['AUTHSKEY'] . "', SignupTime='" . $userinfo['SignupTime'] . "', LastLogin='" . $userinfo['LastLogin'] . "', LastName='" . $userinfo['LastName'] . "', BirthDay='" . $userinfo['BirthDay'] . "', BirthMonth='" . $userinfo['BirthMonth'] . "', BirthYear='" . $userinfo['BirthYear'] . "', Gender='" . $userinfo['Gender'] . "', Xfire='" . $userinfo['XFire'] . "', GameName='" . $userinfo['GameName'] . "', Recruiter='" . $userinfo['Recruiter'] . "', LastClan='" . $userinfo['LastClan'] . "', Connection='" . $userinfo['Connection'] . "', PCType='" . $userinfo['PCType'] . "', Status='" . $userinfo['Status'] . "', ForumsID='" . $userinfo['ForumsID'] . "', Rank='" . $userinfo['Rank'] . "', RankType='" . $userinfo['RankType'] . "', RegTeam='" . $userinfo['RegTeam'] . "', RegTitle='" . $userinfo['RegTitle'] . "', CICTeam='" . $userinfo['CICTeam'] . "', CICTitle='" . $userinfo['CICTitle'] . "', MPTeam='" . $userinfo['MPTeam'] . "', MPTitle='" . $userinfo['MPTitle'] . "', SFTeam='" . $userinfo['SFTeam'] . "', SFTitle='" . $userinfo['SFTitle'] . "', CTeam='" . $userinfo['CTeam'] . "', CTitle='" . $userinfo['CTitle'] . "', RegistrationIP=" . $userinfo['RegistrationIP'] . ";"; $qres=mysql_query($sql, $mysql_conn); if (!$qres) echo 'Error inserting user with username '.$userinfo['Username'].'<br />'; else echo 'Inserted user with username '.$userinfo['Username'].'<br />';}function QuoteExplode($str){ $c=0; $ret=array(); $str="," . trim($str); while($c<strlen($str)){ $so=strpos($str, ",", $c); if ($so===false){ $ret[]=substr($str, $c); return $ret; } $qo=strpos($str, "\"", $c); if ($so<$qo && $so!==false){ } if ($qo!==false && $qo<$so+2){ // Next it is a quote mark $eqo=strpos($str, "\"", $qo+1); if ($eqo===false){ $ret[]=substr($str, $qo+1); return $ret; } $ret[]=substr($str, $qo+1, $eqo-$qo-1); $c=$eqo+1; } else{ $eso=strpos($str, ",", $so+1); if ($eso===false){ $ret[]=substr($str, $so+1); return $ret; } $ret[]=substr($str, $so+1, $eso-$so-1); $c=$eso; } } return $ret;}?>[/code] Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted December 26, 2006 Share Posted December 26, 2006 I think the last line of your query ($sql) needs to be like this:[code]RegistrationIP='" . $userinfo['RegistrationIP'] . "'";[/code] 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.