dean7 Posted June 1, 2009 Share Posted June 1, 2009 Hi all, On my register script i want it to show what time and what date they registered at Register.php: <title>Regsiter</title><?php include("config.php"); //gets the config page if ($_POST[register]) { // the above line checks to see if the html form has been submitted $username = $_POST[username]; $password = $_POST[pass]; $cpassword = $_POST[cpass]; $email = $_POST[emai1]; //the above lines set variables with the user submitted information if($username==NULL|$password==NULL|$cpassword==NULL|$email==NULL) { //checks to make sure no fields were left blank echo "A field was left blank."; }else{ //none were left blank! We continue... if($password != $cpassword) { // the passwords are not the same! echo "Passwords do not match"; }else{ // the passwords are the same! we continue... $password = md5($password); // encrypts the password $checkname = mysql_query("SELECT username FROM users WHERE username='$username'"); $checkname= mysql_num_rows($checkname); $checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); $checkemail = mysql_num_rows($checkemail); if ($checkemail>0|$checkname>0) { // oops...someone has already registered with that username or email! echo "The username or email is already in use"; }else{ // noone is using that email or username! We continue... $username = htmlspecialchars($username); $password = htmlspecialchars($password); $email = htmlspecialchars($email); $ip = $_SERVER['REMOTE_ADDR']; //Everything seems good, lets insert. // the above lines make it so that there is no html in the user submitted information. //Everything seems good, lets insert. $query = mysql_query("INSERT INTO users (username, password, email, ip, regdate) VALUES('$username','$password','$email', '$ip', '$regdate')"); // inserts the information into the database. echo "You have successfully registered!"; } } } } else { // the form has not been submitted...so now we display it. echo (" <center> <form method=\"POST\"> Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\"><br /> Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"pass\"><br /> Confirm Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"cpass\"><br /> Email: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"emai1\"><br /> <input name=\"register\" type=\"submit\" value=\"Register\"> </form> </center> "); } ?> How could i make it so it show time and date the registered with london time? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/160536-joined-date/ Share on other sites More sharing options...
lonewolf217 Posted June 1, 2009 Share Posted June 1, 2009 something like this ? <?php date_default_timezone_set('GMT'); $regdate = date('l jS \of F Y h:i:s A'); Quote Link to comment https://forums.phpfreaks.com/topic/160536-joined-date/#findComment-847229 Share on other sites More sharing options...
Daniel0 Posted June 1, 2009 Share Posted June 1, 2009 1) Burn your book and buy a new one. The one you have is too old. If you are learning from a tutorial, find another one. 2) Logical OR is done using ||, not | which is bitwise OR. 3) Look up the words whitespace, readability and indentation (also see: http://en.wikipedia.org/wiki/Indent_style). 4) Array indices are done like $_POST['username'] not $_POST[username] unless username is a defined constant. 5) Look up the term "SQL injection" and realize that you need to use the function mysql_real_escape_string a number of times throughout your script. 6) htmlspecialchars() is irrelevant for inserting rows into a database. 7) You can use time or MySQL's NOW() function for inserting the registration date. I would advise having a field type like DATETIME and use MySQL's NOW(). Quote Link to comment https://forums.phpfreaks.com/topic/160536-joined-date/#findComment-847231 Share on other sites More sharing options...
Andy17 Posted June 1, 2009 Share Posted June 1, 2009 The place where you echo out your form, you could do that much easier: <?php // Shortened it a lot but I hope you get the point echo '<form method="POST">'; // Instead of echo "<form method=\"POST\">"; ?> That's a whole lot of escapes you got there, which is not necessary and also time consuming. Quote Link to comment https://forums.phpfreaks.com/topic/160536-joined-date/#findComment-847243 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.