Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/160536-joined-date/
Share on other sites

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().

Link to comment
https://forums.phpfreaks.com/topic/160536-joined-date/#findComment-847231
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/160536-joined-date/#findComment-847243
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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