CBaZ Posted July 1, 2008 Share Posted July 1, 2008 2 issues in this script. one being I don't want it to keep entering the same usernames over and over i need a check if exist type thing and its not working what I currently have in place... also the profile2.php link at the bottom does not generate the correct id. the id needs to be for $triv usernames. not sure if this can be figured out with just this script by itself please let me know if you need more info. <?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("users_online2.txt"); $date = date("YmdHis"); echo $triv; if (mysql_num_rows($query) > 1 ) { // loop though array for($i=0;$i<count($triv);$i++) { // and add each entry to SQL $result = "INSERT INTO users (username,created) VALUES ('$triv[$i]', '$date')"; $row2 = mysql_query($result); }} else { $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"); $sql = mysql_query("SELECT user_id FROM users WHERE username != '$username' ORDER by created"); $row = mysql_fetch_assoc($sql); echo '</div><div class="title" id="top_bar_right"><a href="profile2.php?user_id='.$row['user_id'].'" target="RSIFrame2">'$triv'</div></div>'; } ?> Quote Link to comment Share on other sites More sharing options...
interpim Posted July 1, 2008 Share Posted July 1, 2008 In the future put your code between tags. It makes it easier to read. For your username issue. Search your database with the requested username. If you get a positive match, kick the user back with a duplicate name error. otherwise, create the new username. As far as the link for your profile2.php the method looks correct at first glance... what type of output are you getting? Quote Link to comment Share on other sites More sharing options...
CBaZ Posted July 1, 2008 Author Share Posted July 1, 2008 i am not getting the id for the usernames being added in the above code where its insert. it gives me id's that have nothing to do with the ones just added. do you have an example of how i would search the database like with another select from or something have been trying to google it just can't think of it. Quote Link to comment Share on other sites More sharing options...
interpim Posted July 1, 2008 Share Posted July 1, 2008 this is how you would search for an id based on the username. SELECT user_id FROM users WHERE username = '$username' it will select the user_id only, you then have to pull the resulting number and display/use it in your script. How are you storing 'user_id' in your database? 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.