PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?
include 'db.php';
# grab the POST variables from the HTML form
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$password = $_POST['password'];
# Any escaped characters?
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$password = stripslashes($password);
# Any errors in the posted fields?
if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information! <br />';
if(!$first_name){
echo "First Name is a required field. Please enter it below.<br />";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.<br />";
}
if(!$username){
echo "Desired Username is a required field. Please enter it below.<br />";
}
include 'signup.php';
exit();
}
# does this user already exist in the database?
$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if(($email_check > 0) || ($username_check > 0)){
echo "Please fix the following errors: <br />";
if($email_check > 0){
echo "<strong>Your email address has already been used by another member in our database. Please use a different email address!<br />";
unset($email_address);
}
include 'signup.php'; // Shows the form again!
exit();
}
# Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, signup_date);
if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
$userid = mysql_insert_id();
// Let's mail the user!
$subject = "Your 4Boredom.com Membership";
$message = "Dear $first_name $last_name,
You are now registered at our website, http://www.4boredom.com!
You are now able to login with the following information:
Username: $username
Password: $password
Please keep this username and password in a location that is easily accessible by you.
Thanks!
Derek Lemire
4boredom.com
This is an automated response, please do not reply!";
mail($email_address, $subject, $message, "From: MyWebSite<derek@4boredom.com>\nX-Mailer: PHP/" . phpversion());
echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
}
?>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
now is this right for the databasE? I still get errors?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
now is this right for the databasE? I still get errors?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color][/quote]
try
mysql_connect()
<?
include 'db.php';
# grab the POST variables from the HTML form
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$password = $_POST['password'];
# Any escaped characters?
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$password = stripslashes($password);
# Any errors in the posted fields?
if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information! <br />';
if(!$first_name){
echo "First Name is a required field. Please enter it below.<br />";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.<br />";
}
if(!$username){
echo "Desired Username is a required field. Please enter it below.<br />";
}
include 'signup.php';
exit();
}
# does this user already exist in the database?
$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if(($email_check > 0) || ($username_check > 0)){
echo "Please fix the following errors: <br />";
if($email_check > 0){
echo "<strong>Your email address has already been used by another member in our database. Please use a different email address!<br />";
unset($email_address);
}
include 'signup.php'; // Shows the form again!
exit();
}
# Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, signup_date)");
if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
$userid = mysql_insert_id();
// Let's mail the user!
$subject = "Your 4Boredom.com Membership";
$message = "Dear $first_name $last_name,
You are now registered at our website, http://www.4boredom.com!
You are now able to login with the following information:
Username: $username
Password: $password
Please keep this username and password in a location that is easily accessible by you.
Thanks!
Derek Lemire
4boredom.com
This is an automated response, please do not reply!";
mail($email_address, $subject, $message, "From: MyWebSite<derek@4boredom.com>\nX-Mailer: PHP/" . phpversion());
echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
}
?>
<?php
$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, signup_date) VALUES (ADD THE SUPPLIED DATA HERE)") or die("There was an error: " . mysql_error());
?>
What does add the supplied data here mean? Sorry im a little new lol..
I also looked back and realized that the sql database i set up is under mysite_main but with the table users. I do not have the table users anywhere in the code, should that be put somewhere?
Sorry, that was meant to be whatever data you planned on entering into your database.
As a suggestion, you may want to pick up a tutorial or two on interacting PHP with databases. There is a strict syntax to follow when issue SQL commands that you are going to want to know before getting into something like a registration script.
Briefly, a MySQL insert SQL statement looks something like this...
4Boredom wrote:anyone know where I can go for cheap tech support for this? I can pay just not like 100 an hour like some will charge hehe im a college kid
If you want to hire someone to do this, people can make you offers in the Job Hunt forum.. if your lucky someone may do it for you in the Volunteer forum if your unwillinging to keep taking stabs at it.