Jump to content

need help


Recommended Posts

FINALLY SOLVED

Never have I felt so much anger towards one computer. At 3:30 in the morning I felt that I wanted to rip my monitor to pieces. Here is the question, and problem I have been facing.

<?phpif (isset($_POST['subscribe'])) {$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 />";  $management = false;    	}	if ($_POST['email'] == "") { // checks if email is blank  $errorhandler .= "The Email Field was not filled in correctly<br />";  $management = false;	}	if ($_POST['email'] != $_POST['verifyemail']) { //checks if email fields match  $errorhandler .= "The email address DO NOT match<br />";  $management = false;	}	if (!ereg("$regex", $_POST['email'])) { //tests emails format with regex variable above  $errorhandler .= "The email address is improperly formatted<br />";  $management = false;	}	if (is_string($errorhandler)) { //This tests the error handler to see if it has recieved  print "$errorhandler"; //a string information if so it passes the information below.  $management = false; 	}	if($management == true) {// This is were management first comes into play.  $connect = mysql_connect("localhost", "#####", "######");  $select = mysql_select_db("#######");  }else {  echo "There was a problem interacting with the database, please contact us at";  echo "info@theyellowpagesnetwork.com";  $management = false;  }    if($management == true) {  echo "everything seemed to work all right";  }      	}?>

Ok what it's doing is doing all the validation, popping out the error, and still popping out There was a problem interacting with the database, whatever. What I don't get is I set a variable at the beginning $management = true;and as I went down I changed it to $management = false;if it ran into an error, then down there I said as a test to make sure it was performing rightHere I said thisif(is_string($errorhandler))THIS SHOULD NOT work unless an error was detected, so when an error is detected this works and kicks out the proper error messages, then below that I have another control structure that saysif ($management == true) {then do whateverThis is what is confusing me, this is not common sense, if the script runs into any type of error, it should change $management to false, so if it encountered an error, then when the script tests to see if managment is true it SHOULD NOT read that at all if there was an error occured, any help would be appreciated, thanks.

Edited by businessman332211@hotmail.com
Link to comment
Share on other sites

Thats not fixing the problem. I chose this method because I am trying to learn various functions, the php.net manual says specifically that is_string tests a variable to see if it is a string if it is, it returns true, if not it returns false, it says specifically that if is_string checks a variable and it has an empty string meaning "" as it's value then it will return false, because essentially "" == null, with this being true it's saying $errorhandler = null;it's the same thing. But that has nothing to do with the current problem, I did however try that out to test to make sure, and the script still misperformed, I don't understand the logic behind it doing this.

Link to comment
Share on other sites

I also tried a complete redo, someone rewrote the script for me entirely, I tried it as a test run and it does the same thing, it goes through and reports all the errors and still returns the database be interacted with, I have run into ######, a programmers worse nightmare, This is the most evil, gruesome thing I have ever encountered. It's a nightmare I don't think I will ever wake up from, an unruly script, that you can't beat into submission.

Link to comment
Share on other sites

the php.net manual ... it says specifically that if is_string checks a variable and it has an empty string meaning "" as it's value then it will return false
Any link to your source?Because the following works for me:
<?php$str = "";if (is_string($str))	echo "it is a string";	else	echo "it is not";?>

Link to comment
Share on other sites

That's still not the root of the problem, but I understand what you are saying it could cause me problems later, I will change that, just for that sake, but it still won't help me figure out what is causing this other nightmare to happen. I see what you mean though, in the manual it is something that said as a user comment, but currently I changed the script like you siad, it's still having a nightmare, I Don't understand this.

Link to comment
Share on other sites

"everything seemed to work all right"This is what I got with the following code:

<?php$subscribe = "hello";$name = "name";$email = "mail@mymail.ro";$verifyemail = "mail@mymail.ro";if (isset($subscribe)) {$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 ($name == "") { // checks if name is empty, and puts error info into string $errorhandler .= "The Name Field was not filled in correctly<br />"; $management = false;    }if ($email == "") { // checks if email is blank $errorhandler .= "The Email Field was not filled in correctly<br />"; $management = false;}if ($email != $verifyemail) { //checks if email fields match $errorhandler .= "The email address DO NOT match<br />"; $management = false;}if (!ereg("$regex", $email)) { //tests emails format with regex variable above $errorhandler .= "The email address is improperly formatted<br />"; $management = false;}if (!empty($errorhandler)) { //This tests the error handler to see if it has recieved print "$errorhandler"; //a string information if so it passes the information below. $management = false;}if($management == true) {// This is were management first comes into play. //$connect = mysql_connect("localhost", "#####", "######"); //$select = mysql_select_db("#######"); echo "sql<br>";}else { echo "There was a problem interacting with the database, please contact us at"; echo "info@theyellowpagesnetwork.com"; $management = false;} if($management == true) { echo "everything seemed to work all right"; }  }?>

I replaced the $_POST vars (didn't want to make a form for testing), commented the sql functions and put an echo, and I used if (!empty($errorhandler)) (sorry, in the previous post I forgot the !).

Link to comment
Share on other sites

Yes that is great, but here is what happensYou can't simulate a form you said you didn't feel like it, what happens is I changed the variables name, email, and verify email to "" which is what it would be if someone was filling out a form and forgot to fill them in, and the EXACT SAME Thing happen that was happening with my script I get this. THE SAME freaking nightmare

The Name Field was not filled in correctlyThe Email Field was not filled in correctlyThe email address is improperly formattedThere was a problem interacting with the database, please contact us atinfo@theyellowpagesnetwork.com
and that is from your script specifically, now you see why I am so pissed, and having so many problems, even people with triple my experience, are redoing my script and the same thing is happening, you and someone else, I don't understand the logic behind this error, I have thought through this script 200 times.
Link to comment
Share on other sites

and this is the exact code you gave me, just set up to simulate if someone tried entering form information and forgot to fill out the fields.The only changes are at the top, to simulate if someone had forgot to enter the form information

<?php$subscribe = "hello";$name = "";$email = "";$verifyemail = "";if (isset($subscribe)) {$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 ($name == "") { // checks if name is empty, and puts error info into string$errorhandler .= "The Name Field was not filled in correctly<br />";$management = false;    }if ($email == "") { // checks if email is blank$errorhandler .= "The Email Field was not filled in correctly<br />";$management = false;}if ($email != $verifyemail) { //checks if email fields match$errorhandler .= "The email address DO NOT match<br />";$management = false;}if (!ereg("$regex", $email)) { //tests emails format with regex variable above$errorhandler .= "The email address is improperly formatted<br />";$management = false;}if (!empty($errorhandler)) { //This tests the error handler to see if it has recievedprint "$errorhandler"; //a string information if so it passes the information below.$management = false;}if($management == true) {// This is were management first comes into play.//$connect = mysql_connect("localhost", "#####", "######");//$select = mysql_select_db("#######");echo "sql<br>";}else {echo "There was a problem interacting with the database, please contact us at";echo "info@theyellowpagesnetwork.com";$management = false;}if($management == true) {echo "everything seemed to work all right";}}?>

Link to comment
Share on other sites

when an error is encountered in the script, it should change management to false, when the scripts tests if management is true and it's not then it shouldn't try to run that part of the script at all, unless there were no errors, and management stayed true, do you see why I am having such a problem now, I don't understand this at all.

Link to comment
Share on other sites

Finally I understand what your problem is...The fact that the "There was a problem interacting with the database.." message still appears if there is a previous validation error? If yes, then try:

if($management == true) {// This is were management first comes into play.$error = false;// ...// sql functions// if something goes wrong, then set $error = true;if ($error) {	echo "There was a problem interacting with the database, please contact us at";	echo "info@theyellowpagesnetwork.com";	$management = false;	}}if($management == true) {echo "everything seemed to work all right";}

Link to comment
Share on other sites

I had finally gotten it, what was happening was I was testing it, but when the script got there it testing to see if it was true, IF IT wasn't true then it popped up that message in the else statement so I changed that part to this.

<?phpif (isset($_POST['subscribe'])) {$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"; //a string information if so it passes the information below.  $management = false; 	}	if($management == true) {// This is were management first comes into play.  $connect = mysql_connect("localhost", "####", "#####");  $select = mysql_select_db("#####"); 	 if (!$connect || !$select){ 	 echo "There was a problem interacting with the database please contact us at "; 	 echo "info@theyellowpagesnetwork.com"; 	 $management = false; 	 }  }      if($management == true) {  echo "everything seemed to work all right";  }     	 }?>

and it worked, I just have to think ahead from now on when organizing me if else statements, I was unaware I could create an if statement, with others inside of it, to that level, I am starting to understand control structures more and more, thanks for all the help I really appreciate it.

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