Jump to content

registration and login form complications!


newsha99

Recommended Posts

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!

 

 

 

post-204135-0-98101200-1492652630_thumb.png

post-204135-0-11317300-1492652633_thumb.png

Link to comment
Share on other sites

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 by benanamen
Link to comment
Share on other sites

//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 by newsha99
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by ginerjm
Link to comment
Share on other sites

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 by newsha99
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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................................

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.