Jump to content

Storing username & passwords & e-mail's into MySQL


Mythic Fr0st

Recommended Posts

Well, I've got everything sorted out, but however, I cant figure this out

I dont get how to add stuff into MySQL, I've read a tutorial for it, for a while, but I still can't figure it out?

I have the database made, and the tables setup, but how do I put the data into it o_O?
mysql_query("INSERT INTO your_table_name (your_column_1, your_column_2) VALUES ('your_value_1', 'your_value_2');

So if your table is "mytable" and you want to insert "john" into a "name" column and "florida" into a "location" column.. do

mysql_query("INSERT INTO mytable (name, location) VALUES ('john', 'florida');

Make sure you've connected to mysql first. And if you're storing passwords you should encrypt them with something like the md5() function.
firstly, I was told to put this in my SQL section my phpMyAdmin it creates tables and stuff

[code]CREATE TABLE `users` (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL DEFAULT '',
  `email` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `idx_username` (`username`),
  UNIQUE KEY `idx_email` (`email`)
)
[/code]
How would I add a section for my password, like it has "email" but can you show me how to add password too, I tried and made lots of errors lol

and i've got it going

but I need to add the password, for login

this is what im using to check for the login ( but theres no password to check for )

and whats md5() lol

my login code:

[code]<?php
$con = mysql_connect("localhost","Moofasa","nottelling");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("users", $con);

$result = mysql_query("SELECT * FROM users
WHERE username=$_POST['login']");

while($row = mysql_fetch_array($result))
  {
  echo $row['username'] . " " . $row['email'];
  echo "<br />";
  }

?>
[/code]

I just get an error somewhere in there

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\easyphp1-8\www\test\home.php on line 25 to be exact...

line 25, is the WHERE username=$_POST['login']"); line, can anyone tell me whats wrong with it?

edit: note: the purpose of the "Login" code is to check if the persons username & password exist
1)
Just store passwords as varchar as well.
CREATE TABLE `users` (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL DEFAULT '',
  `password` varchar(255) NOT NULL DEFAULT '',
  `email` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `idx_username` (`username`),
  UNIQUE KEY `idx_email` (`email`)
)

2)
md5 is a form of one way encryption... if a person gets a hold of your database it wont be convenient in the least to try to get the encrypted passwords...
if you have the password stored in MD5 it's just generally safer, I wont get into that unless you want, it was just a suggestion.

3)
here's how to check to see if someone's user/pass/email is set, that's what you wanted right?
[code=php:0]

// the top of your code here, removed for size

$result = mysql_query("SELECT * FROM users
WHERE username={$_POST['login']}");
// you need to put {} around arrays when you use them like above
// I did it for you

while($row = mysql_fetch_array($result))
  {
  echo $row['username'] . " " . $row['email'] . " ";
  if(!empty($row['password'])){
    echo "Password is set."; // You dont wanna echo passwords :D
  } else {
    echo "Password ISN'T set.";
  }
  echo "<br />";
  }
[/code]

Archived

This topic is now archived and is closed to further replies.

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