Jump to content

how to add usernames to mysql in a seperate row?


CBaZ

Recommended Posts

also this seems to add the same usernames continously any way to make it check for existing and skip?

<?php

error_reporting(E_ALL);

$connect = mysql_connect("localhost", "username", "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("users_online2.txt");

$date = date("YmdHis");

echo " ".$triv."";

if (mysql_num_rows($query) > 0) {

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

echo '

</div>

<div class="title" id="top_bar_right"><a href="profile2.php?user_id=$sql" target="RSIFrame">'.$triv.'</a></div>

</div>

';

 

?>

Will this work:

 

<?php
error_reporting(E_ALL);
$connect = mysql_connect("localhost", "username", "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("users_online2.txt");
$date = date("YmdHis");
echo $triv;
if (mysql_num_rows($query) <= 0) {
$result = "INSERT INTO `users` (`username`,`created`) values ('$triv', '$date')";
} else if(mysql_num_rows($query) >= 1) {
echo "number of rows: '".mysql_num_rows($query,"'";
}
$row2 = mysql_query($result) or die("QUERY FAILED: " . mysql_error());
$sql = mysql_query("SELECT * FROM `users` WHERE `user_id`='$user_id' ORDER BY `created`");
echo '</div><div class="title" id="top_bar_right"><a href="profile2.php?user_id='.$sql['user_id'].'" target="RSIFrame">'.$triv.'[/url]</div></div>';
?>

echo "number of rows: '".mysql_num_rows($query,"'");

i noticed this line was missing a ) so i put it now i get following error

number of rows query failed you have in error in your SQL syntax, check the manual that corresponds to your MYSQL version for the right syntax to use near 'resource ID # 7 at line 1

<?php

echo mysql_error();

$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("users_online2.txt");

$date = date("YmdHis");

echo $triv;

if (mysql_num_rows($query) <= 0) {

$result = "INSERT INTO users (username,created) values ('$triv', '$date')";

} else if (mysql_num_rows($query) >= 1) {

echo "number of rows: '".mysql_num_rows($query);          //it's working up to this point

}

$row2 = mysql_query($result) or die("QUERY FAILED: " . mysql_error());

$sql = mysql_query("SELECT * FROM users WHERE user_id ='$user_id' ORDER BY created");

echo '</div><div class="title" id="top_bar_right"><a href="profile2.php?user_id='.$sql['user_id'].'" target="RSIFrame">'.$triv.'[/url]</div></div>';

?>

ok it runs this way but it does not add to the database and i am not sure if it will put each line from txt into a seperate line of my mysql.  also the user_id does not come up not sure as to why.

 

<?php

echo mysql_error();

$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("users_online2.txt");

$date = date("YmdHis");

echo $triv;

if (mysql_num_rows($query) <= 0) {

$result = "INSERT INTO users (username,created) VALUES ('$triv', '$date')";

        $row2 = mysql_query($result);

} else if (mysql_num_rows($query) >= 1) {

echo "number of rows: '".mysql_num_rows($query);

}

$sql = mysql_query("SELECT user_id FROM users WHERE user_id = '$user_id' ORDER BY created");

echo '</div><div class="title" id="top_bar_right"><a href="profile2.php?user_id='.$sql['user_id'].'" target="RSIFrame2">'.$triv.'[/url]</div></div>';

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.