Mythic Fr0st Posted December 3, 2006 Share Posted December 3, 2006 Well, I've got everything sorted out, but however, I cant figure this outI 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? Link to comment https://forums.phpfreaks.com/topic/29282-storing-username-passwords-e-mails-into-mysql/ Share on other sites More sharing options...
genericnumber1 Posted December 3, 2006 Share Posted December 3, 2006 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.. domysql_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. Link to comment https://forums.phpfreaks.com/topic/29282-storing-username-passwords-e-mails-into-mysql/#findComment-134215 Share on other sites More sharing options...
Mythic Fr0st Posted December 3, 2006 Author Share Posted December 3, 2006 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 loland i've got it goingbut I need to add the password, for loginthis is what im using to check for the login ( but theres no password to check for )and whats md5() lolmy 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 usersWHERE username=$_POST['login']");while($row = mysql_fetch_array($result)) { echo $row['username'] . " " . $row['email']; echo "<br />"; }?>[/code]I just get an error somewhere in thereParse 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 Link to comment https://forums.phpfreaks.com/topic/29282-storing-username-passwords-e-mails-into-mysql/#findComment-134228 Share on other sites More sharing options...
genericnumber1 Posted December 3, 2006 Share Posted December 3, 2006 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 youwhile($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] Link to comment https://forums.phpfreaks.com/topic/29282-storing-username-passwords-e-mails-into-mysql/#findComment-134232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.