Click to See Complete Forum and Search --> : Script Help (not working)


Jonathan
11-26-2003, 11:41 PM
I was wondering if there was anything wrong w/ my script... I can't seem to find it... help?


<?
#####################################
# Copyright (c) 2003 Crosspoint #
# All rights reserved... #
# Written by Jonathan #
# webmaster@crosspoint.org #
#####################################
include 'connect.php';

#####################################
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$phone = $_POST['phone_number'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$ip_addr = $_SERVER['REMOTE_ADDR'];
$date = now();
#####################################

if ((empty($fname)) || (empty($lname)) || (empty($phone)) || (empty($city)) || (empty($state)) || (empty($zip)) || (empty($email)) || (empty($password)) || (empty($password2)) || (empty($username))){
echo "Please enter all of the information";
include 'signup.html';
exit();
}

# Passwords
if ($password != $password2){
echo "Your passwords do not match.";
include 'signup.html';
exit();
}

# Usernames
if (ereg("([a-z,A-Z])"), $username){
echo "Please enter a valid username (all text, not letters / misc. symbols)";
include 'signup.html';
exit();
}

# First/Last Names
if ((strlen($fname) < 2) || (strlen($lname) < 2)){
echo "Please enter your full name";
include 'signup.html';
exit();
}

# Email Address
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $email)) {
return 1;
} else {
echo "Invalid e-mail.";
include 'signup.html';
exit();
}
if($email == "your@yourdomain.com"){
echo "Invalid e-mail.";
include 'signup.html';
exit();
}

# Phone Number
if(preg_match("/\d{3}(\w|-)?\d{3}(\w|-)?\d{4}\(w|-)?(\wext\w\d+/i", $phone)){
return 1;
} else {
echo "Invalid phone number";
include 'signup.html';
exit();
}
if($phone == "000-000-0000"){
echo "Please enter your phone number";
include 'signup.html';
exit();
}

# Convert & secure password...
$db_password = md5($password);

# Check for e-mail $ username
$check_user_text = mysql_query("select * from $table_name where username='$username'");
$check_user_in_db = mysql_num_rows($check_user_text);
$check_email_text = mysql_query("select * from $table_name where email='$email'");
$check_email_in_db = mysql_num_rows($check_email_text);

if (($check_email_in_db) == 0 && ($check_user_in_db == 0)){
$insert_query = "insert into $table_name (first_name,last_name,phone_num,city,state,zip,email,signup_date,activated,ip_address,username,passw ord)
values ('$fname','$lname','$phone','$city','$state','$zip','$email','$date','0','$ip_addr','$username','$db _password')";
$insert_action = mysql_query($insert_query);
$insert_id = mysql_insert_id();

##########################################################
### Emailing :::::::::::::::::::::::::::::::::::::::::::::
##########################################################
$subject = "Confirmation E-mail";
$message = "Dear $fname $lname,

Thank your for signing up for our Crosspoint Youth Affiliates website. We hope you will find whatever it is that you are looking for. If you would like to see something added to the site please contact the webmaster at webmaster@crosspoint.org. In order to log in you must complete this registration. To complete the registration please click below:

http://www.crosspoint.org/youth/members/activate.php?id=$userid&code=$db_password

*** If the above link is not clickable please copy and paste this into the address bar. ***

After you activate the account you can log in with the following information:

-------------------------------------
Username: $username
Password: $password
-------------------------------------

Thank you,
Webmaster
crosspoint.org

(This is an automated response, if you did not sign up for this then please ignore this email.)";

if(@mail($email,$subject,$message, "From: The Crosspoint Webmaster<webmaster@crosspoint.org>"){
echo "An e-mail has been sent to the e-mail specified. Please follow instructions on how to complete your registration.";
} else {
echo "An error has occured...";
}
##########################################################
##########################################################


} else {
echo "There was an error in creating your account... Such as the same e-mail is in our database, or the same username is in our database.";
include 'signup.html';
exit();
}

?>

Nevermore
11-27-2003, 08:21 AM
What's the problem - an error, or just doesn't work? Be specific.

Jonathan
11-27-2003, 09:09 AM
Sorry...

The script never finishes... When I run it it doesn't complete it at all... you can see a working thing here:

http://www.crosspoint.org/youth/members/signup.html

Nevermore
11-27-2003, 10:04 AM
Just flicking through, you need to get rid of the double quotes within the message variable because it was declared with them. Try that, if it doesn't work I'll try it out and debug it in more detail.

Jonathan
11-27-2003, 01:53 PM
oh my goodness... I didn't even notice that... lol... thanks. (I will test it soon, but first... TURKEY DAY! :) )

Jonathan
11-29-2003, 10:18 AM
nope.. it doesn't work...

Jonathan
11-29-2003, 10:35 AM
I have updated it... here:
<?
#####################################
# Copyright (c) 2003 Crosspoint #
# All rights reserved... #
# Written by Jonathan #
# webmaster@crosspoint.org #
#####################################
include 'connect.php';

#####################################
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$phone = $_POST['phone_number'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$ip_addr = $_SERVER['REMOTE_ADDR'];
$date = now();
#####################################

# Passwords
if ($password != $password2){
echo "Your passwords do not match.";
include 'signup.html';
exit();
}

# First/Last Names
if ((strlen($fname) < 2) || (strlen($lname) < 2)){
echo "Please enter your full name";
include 'signup.html';
exit();
}

# Email Address
if(!eregi('^[a-zA-z0-9_\-\.]+@[a-zA-Z0-9\-+\.[a-zA-Z0-9\-\.]+$', $email)) {
echo "Invalid email.";
include 'signup.html';
exit();
}

# Phone Number
if(!eregi("/\d{3}(\w|-)?\d{3}(\w|-)?\d{4}\(w|-)?(\wext\w\d+/i", $phone)){
echo "Invalid phone number";
include 'signup.html';
exit();
}

# Convert & secure password...
$db_password = md5($password);

# Check for e-mail $ username
$check_user_text = mysql_query("select * from youth_affiliates where username='$username'");
$check_email_text = mysql_query("select * from youth_affiliates where email='$email'");
$check_user_in_db = mysql_num_rows($check_user_text);
$check_email_in_db = mysql_num_rows($check_email_text);

if (($check_email_in_db == 0) || ($check_user_in_db == 0)){
$insert_query = "insert into youth_affiliates (first_name,last_name,phone_num,city,state,zip,email,signup_date,activated,ip_address,username,passw ord)
values ('$fname','$lname','$phone','$city','$state','$zip','$email','$date','0','$ip_addr','$username','$db _password')";
$insert_action = mysql_query($insert_query);
$insert_id = mysql_insert_id();

##########################################################
### Emailing :::::::::::::::::::::::::::::::::::::::::::::
##########################################################
$subject = "Confirmation E-mail";
$message = "Dear $fname $lname,

Thank your for signing up for our Crosspoint Youth Affiliates website. We hope you will find whatever it is that you are looking for. If you would like to see something added to the site please contact the webmaster at webmaster@crosspoint.org. In order to log in you must complete this registration. To complete the registration please click below:

http://www.crosspoint.org/youth/members/activate.php?id=$userid&code=$db_password

*** If the above link is not clickable please copy and paste this into the address bar. ***

After you activate the account you can log in with the following information:

-------------------------------------
Username: $username
Password: $password
-------------------------------------

Thank you,
Webmaster
crosspoint.org

(This is an automated response, if you did not sign up for this then please ignore this email.)";

if(@mail($email,$subject,$message, "From: The Crosspoint Webmaster<webmaster@crosspoint.org>"){
echo "An e-mail has been sent to the e-mail specified. Please follow instructions on how to complete your registration.";
} else {
echo "An error has occured... " . mysql_error();
}
##########################################################
##########################################################


} else {
echo "There was an error in creating your account... Such as the same e-mail is in our database, or the same username is in our database.";
include 'signup.html';
exit();
}

?>

Nevermore
11-29-2003, 02:17 PM
How much of the script executes? Does it give any clues as to what is causing it to stop?

Jonathan
11-29-2003, 03:02 PM
no... I have tried everything, even just for it to show an error... it just comes up blank

dreamcatcher
11-29-2003, 07:41 PM
Hi Jonathan,

I assume this code is what is on your enter_info.php page?

The form action part of your script is missing. ie:

if ($_POST['submit']) { code here }

Try the following:



<?
#####################################
# Copyright (c) 2003 Crosspoint #
# All rights reserved... #
# Written by Jonathan #
# webmaster@crosspoint.org #
#####################################
include 'connect.php';

#####################################

if ($_POST['submit']) {

$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$phone = $_POST['phone_number'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$ip_addr = $_SERVER['REMOTE_ADDR'];
$date = now();
#####################################

if ((empty($fname)) || (empty($lname)) || (empty($phone)) || (empty($city)) || (empty($state)) || (empty($zip)) || (empty($email)) || (empty($password)) || (empty($password2)) || (empty($username))){
echo "Please enter all of the information";
include 'signup.html';
exit();
}

# Passwords
if ($password != $password2){
echo "Your passwords do not match.";
include 'signup.html';
exit();
}

# Usernames
if (ereg("([a-z,A-Z])"), $username){
echo "Please enter a valid username (all text, not letters / misc. symbols)";
include 'signup.html';
exit();
}

# First/Last Names
if ((strlen($fname) < 2) || (strlen($lname) < 2)){
echo "Please enter your full name";
include 'signup.html';
exit();
}

# Email Address
if(ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)", $email)) {
return 1;
} else {
echo "Invalid e-mail.";
include 'signup.html';
exit();
}
if($email == "your@yourdomain.com"){
echo "Invalid e-mail.";
include 'signup.html';
exit();
}

# Phone Number
if(preg_match("/d{3}(w|-)?d{3}(w|-)?d{4}(w|-)?(wextwd+/i", $phone)){
return 1;
} else {
echo "Invalid phone number";
include 'signup.html';
exit();
}
if($phone == "000-000-0000"){
echo "Please enter your phone number";
include 'signup.html';
exit();
}

# Convert & secure password...
$db_password = md5($password);

# Check for e-mail $ username
$check_user_text = mysql_query("select * from $table_name where username='$username'");
$check_user_in_db = mysql_num_rows($check_user_text);
$check_email_text = mysql_query("select * from $table_name where email='$email'");
$check_email_in_db = mysql_num_rows($check_email_text);

if (($check_email_in_db) == 0 && ($check_user_in_db == 0)){
$insert_query = "insert into $table_name (first_name,last_name,phone_num,city,state,zip,ema il,signup_date,activated,ip_address,username,password)
values ('$fname','$lname','$phone','$city','$state','$zip ','$email','$date','0','$ip_addr','$username','$db_password')";
$insert_action = mysql_query($insert_query);
$insert_id = mysql_insert_id();

##########################################################
### Emailing :::::::::::::::::::::::::::::::::::::::::::::
##########################################################
$subject = "Confirmation E-mail";
$message = "Dear $fname $lname,

Thank your for signing up for our Crosspoint Youth Affiliates website. We hope you will find whatever it is that you are looking for. If you would like to see something added to the site please contact the webmaster at webmaster@crosspoint.org. In order to log in you must complete this registration. To complete the registration please click below:

<a href="http://www.crosspoint.org/youth/members/activate.php?id=" target="_blank">http://www.crosspoint.org/youth/mem...ctivate.php?id=</a>$userid&code=$db_password

*** If the above link is not clickable please copy and paste this into the address bar. ***

After you activate the account you can log in with the following information:

-------------------------------------
Username: $username
Password: $password
-------------------------------------

Thank you,
Webmaster
crosspoint.org

(This is an automated response, if you did not sign up for this then please ignore this email.)";

if(@mail($email,$subject,$message, "From: The Crosspoint Webmaster<webmaster@crosspoint.org>"){
echo "An e-mail has been sent to the e-mail specified. Please follow instructions on how to complete your registration.";
} else {
echo "An error has occured...";
}
##########################################################
##########################################################


} else {
echo "There was an error in creating your account... Such as the same e-mail is in our database, or the same username is in our database.";
include 'signup.html';
exit();
}

}

?>

Jonathan
11-29-2003, 07:48 PM
It still isn't working... the current code:<?
#####################################
# Copyright (c) 2003 Crosspoint #
# All rights reserved... #
# Written by Jonathan #
# webmaster@crosspoint.org #
#####################################
include 'connect.php';

#####################################

if ($_POST['submit') {

$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$phone = $_POST['phone_number'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$ip_addr = $_SERVER['REMOTE_ADDR'];
$date = now();
#####################################

if ((empty($fname)) || (empty($lname)) || (empty($phone)) || (empty($city)) || (empty($state)) || (empty($zip)) || (empty($email)) || (empty($password)) || (empty($password2)) || (empty($username))){
echo "Please enter all of the information";
include 'signup.html';
exit();
}

# Passwords
if ($password != $password2){
echo "Your passwords do not match.";
include 'signup.html';
exit();
}

# Usernames
if (ereg("([a-z,A-Z])"), $username){
echo "Please enter a valid username (all text, not letters / misc. symbols)";
include 'signup.html';
exit();
}

# First/Last Names
if ((strlen($fname) < 2) || (strlen($lname) < 2)){
echo "Please enter your full name";
include 'signup.html';
exit();
}

# Email Address
if(ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)", $email)) {
return 1;
} else {
echo "Invalid e-mail.";
include 'signup.html';
exit();
}
if($email == "your@yourdomain.com"){
echo "Invalid e-mail.";
include 'signup.html';
exit();
}

# Phone Number
if(preg_match("/d{3}(w|-)?d{3}(w|-)?d{4}(w|-)?(wextwd+/i", $phone)){
return 1;
} else {
echo "Invalid phone number";
include 'signup.html';
exit();
}
if($phone == "000-000-0000"){
echo "Please enter your phone number";
include 'signup.html';
exit();
}

# Convert & secure password...
$db_password = md5($password);

# Check for e-mail $ username
$check_user_text = mysql_query("select * from $table_name where username='$username'");
$check_user_in_db = mysql_num_rows($check_user_text);
$check_email_text = mysql_query("select * from $table_name where email='$email'");
$check_email_in_db = mysql_num_rows($check_email_text);

if (($check_email_in_db) == 0 && ($check_user_in_db == 0)){
$insert_query = "insert into $table_name (first_name,last_name,phone_num,city,state,zip,ema il,signup_date,activated,ip_address,username,password)
values ('$fname','$lname','$phone','$city','$state','$zip ','$email','$date','0','$ip_addr','$username','$db_password')";
$insert_action = mysql_query($insert_query);
$insert_id = mysql_insert_id();

##########################################################
### Emailing :::::::::::::::::::::::::::::::::::::::::::::
##########################################################
$subject = "Confirmation E-mail";
$message = "Dear $fname $lname,

Thank your for signing up for our Crosspoint Youth Affiliates website. We hope you will find whatever it is that you are looking for. If you would like to see something added to the site please contact the webmaster at webmaster@crosspoint.org. In order to log in you must complete this registration. To complete the registration please click below:

<a href="http://www.crosspoint.org/youth/members/activate.php?id=" target="_blank"><a href="http://www.crosspoint.org/youth/mem...ctivate.php?id=" target="_blank">http://www.crosspoint.org/youth/mem...ctivate.php?id=</a></a>$userid&code=$db_password

*** If the above link is not clickable please copy and paste this into the address bar. ***

After you activate the account you can log in with the following information:

-------------------------------------
Username: $username
Password: $password
-------------------------------------

Thank you,
Webmaster
crosspoint.org

(This is an automated response, if you did not sign up for this then please ignore this email.)";

if(@mail($email,$subject,$message, "From: The Crosspoint Webmaster<webmaster@crosspoint.org>"){
echo "An e-mail has been sent to the e-mail specified. Please follow instructions on how to complete your registration.";
} else {
echo "An error has occured...";
}
##########################################################
##########################################################


} else {
echo "There was an error in creating your account... Such as the same e-mail is in our database, or the same username is in our database.";
include 'signup.html';
exit();
}

}

?>

dreamcatcher
11-29-2003, 07:50 PM
Sorry, I edited it after you tried it.

if ($_POST['submit') {

should be:

if ($_POST['submit']) {

I forgot a square bracket. Hope that works.

Jonathan
11-29-2003, 07:54 PM
nope... still not working

dreamcatcher
11-29-2003, 07:59 PM
Strange. Ok, something else to try.

Change your form action to:

<form method="POST" action="enter_info.php?action=signup">

then at the top of your file, change:

if ($_POST['submit']) {

to:

if ($_REQUEST['action'] == "signup") {

Try that!!

Jonathan
11-29-2003, 08:03 PM
nope...

dreamcatcher
11-29-2003, 08:06 PM
This might seem like a silly question, but does your server actually support PHP?

Jonathan
11-29-2003, 08:07 PM
yes

dreamcatcher
11-29-2003, 08:16 PM
Ok. A simple thing to try is to change the <? to <?php at the top of your page. Shouldn`t make a difference but you never know.

You could add the php to your signup.html page, rename is with a .php extension, then change the form action to:

<form method="post" action="<? echo $PHP_SELF; ?>"

But to be honest if the external file isn`t working, I can`t see this working either.

I`m a little stumped I`m afraid.

Jonathan
11-29-2003, 08:24 PM
This is hard... it didn't work any of it

dreamcatcher
11-29-2003, 08:28 PM
Just one final thing, on your signup.html page you don`t have a closing form tag:

</form>

Try adding that somewhere after the form and see if that works.


<td><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>

Jonathan
11-29-2003, 08:33 PM
thanks for the help, but it isn't working...

dreamcatcher
11-29-2003, 08:35 PM
Sorry I couldn`t be of any help!

:(

Jonathan
11-29-2003, 08:35 PM
ptell you were a help... I didn't know of all of that stuff

Nevermore
11-30-2003, 02:53 AM
Doesnone of it work, or does it fail somewhere specific?

dreamcatcher
11-30-2003, 04:03 AM
Ok, a new day, new ideas! :)

There isn`t much error checking in your .php file, so it may be something to do with part of the syntax. So, do the following:

Underneath the <? at the top of your file add:

error_reporting (E_ALL ^ E_NOTICE);

Then, change your mysql queries to:


$check_user_text = mysql_query("select * from $table_name where username='$username'") or die(mysql_error());
$check_user_in_db = mysql_num_rows($check_user_text);
$check_email_text = mysql_query("select * from $table_name where email='$email'") or die(mysql_error());
$check_email_in_db = mysql_num_rows($check_email_text);


Then access your enter_info.php in your browser and see if you see any error messages. I`m just wondering about the variables for the table name.

Jonathan
01-07-2004, 08:13 PM
Thanks for all of your help. I finally have the script running. :) I found I accidentally missed a "}" in another file :P Sorry for the long response