Error creating new Table!!!
"); exit(); } //Insert the first record $j = 0; $recordnum = $numoflines; $column = "column"; $column = $column."0"; $firstrecord = $newlinearray[0]; //Remove the unwanted double quotes $firstrecord = eregi_replace("\"","",$firstrecord); //Remove the unwanted single quotes (if you want single quotes, just add slashes before doing the insert) $firstrecord = eregi_replace("'","",$firstrecord); //Insert the first record $sql = "INSERT INTO $servertable ($column, RowNumber) values ('$firstrecord','$recordnum')"; $sqlGo = @mssql_query($sql); if(!$sqlGo){ echo("Data could not be inserted from the file!!! - Try again!!!
"); exit(); } $column = "column";//prepare to update each column of the newly inserted row while($j != $holdi){ $column = $column.$j; $rowdata = trim($newlinearray[$j]); //$rowdata = rtrim($newlinearray[$j]); //Same principle as above $rowdata = eregi_replace("\"","",$rowdata); $rowdata = eregi_replace("'","",$rowdata); //Update each row, one at a time //Notice that ID will always correspond to the correct $recordnum $sql = "UPDATE $servertable SET $column='$rowdata' WHERE ID=$recordnum"; //Check to make sure the updates are successful if(@mssql_query($sql)){ $ok = 1; }else{ $ok = 0; } $column = "column";//reset $column $j++;//go to the next column } }else{//numoflines != 1, thus all records after the first one can now be inserted $column = "column";//set $column to prepare for inserts $recordnum = $numoflines;//set $recordnum appropriately $j = 0; $column = $column."0";//set first column $firstrecord = $newlinearray[0];//grab data for first column //Remove the unwanted double quotes $firstrecord = eregi_replace("\"","",$firstrecord); //Remove the unwanted single quotes $firstrecord = eregi_replace("'","",$firstrecord); //INSERT the new record $sql = "INSERT INTO $servertable ($column, RowNumber) values ('$firstrecord','$recordnum')"; $sqlGo = @mssql_query($sql); if(!$sqlGo){ echo("Data could not be inserted from the file!!! - Try again!!!
"); exit(); } $column = "column"; while($j != $i){ $column = $column.$j; $rowdata = rtrim($newlinearray[$j]); //Remove unwanted double quotes $rowdata = eregi_replace("\"","",$rowdata); //Remove unwanted single quotes $rowdata = eregi_replace("'","",$rowdata); //UPDATE each column place of the new record $sql = "UPDATE $servertable SET $column='$rowdata' WHERE ID=$recordnum"; //Check to make sure the updates are successful if(@mssql_query($sql)){ $ok = 1; }else{ $ok = 0; } $column = "column";//reset $column $j++;//move to the next column } } } } //Check if indeed everything was fine if($ok == 1){ echo("Data inserted correctly!!!
"); }else{ echo("Data could not be inserted from the file!!! - Try again!!!
"); } ?>