Jump to content
xisto Community
HmmZ

Php Simple Login Tutorial Learn how to make a simple login

Recommended Posts

Hmmz, I adjusted my code and the error went away, but when I went to try it out and register, yep, I hit another roadblock...it says...

Error: User not added to database.


...frustrating...

what do you make of this?

Share this post


Link to post
Share on other sites

Sorry about the double post...but its 4 AM and I'm goin to bed but I saw somethin else...in addition to my previous post whenever I registered to check what would happen and it said user not added to database...I went to my phpMyAdmin and looked at my table....and my username WAS added...this just adds to my confusionAny help?

Share this post


Link to post
Share on other sites

I think I see the problem, its checking a wrong query, try the following (old code first to see where you can find it)

// Fields are clear, add user to database //  Setup query $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "  ."VALUES ('".$_POST["username"]."', "  ."PASSWORD('".$_POST["password"]."'), "  ."'".$_POST["email"]."')"; //  Run query $r = mysql_query($q);  // Make sure query inserted user successfully if ( !mysql_insert_id() )  {  die("Error: User not added to database.");  }

replace if(!mysql_insert_id()) with this:
if(!$r)

let me know if that fixes your problem

Share this post


Link to post
Share on other sites

Hey guys I found a tutorial that fixed my problem...thanks to all that tried to help...I believe the tutorial link I found is under the hosted members area, it is a really easy step by step guide that include improvements to the original php codes, thanks again everyone.

Share this post


Link to post
Share on other sites

I like that alot! I'm trying to lurn php and mySql, and that help. Two thumbs up!

Share this post


Link to post
Share on other sites

Whenever I try this, it always says "ERROR:Not added to the database."

<?php// dbConfig.php is a file that contains your// database connection information. This// tutorial assumes a connection is made from// this existing file.include ("dbconfig.php");//Input vaildation and the dbase codeif ( $_GET["op"] == "reg" ) { $bInputFlag = false; foreach ( $_POST as $field )  {  if ($field == "")   {   $bInputFlag = false;   }  else   {   $bInputFlag = true;   }  } // If we had problems with the input, exit with error if ($bInputFlag == false)  {  die( "Problem with your registration info. "   ."Please go back and try again.");  } // Fields are clear, add user to database //  Setup query $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "  ."VALUES ('".$_POST["username"]."', "  ."PASSWORD('".$_POST["password"]."'), "  ."'".$_POST["email"]."')"; //  Run query $r = mysql_query($q);  // Make sure query inserted user successfully if ( !mysql_insert_id() )  {  die("Error: User not added to database.");  } else  {  // Redirect to thank you page.  Header("Location: register.php?op=thanks");  } } // end if//The thank you pageelseif ( $_GET["op"] == "thanks" ) { echo "<h2>Thanks for registering!</h2>"; } //The web form for input abilityelse { echo "<form action=\"?op=reg\" method=\"POST\">\n"; echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n"; echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n"; echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n"; echo "<input type=\"submit\">\n"; echo "</form>\n"; }// EOF?>

Share this post


Link to post
Share on other sites

Here is the MD5 alternative:


<?PHP $user_name = $_POST['u_name']; $password = $_POST['pass']; //db connection string $db = mysql_connect("localhost","root","pass"); mysql_select_db("my_database",$db); //replace the above values with your actual database val //We will now retrive the password from the database $sql_query = mysql_query("SELECT password FROM user_data WHERE user_name='$user_name'",$db); $rs = mysql_fetch_row($sql_query); //comparing passwords Note before we can compare the password we use md5() to encrypt the $password becuase the password that we retrive from the database is in the encrypted form. if(md5($password) != $rs[0]) echo "ERROR: Invalid User"; else echo "Congrats, Password is correct!"; ?>


( I pulled this off http://www.phpbuddy.com/ ) Although this shows you how fast and easy it is to use MD5 and personally I prefer it over PEAR

Share this post


Link to post
Share on other sites

That's about it!. I used many simple examples hoping that you will learn how the internal systems work so you can expand on them and design a system that's just right for your needs. Have fun! :D
hey dude i have a question. I followed your tutorial. See when i add the code it is previewed before you go back to the the contraol center(using freehostingnow.com). When it previews in shows it all but when i go to http://www.sro-gaming.freehostingnow.com/register/login.php the pages are blank. if you know what's weong email me at sro-gaming@hotmail.com
Subject: login trouble
thnx

Notice from jlhaslip:
No need to quote the whole Original Posting into your reply

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.