Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> My Sql Database Help?
shnabo11
post Aug 16 2007, 03:51 PM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 1
Joined: 16-August 07
Member No.: 24,120



Ok, i am new at web design, i dont know too much about it... I was working on a website for about a month this is what i got, My Web , like i said, i dont know much.. i used FrontPage and did all of that, my current host is AFMU which uses MySQL, but the way it is set up I dont know how to acquire the URL of the database or any information i dont know what it means at all.. i just want to do a simple login feature, i mean this is my first website and i am learning so I think it would be a great feature to add in and learn. i can create data bases from there but do not know what to do afterwards, example: I Create a database name and a user this is what it leaves me with; NOTE! I did not change ANYTHING listed below, this is EXACTLY what it created for me, now that i got that off my chest, here it is:
CODE
Current Databases:
deatncom_logindb  
Users in logindb
deatncom_shnabo (Privileges: ALL PRIVILEGES)

Connection Strings
Perl $dbh = DBI->connect("DBI:mysql:deatncom_logindb:localhost","deatncom_shnabo","<PASSWORD HERE>");
PHP $dbh=mysql_connect ("localhost", "deatncom_shnabo", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("deatncom_logindb");


Could some on please tell me how i use this information??? please..

I appreciate the time you took to read this, and if you know what to do please post, thank you very much


This post has been edited by shnabo11: Aug 16 2007, 04:01 PM
Go to the top of the page
 
+Quote Post
pyost
post Aug 16 2007, 07:38 PM
Post #2


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,002
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



In order to connect a web site with a MySQL database, you will need to know more about web development than just using Microsoft FrontPage - you will also need to learn PHP (or ASP, but the former is a better option). However, prior to doing so, it would also be a good idea to start dealing with HTML code instead of using a WYSIWYG (What You See Is What You Get) editor (e.g. FrontPage, Dreamweaver). Be aware that PHP isn't easy, and that it will take at least a month of regular practice for you to be able to create a hack-proof and secure login system.

If all this looks like a too big step to you, there is always the option of using a CMS (Content Management System) for your web site. These are great because they offer easy content management along with a user-friendly interface, as well as a registrations system (in most cases). I must warn you, though, that this option too requires a little HTML/PHP knowledge in order to use it to its full potential. Even if you do decide on the first one, examining how a certain CMS works is a great way of learning new things. Or at least that is my experience smile.gif
Go to the top of the page
 
+Quote Post
Arbitrary
post Aug 17 2007, 03:31 AM
Post #3


Premium Member
Group Icon

Group: [HOSTED]
Posts: 363
Joined: 17-June 06
From: Adblock life
Member No.: 13,992



Pyost is right--you definitely need more than just FrontPage.

Okay, if you've already created a database, then just paste the code that was given to you in a file. I'll go with PHP for now:

CODE
PHP $dbh=mysql_connect ("localhost", "deatncom_shnabo", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("deatncom_logindb");

Paste this in a .php file and replace <PASSWORD HERE> with the password you specified while creating the database. Once you run the file, the database connection will be opened. Also remember to put <?php and ?> around the PHP code.

Then, afterwards, you want to create a table in the database to hold your login information. (Use PhpMyAdmin if you're using MySQL) You could go with three fields (username, password, email, id) for a very very simple user registration. For the username, password, and email you should leave the field type as varchar with a length of your choice. For the id, use a type of int and set it as a primary key. Also, under extras, set the id to 'auto_increment'. The id is mostly for internal tracking purposes and won't be of much use to the end-user.

Under the different options, you shouldn't need to touch collation, attributes, and null. Default you can set if you want there to be a default value for each field. (Not really applicable in your situation, I think)

Clicking save should also generate PHP code that can be used to create the exact same table if you paste it in a php file.

Then, in order to access the table, you should use mysql. First you'd want to create a registration page (let's say called register.php). In it you'd have:

CODE
<form action="register.php" method="post">
<label for="username">Username: </label>
<input type="text" name="firstname"><br />
<label for="password">Password: </label>
<input type="password" name="password"><br />
<label for="email">Email: </label>
<input type="text" name="email"><br />
</form>


As a side note, I typed this in the browser, so there's no guarantee it'll work right off the bat. Now, to break apart the tags within <form></form>...

[a] the action attribute within <form> -- this is where the form directs to, and it's also where you want to put the php code to execute data received from the form
[b] the method attribute within <form> -- this tells the browser how to send the information. It can either be POST or GET. If it's GET, the data will appear in a website's url--ex: www.example.com/something.php?actid=5 If it's POST, the data is hidden. For something sensitive like registration or logging in, POST should always be the one used
[c] the name attribute in the input tag -- this is the name that's used by PHP to access the data--you'll see later.

Moving on...

Now, to access the form data that a user has entered, in register.php we'd want to have:

CODE
<?php
$username = $_POST["username"];
$email= $_POST["email"];
$password= $_POST["password"];
?>


Suppose the user entered helpless as the username, iowf83M as the password and weoiwho@gmail.com as the email. Then the variables $username, $email, and $password should contain the respective data. The array variable $_POST is defined by PHP to access data from a form with a method of POST. The ["username"] part of the variable is the value defined in name in the input tag.

Before you do anything with the password, you should md5 has it for security purposes. Ex:

CODE
<?php
$password = md5($password);
?>

md5 is a (nice) built-in function in php that does what it says.

Once you've got the data within variables and hashed accordingly, you'd want to use this to insert the data into the database:

CODE
<?php
mysql_query("INSERT INTO <table_name> (username, password, email)
VALUES ('$username', '$password', '$email')");
?>


To break the mysql query down, INSERT INTO is very obvious. Replace <table_name> with the name of your table. (Most likely users or something like that). The stuff between the parentheses are the fields you want to insert into--username, password and email. The values correspond to their respective fields.

Now that the data is in the database, to retrieve it, we use another mysql query.
CODE
$username = $_POST["username"];
$email= $_POST["email"];
$password= $_POST["password"];

$result = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");


The select query gets the user where username is the username entered and password is the password entered. If $result exists, then the user can be logged in.

This is the most basic aspects of a login system, and it's not even fully complete yet. For a secure login system, check out http://www.devshed.com/c/a/PHP/Creating-a-...P-Login-Script/ . Of course, you'd need stripslashes to make sure that sql injections won't work. And as incoherent last words, it's best to use a framework for larger projects (I recommend CakePHP)

This post has been edited by Arbitrary: Aug 17 2007, 03:33 AM
Go to the top of the page
 
+Quote Post
yordan
post Aug 20 2007, 12:56 PM
Post #4


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 1,980
Joined: 16-August 05
Member No.: 7,896



Thanks to Arbitrary for this very complete introduction.
I would also add a suggestion.
If you are hosted here at astahost, and if you like "learn-by-example", I would suggest you to use the Astahost's "Fantastico" facility, and install a phpbb forum or a 4image gallery, have a look at the sources generated, and see how they manage the database connection and user/passwords handling.
I really think that looking at other people's programs help understanding a lot.
And, of course, having a working system, which correctly connects to a correctly database, is really helpful.
Then, comparing the working scripts to your faulty scripts could help correcting your errors.
And, of course, when you will be grown, you will start writing down your own programs from scratch, and they will be far better than any examples that could be provided.
Regards
Yordan
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. phpBB Database Transfer(10)
  2. Embedded Database(7)
  3. Creating A Game In Rpg Maker 2000/2003(18)
  4. Need Advice On Creating Online Music Database(6)
  5. Mirror My MySQL Database To Another Mysql Server(4)
  6. How To: Connect, Read, Write, Close A Database(3)
  7. The Best Database(48)
  8. Need Help With A PHP - MySQL Registration Script(13)
  9. MySQL Output Database Question(18)
  10. Is It A Good Practice To Store Image Or Other Binary Files Directly In A Mysql Database(4)
  11. Permission Problem With Mysql Database Creation(8)
  12. Ajax + Php + Sql = Simply Superb! ( With Visitor Tracking )(10)
  13. How Many Concurrent Users For Oracle Database?(1)
  14. Database Size?(10)
  15. Five Common Php Database Problems(0)
  1. Need Help In Database Auto_increment(9)
  2. Can't Select Database =?(3)
  3. How To Make A Value In The Database Raise Every Minute.(50)
  4. Api And Http Or Database?(0)
  5. Connecting To A Remote Database(9)
  6. Database(1)
  7. Integrate Access Database Onto Intranet Site(5)
  8. Accessing Ms Access Database From A Centralized Location?(5)
  9. Mysql Database Management(1)
  10. Mysql Database Entry By Excel Sheets(2)
  11. Space Needed For Database(10)
  12. Database Access On Remote Server W/jsp(0)
  13. Some Useful Database Links.(7)


 



- Lo-Fi Version Time is now: 5th September 2008 - 11:19 AM