newsha99 Posted April 20, 2017 Share Posted April 20, 2017 I have had troubles finding out why after the registering page it directs me to a blank page that says : "Connection to MySQL server successfully established." I had two php code segments: one for the registration process and one for login process. The purpose was for it to check if the user was already registered if not then they could register and it would save their login data and direct them to the member page which has all the content behind the login. If they are already registered or nothing is entered and/or the characters of each variables are less than 6 then it would give them an error. that was the idea behind it but every time i press on register even without the required characters it directs the page to a blank page saying: "Connection to MySQL server successfully established." please help and thank you! Quote Link to comment Share on other sites More sharing options...
benanamen Posted April 20, 2017 Share Posted April 20, 2017 (edited) Pictures are for hanging on the wall. Post your code and use the code tags. Your code is pretty bad with many problems. If you copied that from a tutorial you should delete the bookmark. * You posted in the wrong category. There is no regex that I saw. Edited April 20, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
newsha99 Posted April 20, 2017 Author Share Posted April 20, 2017 (edited) //registration process <?php session_start (); include 'connect.php'; if (isset ($_POST ['users'])){ $username = $_POST ['username']; $password = $_POST ['password']; $errors= ""; if (strlen ($username) < 6){ $errors .="your username must be more than 6 characters long."; } else{ $query ="select * from users where username='username';"; $result= mysqli_query($connection, $query) or die (mysqli_error($connection)); if (mysqli_num_rows($result)>=1){ $errors .= "your username is already in use."; } } if (strlen ($password) < 8{ $errors .= "your password must be more than 8 characters long."; } if ($errors==""){ $query ="insert into users(username,password) values ($username,$password);"; $result= mysqli_query ($connection,$query ) or die(mysqli_error ($connection)); $_SESSION['username']= $username; header("Location: member.html"); } else { $_SESSION['registererror'] = $errors; header("Location: register.php"); } } else { header("Location: register.php"); } ?> //login process <?php session_start(); include 'connect.php'; if (isset($_POST['username']) and isset($_POST['password'])) { $username = $_POST['useranme']; $password = $_POST['password']; $query = "select * from users where username='$username' and password='$password';"; $result = mysqli_query($connection, $query) or die(mysqli_error($connection)); if (mysqli_num_rows($result) == 1) { $_SESSION['username'] = $username; header ("Location : member.html"); } } if (!isset($_SESSION['username'])) { $_SESSION['passmsg'] = "Incorrect username or password."; } header("Location: login.php"); ?> Edited April 20, 2017 by newsha99 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 20, 2017 Share Posted April 20, 2017 The code doesn't tell us anything (except that you have plenty of other errors you need to take care of). Show the connection script. Appearently you're doing strange things there. Or even better: Throw away your current code, learn PDO, start over. mysqli is too complicated for the average PHP newbie. I also strongly recommend you start thinking about the code you write instead of blindly following dubious “tutorials” you found somewhere. All this or die(mysqli_error()) stuff is cargo cult programming -- everybody does it, nobody has any idea why they're doing it. Quote Link to comment Share on other sites More sharing options...
benanamen Posted April 20, 2017 Share Posted April 20, 2017 I guess you missed the part where I said use the code tags. The forum expects it of you. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 20, 2017 Share Posted April 20, 2017 (edited) 1 - you test if the lengths of your inputs are less than a certain value but then you say that the value must be GREATER than that value, leaving out that specific value. 2 - you save your passwords in plain text apparently. Nobody does that. 3 - your query looks for a username of EXACTLY 'username'. Do you really allow that to be a username? 4 - I am assuming that your username and password values are not numeric, so to use them in queries you must quote them. Or use PREPARED QUERIES and avoid that. 5 - you show us an error message that you have a problem with, but you don't show us the code that produced that message. How can you expect us to help you? Coding hint - use indents to help organize your code and make it easier to read thru. Having everything in column 1 is boring and hard to decipher when is looking for a certain 'block' of statements. Example (note how I used code tags here): if (isset($_POST['username']) and isset($_POST['password'])) { $username = $_POST['useranme']; $password = $_POST['password']; $query = "select * from users where username='$username' and password='$password';"; $result = mysqli_query($connection, $query) or die(mysqli_error($connection)); if (mysqli_num_rows($result) == 1) { $_SESSION['username'] = $username; header ("Location : member.html"); } } if (!isset($_SESSION['username'])) { $_SESSION['passmsg'] = "Incorrect username or password."; } header("Location: login.php"); oops - the forum is not accepting any of the tabs in my version of your code Edited April 20, 2017 by ginerjm Quote Link to comment Share on other sites More sharing options...
newsha99 Posted April 20, 2017 Author Share Posted April 20, 2017 (edited) This is the connect page and i got help from a classmates code. <?php $host_name="db678077635.db.1and1.com"; $database="db678077635"; $username="dbo678077635"; $password="password!"; $connect= mysqli_connect($host_name, $username, $password, $database); if (mysqli_connect_errno()){ echo "<p> Failed to connect to MySQL:'.mysqli_connect_error()'.</p>"; } else{ echo "<p> Connection to MySQL server successfully established.</p>"; header("Location: member.html"); } ?> Edited April 20, 2017 by newsha99 Quote Link to comment Share on other sites More sharing options...
benanamen Posted April 20, 2017 Share Posted April 20, 2017 (edited) Seriously! What is your problem? FOR THE THIRD TIME, USE THE CODE TAGS Congratulations on posting your complete server credentials for the world to see. Edited April 20, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 20, 2017 Share Posted April 20, 2017 OK - you have some connection code. Who is a "classmates code" and what does that matter to us? You include this code in your script and it does a connection. That's all it should be doing but you and your "classmates" decided to execute a header to take you to some OTHER page. How the heck is your script going to run if your connection code takes you somewhere else? You don't program much, do you? Contrary to what you might think - until you learn one language fluently It Is Rocket Science. So many people think they can dabble in it like fixing their lawn mower engine. This is more like fixing an 8-cyl muscle car - don't do it half-assed and without doing some reading and learning from reputable sources. And please use the code tags. Here's another reading assignment - read the forum rules. They will tell you how to post here. Quote Link to comment Share on other sites More sharing options...
newsha99 Posted April 20, 2017 Author Share Posted April 20, 2017 Seriously! What is your problem? FOR THE THIRD TIME, USE THE CODE TAGS Congratulations on posting your complete server credentials for the world to see. i obviously changed the password and username if you think im stupid enough to show it to the world like that you must be crazy................................ Quote Link to comment Share on other sites More sharing options...
newsha99 Posted April 20, 2017 Author Share Posted April 20, 2017 OK - you have some connection code. Who is a "classmates code" and what does that matter to us? You include this code in your script and it does a connection. That's all it should be doing but you and your "classmates" decided to execute a header to take you to some OTHER page. How the heck is your script going to run if your connection code takes you somewhere else? You don't program much, do you? Contrary to what you might think - until you learn one language fluently It Is Rocket Science. So many people think they can dabble in it like fixing their lawn mower engine. This is more like fixing an 8-cyl muscle car - don't do it half-assed and without doing some reading and learning from reputable sources. And please use the code tags. Here's another reading assignment - read the forum rules. They will tell you how to post here. whoever you are you should know that i am a high school senior in the AP comp sci class. i am not in college yet, but will be going for my masters in computer science. don't tell me if i do or dont program much cause if i did why in the hell would i be here asking so many questions... you all better get your attitudes fixed before yelling at me behind the screen. ps dont think im dumb enough to share my info of the database like that. a classmate that i have helped me and it was better than what i got from any of you.... because all you did was tell me how bad it is.... NO SHIT. why tf would i be here if my code was running and it was all well . maybe next time when you want to help someone you should actually help them and not say wow.....this code is bad... -_______- goodbye. Quote Link to comment Share on other sites More sharing options...
newsha99 Posted April 20, 2017 Author Share Posted April 20, 2017 The code doesn't tell us anything (except that you have plenty of other errors you need to take care of). Show the connection script. Appearently you're doing strange things there. Or even better: Throw away your current code, learn PDO, start over. mysqli is too complicated for the average PHP newbie. I also strongly recommend you start thinking about the code you write instead of blindly following dubious “tutorials” you found somewhere. All this or die(mysqli_error()) stuff is cargo cult programming -- everybody does it, nobody has any idea why they're doing it. thank you so much for your help! will do! 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.