Zoud Posted January 15, 2007 Share Posted January 15, 2007 I have a form were people can create accounts on my site. When I enter the page, it will insert a user as ("", "") before any information is submitted to the page.Basicly what I need is a small add-on to this code that will not let it activate without information being submitted to it first.[code]<?php$con = mysql_connect("-","-","-");if (!$con) { die('Error: ' . mysql_error()); }mysql_select_db("members", $con);$sql="INSERT INTO person (username, password)VALUES('$_POST[regun]','$_POST[regpw]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "Your account has been created.";mysql_close($con)?><form action="register.php" method="post">Username: <input type="text" name="regun" />Password: <input type="text" name="regpw" /><input type="submit" /></form>[/code]On another note, could someone tell me how to encrypt passwords on the DB when submitted? Link to comment https://forums.phpfreaks.com/topic/34263-recieving-data-from-a-form/ Share on other sites More sharing options...
JJohnsenDK Posted January 15, 2007 Share Posted January 15, 2007 You need to correct a few things like this:[code]<?php$con = mysql_connect("-","-","-");if (!$con) { die('Error: ' . mysql_error()); }mysql_select_db("members", $con);if(isset($_POST[submit])){$sql="INSERT INTO person (username, password)VALUES('$_POST[regun]','$_POST[regpw]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "Your account has been created.";}else{ echo "Didnt work!";}mysql_close($con)?><form action="register.php" method="post">Username: <input type="text" name="regun" />Password: <input type="text" name="regpw" /><input type="submit" name="submit" /></form>[/code] Link to comment https://forums.phpfreaks.com/topic/34263-recieving-data-from-a-form/#findComment-161148 Share on other sites More sharing options...
Zoud Posted January 15, 2007 Author Share Posted January 15, 2007 Thanks! That worked great! Now all I need is for someone to tell me how to encrypt the password field when it's submitted to the DB. Link to comment https://forums.phpfreaks.com/topic/34263-recieving-data-from-a-form/#findComment-161159 Share on other sites More sharing options...
JJohnsenDK Posted January 15, 2007 Share Posted January 15, 2007 There are two ways to crypt password with md5() or crypt()... md5() is a bit more safe. but here you go:[code]<?php$con = mysql_connect("-","-","-");if (!$con) { die('Error: ' . mysql_error()); }mysql_select_db("members", $con);if(isset($_POST[submit])){$crypted_pass = md5($_POST[regpw]);$sql="INSERT INTO person (username, password)VALUES('$_POST[regun]','$crypted_pass')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "Your account has been created.";}else{ echo "Didnt work!";}mysql_close($con)?><form action="register.php" method="post">Username: <input type="text" name="regun" />Password: <input type="text" name="regpw" /><input type="submit" name="submit" /></form>[/code]that should do it. Link to comment https://forums.phpfreaks.com/topic/34263-recieving-data-from-a-form/#findComment-161182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.