Jump to content

Text Reader code


slim_jimmy7

Recommended Posts

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);


?>

Link to comment
Share on other sites

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());

 

 

Link to comment
Share on other sites

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)";

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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' );

Link to comment
Share on other sites

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... :confused:

Link to comment
Share on other sites

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' );

Link to comment
Share on other sites

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



Link to comment
Share on other sites

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" );

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.