inserting usernames from a .txt into mysql
Posted: Wed Jul 02, 2008 3:00 pm
I am not sure how to create the loop so that it adds each username in a seperate row. in the text file it stores usernames as such
user1
user2
this is coming from an IRC bot therefore I need to use the .txt file
user1
user2
this is coming from an IRC bot therefore I need to use the .txt file
Code: Select all
<?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?>
<?php
error_reporting(E_ALL);
$connect = mysql_connect("localhost", "user", "pw") or die ("Could not connect to database: " . mysql_error()); mysql_select_db("db", $connect) or die ("Could not select database");
$query = mysql_query("SELECT * FROM users WHERE username != '" . $username . "'") or die("QUERY FAILED: " . mysql_error());
$triv = file_get_contents("trivia/users_online2.txt");
$date = date("YmdHis");
echo " ".$triv."";
if (mysql_num_rows($query) >= 0) {
for($i=0;$i<count($triv);$i++) {
$result = "INSERT INTO users (username, created) values ('".$triv."', '".$date."')" ;
}} else {
echo "number of rows: '".mysql_num_rows($query)."'<br>";
exit;
}
$row2 = mysql_query($result) or die("QUERY FAILED: " . mysql_error());
$sql = mysql_query("SELECT * FROM users WHERE user_id != '$user_id' ORDER BY created");
?>