CBaZ Posted June 30, 2008 Share Posted June 30, 2008 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> '; ?> Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/ Share on other sites More sharing options...
ShimmyShine Posted June 30, 2008 Share Posted June 30, 2008 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577740 Share on other sites More sharing options...
CBaZ Posted June 30, 2008 Author Share Posted June 30, 2008 nope didn't work at all Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577751 Share on other sites More sharing options...
ShimmyShine Posted June 30, 2008 Share Posted June 30, 2008 replace error_reporting(E_ALL) with echo mysql_error(); see if its a mysql error. Shimmy Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577767 Share on other sites More sharing options...
CBaZ Posted June 30, 2008 Author Share Posted June 30, 2008 it didn't specify any errors at all Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577836 Share on other sites More sharing options...
CBaZ Posted June 30, 2008 Author Share Posted June 30, 2008 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 Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577840 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 change this line: <?php echo "number of rows: '".mysql_num_rows($query,"'"; to <?php echo "number of rows: '".mysql_num_rows($query); Regards ACE Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577878 Share on other sites More sharing options...
CBaZ Posted June 30, 2008 Author Share Posted June 30, 2008 now i see the row number but the id is still wrong i suppose in the bottom part or $query isn't right is it supposed to check mysql rows? or the txt files rows? Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577905 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 what do you mean the id is wrong? Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577909 Share on other sites More sharing options...
CBaZ Posted June 30, 2008 Author Share Posted June 30, 2008 resource id #7 at line 1. the right syntax needs checking Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577939 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 please post your current code and leave a comment at the end of which line the error is pointing towards eg. <?php $var=$$$Var // error is on this line <<< Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-577942 Share on other sites More sharing options...
CBaZ Posted June 30, 2008 Author Share Posted June 30, 2008 <?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>'; ?> Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-578312 Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 Fix: $sql = mysql_query("SELECT user_id FROM users WHERE user_id ='$user_id' ORDER BY created"); Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-578347 Share on other sites More sharing options...
CBaZ Posted June 30, 2008 Author Share Posted June 30, 2008 $row2 = mysql_query($result) or die("QUERY FAILED: " . mysql_error()); this line still has a problem Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-578362 Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 first off its VALUES not values Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-578386 Share on other sites More sharing options...
CBaZ Posted June 30, 2008 Author Share Posted June 30, 2008 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/112515-how-to-add-usernames-to-mysql-in-a-seperate-row/#findComment-578515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.