Jump to content

learning area


Recommended Posts

Ok I have actually tried for my first major script, I was doing great, I followed some advice, put together my own ideas into it, and came up with the perfect solution for validation and email, now I was trying to get a little fancier and throw in some other stuff, I also upgraded the way I coded xhtml/css and started doing it more neat, and more commented, on my site I said that that's what I believe, and I was trying now to go even further, I also read a post on here from someone named crayon violent and I started following advice so far as far as general structuring of php and it's helped a lot, I know I am not that good at structuring it yet but I will get better. Here is the problem I am encountering, and need help with.

<?phpif (isset($_POST['subscribe'])){	$error = ''; if ($_POST['name'] == '') {	$error[] .= print 'The name field was filled in incorrectly, please correct<br/>'; }if ($_POST['email'] == '') {	$error[] .= print 'The Email Field was filled in incorrectly, please correct.<br />'; }if ($_POST['verifyemail'] != $_POST['email']) {	$error[] .= print 'The email Fields Do Not match, please correct.<br />'; }if (is_array($alert)) {	foreach($error as $key => $correctthis) {	echo '$correctthis'; >>> }else{ $connection = mysql_connect('localhost', 'cantsay, 'definitelynote'); $selectdb = mysql_select_db('stillalittletoomuchinfo');  if(!$connection && !$selectdb){	print 'Problem during database connection or selection';	}else {	$insert = 'INSERT INTO cantsaytablename (name, email) VALUES ("{$_POST[name]}", "{$_POST[email]")'; 	}if(!mysql_query($insert)){	print 'The information could not be inserted into the database';	}else{	echo 'successfuly completion of all processes';free();disconnect(); }};

It tells me that the else statement isn't good on a specific line, here is the error.

Parse error: parse error, unexpected T_ELSE in /home/all/funnyemailforwards/public_html/dbprocessing/signuphandler.php on line 13
I marked the line in the php. I am trying to create a double contact form, but there's nothing to see in the php file, and I was so damn stupid I just about left my password and username, and database name in the code, that would have been very very bad. But anyway what I was wondering is a few things, I marked the line the error is coming from in the code with a >>>.What I need to figure out is, well I am setting up a subscribe and unsubscribe for a newsletter, so people can enter there email address to recieve the funny emails, right now I am trying to set the script for if they click submit on subscribe, that works, it validates, my error statement I took from all this worked out as well. I got all that, but when I started adding in database code I can't get it working. What I need help with is what am I doing wrong, I also need to somewhere wire in there, something to still email it to him, I am wanting to email him if the WHOLE process is successful for instance, if the error validation passes, the and all the database processes finish, then it send an email, then close the database and free. The questions I want to ask is why isn't this working here, how do I try and wire in the mail function properly. What about free and disconnect() how do I specify the connection I want closed. Do I need to do anything like remove slashes or anything specific before database entry that I am forgetting, The reason I am asking is magic quotes is on, I checked on his database phpinfo() information. But what I am wondering is are there any suggestions on1. why this isn't working.2. How to make it work.3. How to integrate the mail program, and properly free and close the database connection.4. ANY AND ALL advice about how I could do this differently, better ways to do certain parts, ANYTHING that involves advice on new ways to do this or anything.5. IF there is ANYTHING I can POSSIBLY do to add any more security to this script when it's complete, I am trying to learn a ###### of a lot at once, once I get this script to work, I am writing one below it for isset($_POST['unsubscribe']))and doing exactly the same thing for it, except removing the database information instead, any advice would be great, I am at a critical learning point, to where I have almost pulled over the learning curve, and most of all I am starting to get new scripts ideas, how to work things differently, I am almost finally over that hump, any help would be appreciated.
Link to comment
Share on other sites

I made a lot of changes to your code. #1 is the formatting, you need good formatting, it shouldn't even be an option. Don't stack if or else statements onto the end of other ones, just use the next line. And indent! Also, you don't need a semicolon after a curly bracket ("}") except for specific things like a "do" loop.

if (isset($_POST['subscribe'])){  $error = "";  if ($_POST['name'] == '')    $error .= 'The name field was filled in incorrectly, please correct<br/>';  if ($_POST['email'] == '')    $error .= 'The Email Field was filled in incorrectly, please correct.<br />';  if ($_POST['verifyemail'] != $_POST['email'])    $error .= 'The email Fields Do Not match, please correct.<br />';  if ($error != "")    echo $error;  else  {    $connection = mysql_connect('localhost', 'cantsay', 'definitelynote');    $selectdb = mysql_select_db('stillalittletoomuchinfo');    if(!$connection || !$selectdb)    {      echo 'Problem during database connection or selection';      echo mysql_error();    }    else    {      $insert = "INSERT INTO cantsaytablename (name, email) VALUES ('" . mysql_escape_string($_POST['name']) . "', '" . mysql_escape_string($_POST['email']) . "')";      if(!mysql_query($insert))        echo 'The information could not be inserted into the database';      else        echo 'successfuly completion of all processes';    }    @mysql_close($connection);  }}

See how much easier that is to read and understand? I also replaced all your print statements with echo statements, and these lines didn't make sense:$error[] .= print 'The name field was filled in incorrectly, please correct<br/>';You initialized $error as a string, but that statement is using it as an array (the sqare brackets on the end indicate that). Also, you don't need a print or echo there at all, all you want to do is concatenate the string onto the $error variable. So you can see how I rewrote those.The error you were getting is because you left out a closing }. This probably would have been more obvious if the code was formatted better.I also took out your foreach loop, and just printed $error directly. It does the same thing, but only uses 1 line of code.To close a mysql connection you use mysql_close, and I moved that to the end of your else block and put a @ symbol before it to suppress error messages. If the connection was never opened in the first place, it will not bother to print an error, or else it will close it. You don't need to use mysql_free_result because you aren't working with a result set (those come from SELECT statements).I also redid your SQL query to escape your form variables. You need that unless you want to get your database messed with. You never want to insert anything from GET or POST directly into a SQL statement without escaping it or otherwise validating it. You do check the values, but you never sanitize them for illegal characters.I also made this an OR instead of an AND, and added the error to the output:if(!$connection || !$selectdb)The only other thing I did was remove the curly brackets around 1-line IF or ELSE statements, if there is only 1 line you don't need them. I think that's about it. If you want to add email, head over to php.net and search for the "mail" function.

Link to comment
Share on other sites

I really really want to thank you for all the help so far, It worked perfectly I just had some questions about some of these things, there are other ways to do this, but like what, should I choose these are permanent ways or play around with these until I understand more of what I am doing.Ok here is what i needed to ask.

I made a lot of changes to your code. #1 is the formatting, you need good formatting, it shouldn't even be an option. Don't stack if or else statements onto the end of other ones, just use the next line. And indent! Also, you don't need a semicolon after a curly bracket ("}") except for specific things like a "do" loop.
I looked at your formatting, was the way I was formatting bad, I looked over the way you indented and I will take that example. And try to conform to it from now on, are there any other ways I can be more readable as well, any advice from anyone would be greatly appreciated too.
See how much easier that is to read and understand? I also replaced all your print statements with echo statements, and these lines didn't make sense:
I have heard alot about this before, what are the difference's between print and echo.
To close a mysql connection you use mysql_close, and I moved that to the end of your else block and put a @ symbol before it to suppress error messages. If the connection was never opened in the first place, it will not bother to print an error, or else it will close it. You don't need to use mysql_free_result because you aren't working with a result set (those come from SELECT statements).
I don't fully understand the @ symbol what is it used for and what did you mean by saying that if it never opened it wouldn't close in the first place, do you mean if it doesn't pass validation it won't matter.
I also redid your SQL query to escape your form variables. You need that unless you want to get your database messed with. You never want to insert anything from GET or POST directly into a SQL statement without escaping it or otherwise validating it. You do check the values, but you never sanitize them for illegal characters.
a few things with this, first I searched it on php.net and came up with this.
mysqli_escape_string -- Alias of mysqli_real_escape_string()
I checked that and didn't understand it can you explain that too me, and what's the difference between what you used and this other one, the main other thing I am wondering about, is the server I am using, has only php 4 something and this said php 5 in php.net why is it still working when I am using php 4.
The only other thing I did was remove the curly brackets around 1-line IF or ELSE statements, if there is only 1 line you don't need them. I think that's about it
What do you mean.What I don't understand here more than anything is you said something that sort of took me off guard. And I don't get someting, you said I don't have to close control structures, but before when I tried doing that I always got errors when I didn't. I dont understand this.
And indent! Also, you don't need a semicolon after a curly bracket ("}") except for specific things like a "do" loop.
Can you explain to me what you mean before when I left them off I got errors, you mean all this time, with if, elseif, else, statements, and otehr things I never have to close the ; even at the very very end of all the control structures. If so why has everyone corrected me before when I left those off, or encountered an error they said that it's because of that, I fix it and it works again, I am a little confused about this one.Thanks for all the help I really appreciate it, any other advice opinions about all this accepted too, thanks again.
Link to comment
Share on other sites

should I choose these are permanent ways or play around with these until I understand more of what I am doing.
There are plenty of ways to do most things, just use the one that makes the most sense to you. In some situations, one way might be better, you just need to learn what to look for.
I looked at your formatting, was the way I was formatting bad
Technically, it's no different, it's just a lot harder to read and understand. Especially when you are dealing with scope blocks like loops or if statements.
I have heard alot about this before, what are the difference's between print and echo.
There aren't many, but you were using both, so you might as well be consistent.
I don't fully understand the @ symbol what is it used for and what did you mean by saying that if it never opened it wouldn't close in the first place
The @ symbol causes errors to be ignored.http://www.php.net/manual/en/language.oper...rrorcontrol.phpIf there was an error opening the database connection, and it never opened, trying to close it would produce an error. So by using the @ sign, you can just try to close it and if it's not open it won't produce an error.I wasn't using mysqli_escape_string, I was using mysql_escape_string. The mysqli functions are "improved mysql" functions available in PHP 5.What I mean about 1-line if statements and scope blocks, assume you have this:
if (condition){  statement1  statement2  statement3}

The curly braces signify that all 3 statements are a part of the IF block. But if you only have one statement, you can write it like this:

if (condition)  statement

There is also a shorthand for if-else statements. These two are identical:

if (condition)  statement1else  statement2(condition ? statement1 : statement2);

you said I don't have to close control structures, but before when I tried doing that I always got errors when I didn't.
You don't, I don't know why you were getting errors. The only control structure you need to explicitly terminate with a semicolon, if I remember correctly, is a do-while loop:
<?php$i = 0;do {   echo $i;} while ($i > 0);?>

Can you explain to me what you mean before when I left them off I got errors, you mean all this time, with if, elseif, else, statements, and otehr things I never have to close the ; even at the very very end of all the control structures.  If so why has everyone corrected me before when I left those off, or encountered an error they said that it's because of that, I fix it and it works again, I am a little confused about this one.
I don't know, I don't think those people know what they were talking about. I have never used a semicolon after a closing } for an if statement in anything.
Link to comment
Share on other sites

Ok THat makes sense now, I had one question how do I put form variables into an email, this is what i had, at the end I have it sending 2 seperate different emails perfectly I am surprised I got it on the first try, but what I am trying to do is add in some of the form variables where it shows I tried at. How do I add those in.

     if(!mysql_query($insert))       echo 'The information could not be inserted into the database';     else       $name = $_POST['name'];    $email = $_POST['email'];    $to = 'businessman332211@hotmail.com';    $subject = 'Funny Email Forwards Sign up Notification';    $message = 'Yhis is a confirmation to inform you that/n';    $message .= 'you have been signed up to the Funny Email Forwards/n';    $message .= 'Newsletter.  If you choose to unsubscribe please visit/n';    $message .= 'The website again to unsubscribe.';   if(mail($to, $subject, $message))    echo 'The email was sent Successfully<br />';    $to = 'businessman332211@hotmail.com';    $subject = 'Funny Email Forwards sign up';    $message = 'This is a notification letting you know that {$name) has';    $message .= 'signed up to the news letter using {$email}';   if(mail($to, $subject, $message))   echo 'The confirmation was sent to bobby';   }   @mysql_close($connection); }}

I also wanted to ask about that mysql_escape_stringHow do I use it, like do I use it in that manner every single time I enter it into a database, what does it do, the reason i am asking i didn't know anything about that before then, are there other ways as well to pass it into a database without causing problems, or is this the way that it should always be done.

Link to comment
Share on other sites

You have {$name) there instead of {$name}. Also, you cannot do variable replacement with a single-quoted string, put your message in double-quotes instead.You will want to use mysql_escape_string like I showed, it should be used any time you are putting POST or GET values directly in a query. Apparently it's deprecated though, I guess they want you to use this one instead:http://www.php.net/manual/en/function.mysq...cape-string.phpYou can read that page, including the comments, to get a good idea about why you are supposed to use it, but it helps guard against SQL injection attacks.The only time you wouldn't need to use it is if you are transforming the data between the time you get it from POST and when you use it in the query. Like this would be safe:

$id = intval($_POST['id']);

Since you use intval, you know that $id is an integer, so you don't need to escape it. But you can't trust data coming directly from GET or POST.

Link to comment
Share on other sites

But even so, every time you insert a string of text instead of a number or boolean, you will still want to escape it, just incase the string has any single quotes in it that would mess with the SQL query.

Link to comment
Share on other sites

Ok THat worked I just have to play with it, so now, about what do you think about single or double quotes, I think double now, but what is your opinion, or whoever else has anything to say about anything. I also wanted to ask now, I tried putting both <br />and /n into my email and have it send some cuts in the text, I never had a problem with this before because normally I format like$message = "Whatever I have here for like 10 linesdowndowndowndownand so on";And that is what I normally use but I don't know how to do this when I am trying to set it up like this.

Link to comment
Share on other sites

I believe that in the book Programming PHP, they say to use single quotes for general situations, and double quotes where you need to use escape characters (\n, \r, \t, etc) or variable replacement, but I just pretty much do everything in double quotes. There might be some overhead involved with double quotes, but if there is, it is insignificant. Even so, just understand that double quotes will evaluate things like variables, so if you want to print an actual variable name out (echo '$var':) then you will want to use single quotes. But I pretty much take the view that I use double-quotes for the general case, and single quotes only where I need them.<br> is only for HTML-formatted text. A general line-break is the \n character, so if you are sending plain-text email, you will want to use \n. This will print on multiple lines:$message = "line 1\nline 2\nline3";You don't need to escape anything going through email, the only reason you escape text going into SQL is because if you don't, someone could use a cleverly-formatted input to run their own SQL statement. Like if you have a statement like this:SELECT * FROM users WHERE id='{$_POST['user']}' AND password='{$_POST['password']}'Someone could log in as anyone they want if they write this out in the password field:' OR ''='Because when you replace that with the POST variable, the SQL statement looks like this:SELECT * FROM users WHERE id='justsomeguy' AND password='' OR ''=''Since '' always equals '', they will be logged in under whatever account they choose. This doesn't matter with email, because email is just text, SQL is more of a command.

Link to comment
Share on other sites

Well, you're asking a lot of questions about what is better. That all depends what you want to do. If you want your application to quit when an error happens, then use Die. If you don't, if you want to log the error in a database or something and show the user that something happened and give them a choice what they want to do, then you'll probably want to write your own function for handling errors.

What other functions can I use in place of what you said, what all are available because I see a lot of other people not doing this, or something else, just trying to learn from this as much as I can as I go along.
If you are talking about escaping characters for SQL statements, I'm sure you can use regular expressions to escape specific characters, or write your own function to do something like that, or you can use the built-in function I gave you.The bottom line is that there is no one way that is always right or always the best. It depends what you want your application to do. If there is a built-in PHP function to do what you want to do, that's a good thing, or else you can write your own instead.With regard to newlines, this does work:echo "line 1\nline 2\nline 3";Put that in a file, then view the source (HTML does not render newlines as line breaks, only <br> tags). When you view the source, you will see that each of those newline characters creates a newline.If you want to see the line breaks rendered in HTML, you can do this:echo nl2br("line 1\nline 2\nline 3");nl2br converts newlines into <br> tags.
Link to comment
Share on other sites

How do I change this to utilize OR DIE statementsJust a rough idea will allow me to use it

<?phpif (isset($_POST['subscribe'])){ $error = ""; if ($_POST['name'] == '')   $error .= 'The name field was filled in incorrectly, please correct<br/>'; if ($_POST['email'] == '')   $error .= 'The Email Field was filled in incorrectly, please correct.<br />'; if ($_POST['verifyemail'] != $_POST['email'])   $error .= 'The email Fields Do Not match, please correct.<br />'; if ($error != "")   echo $error; else {   $connection = mysql_connect('######', '######', '######');   $selectdb = mysql_select_db('cantsay');   if(!$connection || !$selectdb)   {     echo 'Problem during database connection or selection';     echo mysql_error();   }   else   {     $insert = "INSERT INTO notell (name, email) VALUES ('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['email']) . "')";     if(!mysql_query($insert))       echo 'The information could not be inserted into the database';     else       $name = $_POST['name'];    $email = $_POST['email'];    $to = 'businessman332211@hotmail.com';    $subject = 'Funny Email Forwards Sign up Notification';    $message = "This is a confirmation to inform you that";    $message .= "you have been signed up to the Funny Email Forwards";    $message .= "Newsletter.  If you choose to unsubscribe please visit";    $message .= "The website again to unsubscribe.";    $message = wordwrap($message);   if(mail($to, $subject, $message))    echo "You have been subscribed successfully<br />";   else   echo "There was an error sending an email";   }   @mysql_close($connection);   $to = "businessman332211@hotmail.com";    $subject = "Funny Email Forwards sign up";    $message = "This is a notification letting you know that {$name} has";    $message .= "signed up to the news letter using {$email}.";    $message .= "notification is coming from Funny Email Forwards.com";    $message = wordwrap($message);    mail($to, $subject, $message); }}?>

Link to comment
Share on other sites

That depends where you want it to quit. Some people do things this way:$connection = mysql_connect('######', '######', '######') or Die (mysql_error());$selectdb = mysql_select_db('cantsay') or Die (mysql_error());

Link to comment
Share on other sites

Here is the original line:$insert = "INSERT INTO cantsaytablename (name, email) VALUES ('" . mysql_escape_string($_POST['name']) . "', '" . mysql_escape_string($_POST['email']) . "')";The line is building a string. In this case, the string holds a SQL query, but it's just a string. The point is to produce a string that looks like this:INSERT INTO table (name, email) VALUES ('steve', 'steve@test.com')So we can substitute variable names in there so you can see what we are replacing:INSERT INTO table (name, email) VALUES ('$var1', '$var2')Now, since the entire string is surrounded by double quotes, in order to close the string and call the msql_escape_string function, you add in the double quotes, and then the period to join the strings.INSERT INTO table (name, email) VALUES ('" . mysql_escape_string($var1) . "', '" . mysql_escape_string($var2) . "')You are essentially replacing the variable like $var1 with the text (" . mysql_escape_string() . "). The double quotes close the string and then reopen it again after the function call, and the single quotes need to surround the string inside the SQL query.

Link to comment
Share on other sites

oh ok, I had one more question, I finished my entire script, below is what it looks like, how do I test to see if something exists in a database, I am almost done with half of my script, after this I start on my part of my script that handle's unsubscribe. After that I am done with this part of the website, I need to check the database, to prevent something from going in there 2 times, this took me awhile to get but here is what I have so far, and it all works perfectly, and all the error handling and everything works 100% as expected and I learnt more than I ever thought possible.

<?php// This is a page that holds 2 different scripts, this completely controls the results coming from the form on signup.php, the purpose of these 2 scripts is to detect which button was pressed, if subscribe was pressed the top set of scripts under the giant if statement run.  If unsubscribe is pressed then the if statement corresponding to unsubscribe is ran.// Begin subscribe scriptif (isset($_POST['subscribe'])) {  // tests if subscribe was clicked on, on the form page$errorhandler = ""; // This will control holding error information$management = true; // Gives me full control over when the script runs and stops$regex = "^[A-Za-z0-9\._-]+@([A-Za-z0-9][A-Za-z0-9-]{1,62})(\.[A-Za-z][A-Za-z0-9-]{1,62})+$";	// regex variables has a regex value initialized into it, this allows me to quickly run	// the regex functions through the email field to test it's format.  It makes sure it 	// contacts an at symbol, and a period, and in the proper places.	if ($_POST['name'] == "") { // checks if name is empty, and puts error info into string  $errorhandler .= "The Name Field was not filled in correctly<br />";	}	if ($_POST['email'] == "") { // checks if email is blank  $errorhandler .= "The Email Field was not filled in correctly<br />";	}	if ($_POST['email'] != $_POST['verifyemail']) { //checks if email fields match  $errorhandler .= "The email address DO NOT match<br />";	}	if (!ereg("$regex", $_POST['email'])) { //tests emails format with regex variable above  $errorhandler .= "The email address is improperly formatted<br />";	}	if ($errorhandler != "") { //This tests the error handler to see if it has recieved  print "$errorhandler"; //any information or not, if it has then it prints the errors  $management = false;  // and changes management to false, which prevents other parts of	}    // the script from running later on down the road	if($management == true) {// This is were management first comes into play.  $connect = mysql_connect("localhost", "####", "######"); //connects to db  $select = mysql_select_db("######"); // selects db 	 if (!$connect || !$select){ //Tests the connection and sellection 	 echo "There was a problem interacting with the database please contact us at "; 	 echo "info@theyellowpagesnetwork.com";  // If it doesn't connect or select it returns 	 $management = false; //errors and changes the management to prevent action during other 	 } //parts of the script  }  // It gets closed 2 times, once for the first if, a second for the other if statement 	   if($management == true) { 	 $inserter = "INSERT INTO signoninfo (name, email) VALUES ('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['email']) . "')"; 	 if(mysql_query($inserter)){  	 $management = true; 	 }else { 	 echo "There was some sort of error interacting with the database.<br />"; 	 echo "Your information was not inserted into it for some unknown reason.<br />"; 	 echo "Please contact us at info@theyellowpagesnetwork.com and notify us of this<br />"; 	 echo "we thank you for your patience!<br />"; 	 $management = false; 	 }  }   	if($management == true) { // start major if mail system construct 	 $mailmanager = true; // sets another manager to manage all email scripts    if($mailmanager == true) {  //tests for the mail manager script    $to = "{$_POST['email']}"; // sets where the email goes to    $subject = "Funny Email Forwards News Letter Notification";  // sets the subject    $message = " This is to notify {$_POST['name']} that you have signed up to ";    $message .= "Funny Email Forwards at {$_POST['email']}.  You should be ";    $message .= "Recieving an email within the next hour that will give you a full list ";    $message .= "of all funny related entries from our database. ";    $message .= "If you do not recieve the other email within 24 hours please contact ";    $message .= "info@theyellowpagesnetwork.com and we will manually send you one.";    // everything under the message variables sets the contents for the mail   	 if(mail($to, $subject, $message)){ // opens up another if construct for email to user   	 echo "Thank you for signing up to the news letter<br />"; // confirmation message   	 echo "You should recieve a confirmation and first letter within 3 hours"; //same here   	 $mailmanager = true; // sets mail manager for use with script below this one   	 }else { // if it doesn't mail then instead it does this   	 echo "There was some sort of problem sending you a confirmation email"; // error message   	 echo "this problem is direcly relating to sending you a confirmation email"; //same   	 echo "I apologize for this error, please contact us at info@theyellowpagesnetwork.com";   	 echo "and we will manually get the process started for you, thanks for your"; //same   	 echo "time and patience"; // same   	 $mailmanager = false; // sets mail manager to false to discontinue the script later      } //closes the else construct above   	 }// closes the bigger if construct containing mail function          if($mailmanager = true){ // starts admin mail section      $to = "businessman332211@hotmail.com"; // sets email to send to      $subject = "Funny Email Forwards Subscription"; // sets subject      $message = "This is to inform you that {$_POST['name']} has signed up to the ";      $message .= "newsletter under {$_POST['email']} at Funny Email Forwards.com.";      // sets email message      mail($to, $subject, $message); // send an email to admin  } //  final if, encloses all coding in admin mail section	} // closes entire mail related script} // closes entire section pertaining to subscribe // End Subscribe Script	//Begin Unsubscribe Script// The script below here is used if someone clicked on unsubscribe on the form. 	 ?>

Link to comment
Share on other sites

I tried some changes I picked up and it didn't work.Here is the code I have changed it into.

<?php// This is a page that holds 2 different scripts, this completely controls the results coming from the form on signup.php, the purpose of these 2 scripts is to detect which button was pressed, if subscribe was pressed the top set of scripts under the giant if statement run.  If unsubscribe is pressed then the if statement corresponding to unsubscribe is ran.// Begin subscribe scriptif (isset($_POST['subscribe'])) {  // tests if subscribe was clicked on, on the form page$errorhandler = ""; // This will control holding error information$management = true; // Gives me full control over when the script runs and stops$regex = "^[A-Za-z0-9\._-]+@([A-Za-z0-9][A-Za-z0-9-]{1,62})(\.[A-Za-z][A-Za-z0-9-]{1,62})+$";	// regex variables has a regex value initialized into it, this allows me to quickly run	// the regex functions through the email field to test it's format.  It makes sure it 	// contacts an at symbol, and a period, and in the proper places.	if ($_POST['name'] == "") { // checks if name is empty, and puts error info into string  $errorhandler .= "The Name Field was not filled in correctly<br />";	}	if ($_POST['email'] == "") { // checks if email is blank  $errorhandler .= "The Email Field was not filled in correctly<br />";	}	if ($_POST['email'] != $_POST['verifyemail']) { //checks if email fields match  $errorhandler .= "The email address DO NOT match<br />";	}	if (!ereg("$regex", $_POST['email'])) { //tests emails format with regex variable above  $errorhandler .= "The email address is improperly formatted<br />";	}	if ($errorhandler != "") { //This tests the error handler to see if it has recieved  print "$errorhandler"; //any information or not, if it has then it prints the errors  $management = false;  // and changes management to false, which prevents other parts of	}    // the script from running later on down the road	if($management == true) {// This is were management first comes into play.  $connect = mysql_connect("localhost", "#####", "#####"); //connects to db  $select = mysql_select_db("#####"); // selects db 	 if (!$connect || !$select){ //Tests the connection and sellection 	 echo "There was a problem interacting with the database please contact us at "; 	 echo "info@theyellowpagesnetwork.com";  // If it doesn't connect or select it returns 	 $management = false; //errors and changes the management to prevent action during other 	 } //parts of the script  }  // It gets closed 2 times, once for the first if, a second for the other if statement 	   if($management == true) {$query = "SELECT * from signoninfo WHERE name = " . "$_POST['name']" . "AND email =" . "$_POST['email']";$result = mysql_query($query);$matches = mysql_numrows($result);if ($matches == 0) { 	 $inserter = "INSERT INTO signoninfo (name, email) VALUES ('" . mysql_real_escape_string($_POST['name']) . "', '" . mysql_real_escape_string($_POST['email']) . "')"; 	 if(mysql_query($inserter)){  	 $management = true; 	 }else { 	 echo "There was some sort of error interacting with the database.<br />"; 	 echo "Your information was not inserted into it for some unknown reason.<br />"; 	 echo "Please contact us at info@theyellowpagesnetwork.com and notify us of this<br />"; 	 echo "we thank you for your patience!<br />"; 	 $management = false; 	 }  } 	}  	if($management == true) { // start major if mail system construct 	 $mailmanager = true; // sets another manager to manage all email scripts    if($mailmanager == true) {  //tests for the mail manager script    $to = "{$_POST['email']}"; // sets where the email goes to    $subject = "Funny Email Forwards News Letter Notification";  // sets the subject    $message = " This is to notify {$_POST['name']} that you have signed up to ";    $message .= "Funny Email Forwards at {$_POST['email']}.  You should be ";    $message .= "Recieving an email within the next hour that will give you a full list ";    $message .= "of all funny related entries from our database. ";    $message .= "If you do not recieve the other email within 24 hours please contact ";    $message .= "info@theyellowpagesnetwork.com and we will manually send you one.";    // everything under the message variables sets the contents for the mail   	 if(mail($to, $subject, $message)){ // opens up another if construct for email to user   	 echo "Thank you for signing up to the news letter<br />"; // confirmation message   	 echo "You should recieve a confirmation and first letter within 3 hours"; //same here   	 $mailmanager = true; // sets mail manager for use with script below this one   	 }else { // if it doesn't mail then instead it does this   	 echo "There was some sort of problem sending you a confirmation email"; // error message   	 echo "this problem is direcly relating to sending you a confirmation email"; //same   	 echo "I apologize for this error, please contact us at info@theyellowpagesnetwork.com";   	 echo "and we will manually get the process started for you, thanks for your"; //same   	 echo "time and patience"; // same   	 $mailmanager = false; // sets mail manager to false to discontinue the script later      } //closes the else construct above   	 }// closes the bigger if construct containing mail function          if($mailmanager = true){ // starts admin mail section      $to = "businessman332211@hotmail.com"; // sets email to send to      $subject = "Funny Email Forwards Subscription"; // sets subject      $message = "This is to inform you that {$_POST['name']} has signed up to the ";      $message .= "newsletter under {$_POST['email']} at Funny Email Forwards.com.";      // sets email message      mail($to, $subject, $message); // send an email to admin  } //  final if, encloses all coding in admin mail section	} // closes entire mail related script} // closes entire section pertaining to subscribe // End Subscribe Script	//Begin Unsubscribe Script// The script below here is used if someone clicked on unsubscribe on the form. 	 ?>

I don't know I changed some but it didn't work, any help would be greatly appreciated. I am currently getting this error message.

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/all/funnyemailforwards/public_html/apex/signupprocessor.php on line 39
Link to comment
Share on other sites

$query = "SELECT * from signoninfo WHERE name = '" . mysql_real_escape_string($_POST['name']) . "' AND email = '" . mysql_real_escape_string($_POST['email']) . "'";$result = mysql_query($query);$matches = mysql_num_rows($result);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...