4me Posted October 15, 2015 Share Posted October 15, 2015 Hello. Please help me, I can not make a "registered with the choice mysql of server" Ie is the usual registration form Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 15, 2015 Share Posted October 15, 2015 Try to phrase a coherent problem description and show the relevant code. Then we might be able to help you. Quote Link to comment Share on other sites More sharing options...
4me Posted October 15, 2015 Author Share Posted October 15, 2015 Jacques1 <?php if(isset($_POST['submit'])) { session_start(); if($_POST['kapcha'] != $_SESSION['rand_code']) exit ("<center>error code image</center>"); else echo ""; if (isset($_POST['login'])) { $login = $_POST['login']; if ($login == '') { unset($login); } } $err = array(); if(!preg_match("/^[a-z0-9\_]+$/", $login)) { exit ("<center>Username can only contain letters of the Latin alphabet and numbers!</center>"); } if( preg_match( "/[а-яёА-ЯЁ|\s]/", $login ) ) { exit ("<center>Username may contain only letters and numbers!</center>"); } if (isset($_POST['password'])) { $password = $_POST['password']; if ($password =='') { unset($password); } } if (strlen($login) < 3 or strlen($login) > 25) { exit ("<center>Login must be at least from <b> 3 </ b> characters and no more than: <b>25<b>, go back and try again</center>"); } if (strlen($password) < 6 or strlen($password) > 20) { exit ("<center>The password should consist of at least from <b> 6 </ b> characters and no more than from <b> 20 </ b>, go back and try again</center>"); } if (empty($login) or empty($password)) { exit ("<center>You do not have entered all the information, go back and fill in all fields!</center>"); } $login = stripslashes($login); $login = htmlspecialchars($login); $password = stripslashes($password); $password = htmlspecialchars($password); $login = $_POST['login']; $password = $_POST['password']; //$password = htmlspecialchars($password); //$password = md5($password); //удаляем лишние пробелы $login = trim($login); $password = trim($password); include ("mysql.php"); $result = mysql_query("SELECT username FROM users WHERE username='$login'", $db); $myrow = mysql_fetch_array($result); if (!empty($myrow['username'])) { exit ("<center>Sorry, you entered login is already registered. Please enter a different username.</center>"); } $result2 = mysql_query ("INSERT INTO users (username,password) VALUES('$login','$password')"); $login = mysql_real_escape_string($_POST['login']); $password = mysql_real_escape_string($_POST['password']); if ($result2=="TRUE") { echo "<center>You have successfully logged in! Now you can log in using your ID.</center>"; } else { echo "Error! You are not registred."; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <meta charset="utf-8"/> <head> <link rel="stylesheet" href="css/styles.css"> <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" /> <title>Register</title> </head> <body> <center><h3><a href="/">Jabber Server </a></h3></center> <div> <form action="../register.php?do=reg" method="post"> <label for="name">Login:</label> <input name="login" type="name" size="15" maxlength="15"> <br /> <label for="password">password:</label> <input name="password" type="password" size="15" maxlength="15"> <br /> <input name="md5" type="hidden"> <img src = "captcha.php" /> <br /> <input type = "text" name = "kapcha" /> <br /> <input type="submit" name="submit" value="Register"> <center> </center> </form> </div> </body> </html> I want to make as there https://jabber.ru/user/register Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 15, 2015 Share Posted October 15, 2015 You are using obsolete MySQL code that will not work at all in the latest version Php. You need to use PDO with prepared statements. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 15, 2015 Share Posted October 15, 2015 It's still unclear to me what you mean by choosing the MySQL server. Do you have multiple database servers? Or are you talking about databases? In any case: Why do you have more than one? By the way, the code has lots of problems. The mysql_* functions are obsolete since more than a decade and will be removed in PHP 7. Nowadays, we use PDO. Randomly throwing all this stripslashes(), htmlspecialchars() etc. at the user input also isn't a good idea. Quote Link to comment Share on other sites More sharing options...
4me Posted October 15, 2015 Author Share Posted October 15, 2015 I have several databases jabberserver1 - (localhost; user1;pass1;dbname1) jabberserver2 - (localhost; user2;pass2;dbname2) etc I need to make sure that the user has registered by the server for registration jabberserver1 or jabberserver2 the script would be entered into the database data for selected mysql server Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 15, 2015 Share Posted October 15, 2015 Why do you want two databases? Why not use one and separate the users within the database? Simply add a column which assigns the user to one of the two Jabber servers. Maintaining two identically(?) structured databases is generally a very bad idea, because it makes the code more complicated, forces you to do everything twice (changes, backups) and can quickly lead to problems if you update one database but forget to update the other. Quote Link to comment Share on other sites More sharing options...
4me Posted October 15, 2015 Author Share Posted October 15, 2015 Jacques1The fact that a database for different servers I need a script that would register users on select server demo https://jabber.ru/user/register Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted October 16, 2015 Solution Share Posted October 16, 2015 I understand that you have multiple Jabber servers, but that doesn't mean you should have a separate database for each one of them. Or is this a specific requirement of the Jabber implementation you're using? Anyway, if you absolutely need multiple databases, create an array which maps the different servernames to different MySQL connection parameters: <?php $jabberDatabases = [ 'jabber1.example.com' => [ 'host' => 'localhost', 'user' => 'user1', 'password' => 'pw1', 'database' => 'db1', ], 'jabber2.example.com' => [ 'host' => 'localhost', 'user' => 'user2', 'password' => 'pw2', 'database' => 'db2', ], ]; Given the name of the jabber server, you can select the corresponding parameters for mysql_connect() and mysql_select_db(). Quote Link to comment Share on other sites More sharing options...
4me Posted October 16, 2015 Author Share Posted October 16, 2015 (edited) Jacques1 thanks can not do it, I found the script, it seems: http://www.codingcage.com/2015/04/php-login-and-registration-script-with.html Edited October 16, 2015 by 4me Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 16, 2015 Share Posted October 16, 2015 (edited) Que Jaw drop . That script has nothing whatsoever to do with what you just posted about.. That script is also vulnerable to SQL Injection. Edited October 16, 2015 by benanamen 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.