Warning: fgets(): supplied argument is not a valid stream resource in â¦.\test\upload_star_data.php on line 12
You are creating a string in the $filehandle variable, but opening the file with the $fp variable (which is the resource indicator -- or the handle). You must supply the resource indicator to fgets.
Have a look at this example:
http://www.php.net/fgets
Warning: mssql_query(): message: The name 'ra' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted. (severity 15) in â¦.\test\upload_star_data.php on line 18
Warning: mssql_query(): Query failed in â¦\test\upload_star_data.php on line 18
sql error
For an INSERT query you don't have to specify the column names in the VALUES portion of the SQL. You'd do that for an UPDATE query, but an UPDATE query is set-up slightly differently. Each inserted value must correspond directly to the number of columns in the database. So if you have 4 fields in your database, you should be inserting 4 values.
Here is your code with corrections..
Code:
<?php
// *.txt is a tab deliminated file
$fp = fopen("uma_stars.txt", "r");
//Open database
include ('./db.php');
while(!feof($fp))
{
$line = fgets($fp, 4096);
$ra = substr($line,0,11);
$dec = substr($line,12,8);
$catalog_num = substr($line,21,11);
$constellation = substr($line,37,3);
mssql_query("INSERT INTO TEST values('$ra', '$dec', '$catalog_num', '$constellation')")
or die(mysql_error());
}
mssql_close($db);
fclose($fp);
?>
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::