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> '; ?> Quote Link to comment 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>'; ?> Quote Link to comment Share on other sites More sharing options...
CBaZ Posted June 30, 2008 Author Share Posted June 30, 2008 nope didn't work at all Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 <<< Quote Link to comment 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>'; ?> Quote Link to comment 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"); Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 first off its VALUES not values Quote Link to comment 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>'; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.