PDA

View Full Version : learning mysql



urbaneve
December 9th, 2003, 08:41 AM
does anyone know of where i can get the bare bones, from the beginning of time, made for dummies informaiton on using a mysql database.

i want to set up a user login and their account information thing and i assume that i need to use mysql but i dont know where to start.

-- and --

one where they can sign up for promotional updates too

any ideas

thanks

Voetsjoeba
December 9th, 2003, 01:40 PM
I believe Freddythunder wrote a tutorial on user login using MySQL. Look it up :)

MTsoul
December 9th, 2003, 07:46 PM
I learned mysql from phpmyadmin, frankly. It is a very good way of using/learning/seeing the mysql stuff.

urbaneve
December 10th, 2003, 04:31 AM
yeah -- i read the tut -- but where i am getting lost is in section 3 -- that's the part i dont understand. i used the script listed there but i dont know what to do with it. and it talks about a 'table' -- i am not sure what that is

and from my original question -- i dont know how to set up a mysql database and the tut doesnt explain thatt even though very well written for setting it up in flash (it explains the flash side of using PHP and mysql only)

thanks mtsoul -- the site was informative (although still a little over my head - but useful

norie
December 10th, 2003, 06:20 AM
I like to read the documentation

http://www.mysql.com/documentation/index.html

Voetsjoeba
December 10th, 2003, 07:08 AM
Yeah, the documentation has a good tutorial indeed. Point 3 in the overview ;)

Freddythunder
December 11th, 2003, 01:38 AM
urbaneve: The third part was written when I used an external mySQL program. It's actually easier when you use phpmyadmin. I'll give a try in the explination, yet I'm sure I'll leave some stuff out...my apologies!!

When you deal with online databases, you're setting up data that can be accessed by field names. One of the first things that you have to do with you server space is tell them you want mySQL. My server (powweb) will not give you the option unless you ask for it. Once you do, then you can set up dbs. When I started, it was $10; now it's free (who got screwed!!...me!!) now then; with phpmyadmin, you have the option when you first log in on the bottom to 'create new table'. That's what you want to do. It will ask you how many fields you want. In this instance you want three:
1 - id - auto_increment primary key (I'll explain further if you need)
2 - name - names in your database
3 - passwords - passwords that match the name

The most important field is the ID - it won't work without a primary key (located as a radio button on the far right side). When writting your own database tables, it's very trial and error and the script that I wrote can be written in a mysql_query() in PHP form, but that may be later. Let me know if you need more info. I figured it out, so I feel that anyone can :P Call me silly!!

urbaneve
December 18th, 2003, 12:31 AM
okey dokie freddy makin progress --
i was able to set up the table -- but now what do i do with it? what is the next step

it was a little tricky but i figured it out. i followed your tut and finally the part 3 made sense -- i just dont know how to tie it all together

here is what my phpadmin looks like

urbaneve
December 18th, 2003, 01:49 AM
here you go

Freddythunder
December 18th, 2003, 10:35 AM
now you need to populate it with usernames and passwords. I'm new to phpmyadmin because I was using a different external program before my host closed that; so I don't know if you can enter info with it or not. I usually will use something like this:


<?
$user=$_POST['user'];
$pass=$_POST['pass'];
if ($REQUEST_METHOD == "POST"){
$query = "INSERT INTO auth (username, password) ";
$query .= "VAULES ('$user','$pass')";
mysql_connect('host','username','password') or die ('no connection');
mysql_select_db('yourdb') or die ('no db');
$result = mysql_query( $query ) or die ('no query');
if ($result){
echo $user." has been entered into the database!";
} else {
echo "Danger Will Robinson!! Something went wrong!!"
}
}
?>
<html>
<head>
<title>Insert crap</title>
</head>
<body>
<form action="<? echo ($PHP_SELF); ?>" method="POST">
Enter name for database:<br>
Name: <input type="text" size="30" name="user"><br>
Password: <input type="text" size="30" name="pass"><br>
<input type="submit" value="add to db">
</form>
</body>
</html>

Now that I've typed all this, didn't I include a script like this in the zip file with the tut? Either way, save it as (something like) insert.php, run it through your browser and insert stuff. The script above is NOT tested, but I think it should work.

urbaneve
December 19th, 2003, 05:32 AM
yeah there was a script in with the zip and i think it went something like this:


<?
//this pulls the variables from the flash movie when the user
//hits submit. Use this when your global variables are off.
//I don't know how to toggle global variables, so I just put
//it in all the time ;)
$user=$_POST['user'];
$pass=$_POST['pass'];

//connect to database
if ($user && $pass){
mysql_pconnect("mysql.yourhost.com","yourusername","yourpassword") or die ("didn't connect to mysql");
mysql_select_db("yourdatabase") or die ("no database");

//make query
$query = "SELECT * FROM auth WHERE username = '$user' AND userpassword = '$pass'";
$result = mysql_query( $query ) or die ("didn't query");

//see if there's an EXACT match
$num = mysql_num_rows( $result );
if ($num == 1){
print "status=You're in&checklog=1";
} else {
print "status=Sorry, but your user name and password did not match a user name/password combination in our database. Usernames and passwords are entered in from a different file. Thank you for visiting test login script!!&checklog=2";
}
}
?>



cross your fingers and hope it works :)

Freddythunder
December 19th, 2003, 05:07 PM
Actually, that one is for checking the database for a match for the flash login. The other one that I wrote above with the form can be used to populate your database. I will cross my fingers for you! :P

urbaneve
December 22nd, 2003, 03:47 AM
okay --- thanks i really appreciate it