stelthius Posted July 19, 2009 Share Posted July 19, 2009 Hey guys, ive built my script installer, and then my script updater, im having a issue with the script updater, it always ads a second admin user is there anyway i could add in a check to see if there is already a username admin if so dont add a new username admin. $admin_pass = md5($_POST['admin_pass']); $query18 = "INSERT INTO `users` (`user_id`, `username`, `password`, `session_id`, `login_ip`, `last_activity`, `user_level`, `email_address`) VALUES (1, '".$_POST['admin_user']."', '".$admin_pass."', 'NIL', 'NIL', 'NIL', '9', '".$_POST['admin_pass']."');"; With regards. Link to comment https://forums.phpfreaks.com/topic/166497-solved-script-installer/ Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Well, yeah just run a query selecting users with that username. If the result set is empty the user doesn't exist and you can run your insertion query. Link to comment https://forums.phpfreaks.com/topic/166497-solved-script-installer/#findComment-877984 Share on other sites More sharing options...
stelthius Posted July 19, 2009 Author Share Posted July 19, 2009 Ah i was curious if it would be wise to throw in a if statement to check to see if admin existed if not add him but if he does dont add him as the installer runs multiple queries, thanks Dan Link to comment https://forums.phpfreaks.com/topic/166497-solved-script-installer/#findComment-877985 Share on other sites More sharing options...
stelthius Posted July 19, 2009 Author Share Posted July 19, 2009 So basicly i could do something like $query="SELECT * FROM users WHERE admin = '$admin'"; $result=mysql_query($query) or die ("Query failed"); // This is the part were im stuck how would i go about adding in the admin is there code if ( ) { // Do nothing carry on finishing the query executions } else { $admin_pass = md5($_POST['admin_pass']); $query18 = "INSERT INTO `users` (`user_id`, `username`, `password`, `session_id`, `login_ip`, `last_activity`, `user_level`, `email_address`) VALUES (1, '".$_POST['admin_user']."', '".$admin_pass."', 'NIL', 'NIL', 'NIL', '9', '".$_POST['admin_pass']."'); } Sorry for the messy code was just threw together to try get an idea. Link to comment https://forums.phpfreaks.com/topic/166497-solved-script-installer/#findComment-877988 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 if (!mysql_num_rows(mysql_query("SELECT * FROM users WHERE username='admin' LIMIT 1"))) { // insert user } Link to comment https://forums.phpfreaks.com/topic/166497-solved-script-installer/#findComment-877990 Share on other sites More sharing options...
stelthius Posted July 19, 2009 Author Share Posted July 19, 2009 Ahhh so i dont need my top query in there at all thanks dan. Link to comment https://forums.phpfreaks.com/topic/166497-solved-script-installer/#findComment-877992 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Well yeah, but I just consolidated it into a single statement. Link to comment https://forums.phpfreaks.com/topic/166497-solved-script-installer/#findComment-877994 Share on other sites More sharing options...
stelthius Posted July 19, 2009 Author Share Posted July 19, 2009 Yeah sorry i meant i dont need it in there if i do it how you did in the example code, thanks Dan Link to comment https://forums.phpfreaks.com/topic/166497-solved-script-installer/#findComment-877995 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.