slim_jimmy7 Posted March 4, 2010 Share Posted March 4, 2010 so I do run this php and I am not getting it to go into mysql. I think it has something to do with the regex statement, but I am not sure (maybe it is overkill). Thanks in advance for your help. // tab delimited file $file = "standings.txt"; // open file $handle = fopen($file, "rb"); $contents = fread($handle, filesize($file)); // close file fclose($handle); $data = preg_split('/[,? ]+/',$contents); $eventname = $data[3]; $finishposition = $data[21]; $drivernumber = $data[23]; $drivername = $data[24]; $laps = $data[25]; $lapsled = $data[26]; $points = $data[27]; $qualposition = $data[22]; $qualtime = $data[28]; $reasonout = $data[29]; $the_query = "INSERT INTO `s1racestats` (`eventname`, `series`, `firstplace`, `finishposition`, `top10`, `top5`, `drivernumber`, `drivername`, `laps`, `lapsled`, `points`, `qual1stplace`, `qualposition`, `qualtime`, `reasonout`, `prov`, `didnotstart`, `year`) VALUES ('$eventname', '$series', PSRLpts, $finishposition, 1, 1, $drivernumber, '$drivername', $laps, $lapsled, $points, 1, $qualposition, $qualtime, '$reasonout', 0, 0, 2010)"; mysql_query($the_query, $connection_details); ?> Quote Link to comment Share on other sites More sharing options...
inspireddesign Posted March 4, 2010 Share Posted March 4, 2010 Try seeing what the error might be: $the_query = "INSERT INTO `s1racestats` (`eventname`, `series`, `firstplace`, `finishposition`, `top10`, `top5`,`drivernumber`, `drivername`, `laps`, `lapsled`, `points`, `qual1stplace`, `qualposition`, `qualtime`, `reasonout`, `prov`, `didnotstart`, `year`) VALUES ('$eventname', '$series', PSRLpts, $finishposition, 1, 1, $drivernumber, '$drivername', $laps, $lapsled, $points, 1, $qualposition, $qualtime, '$reasonout', 0, 0, 2010)"; mysql_query($the_query, $connection_details) or die ('Error in result: '. mysql_error()); Quote Link to comment Share on other sites More sharing options...
slim_jimmy7 Posted March 5, 2010 Author Share Posted March 5, 2010 I am getting an error that says: Error in result: Unknown column 'Running' in 'field list' which is the value for data[29]. I have the field in mysql set to varchar(20). I must be missing some quotations or something? Quote Link to comment Share on other sites More sharing options...
inspireddesign Posted March 5, 2010 Share Posted March 5, 2010 Most likely. Try this and see if you get the same result. $the_query = "INSERT INTO s1racestats ('eventname', 'series', 'firstplace', 'finishposition', 'top10', 'top5','drivernumber', 'drivername', 'laps', 'lapsled', 'points', 'qual1stplace', 'qualposition', 'qualtime', 'reasonout', 'prov', 'didnotstart', 'year') VALUES ('$eventname', '$series', PSRLpts, '$finishposition', 1, 1, '$drivernumber', '$drivername', '$laps', '$lapsled', '$points', 1, '$qualposition', '$qualtime', '$reasonout', 0, 0, 2010)"; Quote Link to comment Share on other sites More sharing options...
slim_jimmy7 Posted March 5, 2010 Author Share Posted March 5, 2010 This is the error I get with putting that in: Error in result: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''s1racestats' ('eventname', 'series', 'firstplace', 'finishposition', 'top10', '' at line 1 Quote Link to comment Share on other sites More sharing options...
inspireddesign Posted March 5, 2010 Share Posted March 5, 2010 Try this... It may or may not work but let's see what error it gives us (if any). $the_query = sprintf("INSERT INTO s1racestats ( eventname, series, firstplace, finishposition, top10, top5, drivernumber, drivername, laps, lapsled, points, qual1stplace, qualposition, qualtime, reasonout, prov, didnotstart, year ) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )", $eventname, $series, PSRLpts, $finishposition, '1', '1', $drivernumber, $drivername, $laps, $lapsled, $points, '1', $qualposition, $qualtime, $reasonout, '0', '0', '2010' ); Quote Link to comment Share on other sites More sharing options...
slim_jimmy7 Posted March 5, 2010 Author Share Posted March 5, 2010 This is the error I get with that one: Error in result: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''eventname', 'series', 'firstplace', 'finishposition', 'top10', 'top5','drivernu' at line 1 'drivernu' is not anywhere in the document... Quote Link to comment Share on other sites More sharing options...
inspireddesign Posted March 5, 2010 Share Posted March 5, 2010 the error it returns only give you a portion of the error where the problem might be in the query. drivernu is -> drivernum Anyway, try this: $the_query = sprintf("INSERT INTO s1racestats ( eventname, series, firstplace, finishposition, top10, top5, drivernumber, drivername, laps, lapsled, points, qual1stplace, qualposition, qualtime, reasonout, prov, didnotstart, year ) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )", $eventname, $series, PSRLpts, $finishposition, '1', '1', $drivernumber, $drivername, $laps, $lapsled, $points, '1', $qualposition, $qualtime, $reasonout, '0', '0', '2010' ); Quote Link to comment Share on other sites More sharing options...
slim_jimmy7 Posted March 5, 2010 Author Share Posted March 5, 2010 This is what I get with that: Error in result: Unknown column 'Carolina' in 'field list' I guess I should also show you what the txt file looks like: Race Final North Carolina Speedway 1.017 miles 137 laps -------------------------------------------------------------------------------- Fin Str Driver Laps Led Pts Qual Reason Out -------------------------------------------------------------------------------- 1 1 38 !ECR!Mate 137 81 185 147.018 Running 2 2 50 Gabby 137 35 175 146.009 Running 3 3 133 Spoiler33 137 9 170 145.998 Running 4 5 83 fisch83 137 0 160 145.262 Running 5 11 15 SKOALMAN 137 7 160 143.514 Running 6 4 104 !Rude! 136 3 155 145.303 Running 7 8 106 (WCR)JDM106 136 0 146 144.426 Running 8 12 77 slim 135 0 142 143.508 Running 9 7 45 Ozzie 135 2 143 144.883 Running 10 14 108 Speedball57 135 0 134 Running 11 6 101 jimbob4 133 0 130 145.055 Running 12 9 51 A_Parks 59 0 127 144.164 DNF 13 10 61 !ECR!B1Racer 27 0 124 143.841 DNF 14 13 76 PSRL 0 0 121 Running Race time - 57:27.389 Average speed - 145.499mph Margin of victory - 3.374sec Caution flags - 0 # of lead changes - 7 Weather - Clear 53^ N 10mph Quote Link to comment Share on other sites More sharing options...
inspireddesign Posted March 5, 2010 Share Posted March 5, 2010 Try this: If this doesn't help ask the guys over in the phpfreak MySQL forum. $the_query = sprintf("INSERT INTO s1racestats ( eventname, series, firstplace, finishposition, top10, top5, drivernumber, drivername, laps, lapsled, points, qual1stplace, qualposition, qualtime, reasonout, prov, didnotstart, year ) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )", "$eventname", "$series", "PSRLpts", "$finishposition", "1", "1", "$drivernumber", "$drivername", "$laps", "$lapsled", "$points", "1", "$qualposition", "$qualtime", "$reasonout", "0", "0", "2010" ); Quote Link to comment Share on other sites More sharing options...
slim_jimmy7 Posted March 5, 2010 Author Share Posted March 5, 2010 Thank you for your help, unfortunately that didn't work. Have reposted over here at the mysql guys forum to see what they think: http://www.phpfreaks.com/forums/index.php/topic,290103.0.html Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 5, 2010 Share Posted March 5, 2010 Just randomly trying different syntax is not how you program. Your current problem is that string data in the SQL query statement must be enclosed in single quotes, in the query statement. 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.