I'm wondering how to make a page where people can register. I know the seperate basics, I know for example:
- how to make a form that upon submitting creates new entries in a tabel (using INSERT INTO)
- how to make a contact form that emails information to an e-mail adress provided
- how to validate the contact form
What I want to be able to do is this, I want a form with the fields: username, password and e-mail adress. When pressing the submit button I want this to happen:
- the form to be validated (including true e-mail adress validation)
(- if validation fails, echo the error messages at the fields where validation failed (example: "You did not provide a valid e-mail adress"))
- the information entered must be sent to the e-mail adress provided so that a visitor has their password saved
- when done, the script should redirect the visitor to a new page within the site, LOGGED IN
now what I don't know is, how do I (roughly) order everything? As in: in what order should I write the PHP parts or should I spread these actions over several scripts? Also I'm not the greatest with all the if / else tags. How do I make sure that everything goes the way I want it? Anything would help, being it a complete script (easiest ) or a quick sketch in paint. So this is what I need:
CHECK if form is filled in correctly
IF it is not filled correctly, echo errors
[i](this just came to my mind, I also want to make sure that the user came from my site so that it is not a spambot, using:
Code
<?php
$previous_url = getenv("HTTP_REFERER");
if ($previous_url != "http://www.example.com/register.html") {
echo "You can't call this script from a different location";
exit;
}
?>
IF filled correctly, e-mail information to e-mail adress provided (using $POST[visitormail] for example)
REDIRECT to new page
This is for a class right? Unluckily for you, I won't give you the answers , I will give you bits and pieces to get you on the right path. Let me remind you if you didn't know or forgot: http://www.php.net is the prime resource for functions and such.
Let's break the problem into parts.
True email validation: This is not that difficult. You can only really test the DNS records of the domain name to see if there is a MX record. Use this function: http://us2.php.net/manual/en/function.checkdnsrr.php You will need to strip out the domain name off the email by using a regex, but that is pretty simple.
Now, logistically, all these functions should be in a separate function file and you would just call the function...
Code
//functions.php
<?PHP
function checkemail($email)
{
//this function will check the dns records of the email address
//It will return true or false
/*
Bla bla bla
*/
return 1;
}
?>
Code
<?PHP
//Calling page...
include('functions.php'); //Grab the functions
//Got email address from form.
//Does it have extra slashes in it?
$email=stripslashes($_POST['email']);
if(!checkemail($email))
{
exit('Email address is invalid');
}
?>
You can then reuse these functions anywhere you want.
The last bit about the referrer is a bit strange when put into practice. You're better off displaying a simple math problem and having the user answer it... Like what is 2+2? That will defeat the bots. You can also use session and tons of other stuff.
I know I'm vague. If you need actual code samples, just ask and I will show them.
2014 is going to be a good year. More content, more streamlining. Be a part of history!
Hey Aron, thanks a bunch and I'm sorry for my late reaction. I've been busy designing a flyer over the last few hours - so many things on my mind!
I'll take an indepth look to your answer and the links you provided now, I'll let you know once I've finished or if I'm still having trouble .
The idea of comparing the referrer site and the correct referrer was in my PHP book, I think it's good enough for the assignment in class .
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
include "function.php";
kader("TEST");
?>
</body>
</html>
I'm progressing really slow due to a lot of other work AND personal issues also . Once more, thanks for your time though! Also on a side note, would you mind closing Photoshop This! on agfx and making a new one? I'm really sorry but I'm not sure if I have the time searching for a new picture.
I've also stumbled upon a new problem. My teacher tried explaining this to me but it still seems pretty abstract to me.
What I'm basically making is a time scheme for a anniversary festival. The acts playing on the festival will have different genres such as music, dance, theatre etc.
When drawing the table, using for example SELECT * FROM acts WHERE day = thursday, I want every table row (<tr> to have a CSS class corresponding with the genre of that act. So that the rows for all music acts would have for example a green background and white text, whereas the dance rows could have a red background and black text.
If you could help me by giving the code for two different genres with very minimalistic CSS (for example only background: #COLOR) I'm sure I could do the rest .
That one is very simple... We'll just do inline css:
Code
<table>
<tr style="background:#00f; color:#fff;"><!-- Start of row: Background is totally blue and text color is white-->
<td>bla bla bla</td>
</tr>
<tr style="background:#f00; color:#0ff;"><!-- Start of row: Red background, text is tealish. -->
<td>Bla bla bla bla</td>
</tr>
</table>
That's an example of inline styles. You can just paste that code in an html page to see how it renders.
2014 is going to be a good year. More content, more streamlining. Be a part of history!
Heh I know that much mate . But for that to work I'd have to know exactly what time plan entries I have.
Now imagine the administrator submitting new acts in the backoffice!
I've managed to make it so that it'll display everything in the correct order (SORT BY time ASC) but I have to make sure that new entries submitted get the right CSS to go along with them (corresponding with the genre) .
I'm not sure if his code is 100% right but the idea seems simpler then yours, right? . I'm going to give his idea a try now, see if I get it to work.
Main problem is that we both are suckers with SQL, I wonder how to make it that $genre is loaded from the database properly, as well as the content for every td.
And when I've got round to doing it, I'll have to put it in an array as well.
And then make it sure that it's sorted by time O.o
Example. To fetch data from your table with database name 'test' and username 'user' with password 'pass' from table 'data'...
Code
<?PHP
if(!mysql_connect ( 'localhost','user','pass')) //Connect to database or die
{
die('There was a problem connecting to the database';
}
if (!mysql_select_db('test'))
{
echo "Unable to select test: " . mysql_error();
exit;
}
$sql ='SELECT * FROM data';
$result = mysql_query($sql); //Send query
if (!$result) //Bad query
{
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) //No results
{
echo "No rows found, nothing to print so am exiting";
exit;
}
while ($row = mysql_fetch_assoc($result))
{
print_r($row);
}
mysql_free_result($result); //Release mysql result
mysql_close();
?>
2014 is going to be a good year. More content, more streamlining. Be a part of history!
Ah thanks mate, these functions have helped me! I've now managed to leech stuff out of the database and display it on screen, now I'm going to try changing the layout with CSS depending on the output data.