Jump to content

basic script


Ninjakreborn

Recommended Posts

[b]SOLVED[/b]

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.

[code]<?php
if (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";
        }
        
        
            
}
?>[/code]
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 right
Here I said this
if(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 says
if ($management == true) {
then do whatever
This 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.
Link to comment
Share on other sites

I don't know really, personal preference possibly, but I don't understand why it's not working, it has nothing to do with that part, It has something to do with the management variable, I just don't understand why it's not working, It shouldn't pass that control structure if $management == false;
but it does, it still runs that part of the script for some reason.??

I can try that to make sure, but what I was told is that "" = null, so null means not existent, like not a string, not an array so if you do.
$error[] = null;
then it's still not an array, and $error[] = "";
is the same thing, but even changing that won't do anything with that part of the script, I can play with it, maybe come up with a way I like better for errorhandler but for now I have to figure out what's wrong with this script, any help would be appreciated.
Link to comment
Share on other sites

I have to say I'm confused by this script.
The method I would advise is:
[code]
if ($_POST['field'] == "")
{
  $error[1] = "This field is empty";
}
if (!isset ($error))
{
  $management = true;
}
else
{
  foreach ($error as $text)
  {
    echo $text."<br>";
  }
  $management = false;
}
[/code]
Link to comment
Share on other sites

I have went through a thousand different ways to do this same script, my original idea was to come up with my own idea, I have asked for hundreds of peoples advice, and put it all together, tried things, didn't like them, I finally found a specific way I like, and what I know is wrong is the way I set up my if statements, as always I get confused with control structures, I have went over this script 1000 times, Ididn't want it trying to connect to a database, unless it passed all validation, I finally thought I had an idea with the management variable and it still didn't work, I like the way I did validation, I finally found something I like, that is fun programming, and allows "me" a good basis if I wanted to add new features, what I need help with now, is figuring out what is wrong with my control structure, if it encounters an error
$management should change to false, and as long as it's false those if control structures down there shouldn't work, they should get to it, read
if ($management == true){
do whatever
}
and it should say "ok since $management is currently false, then this part of the script isn't supposed to activate
but what it's currently doing which is pissing me off, is I go to the site, if I don't fill in any fields and click submit, it should start going down the script.
It should start off the script it gets down to the first line and checks name to see if it's blank, ok it is, so it should put something into the error handler string and change management to false, as it moves down the script it should check more errors. Then it gets to the error handler string, the script looks and asks is $errorhandler a string, if it has acquired any errors then it is indeed a screen and it runs the script, at that time it passes out all the errors, if this has happened, then Definitely management is currently false, so it should move further down the script, the script asks if management is true or not, if it's true then it should work the script if it's false then it knows not to do that, but EVEN THOUGH the damn thing is false, it still decides it wants to go against what I said, and run the script anyway, what's going on.

because when I go to the site
www.funnyemailforwards.com
and I click on sign on
and I click subscribe
it gives me all the validation error messages, and the error message saying it couldn't interact with the database, it shouldn't even be trying to interact with the database,.
Link to comment
Share on other sites

ok ok, but could you try using this code?

[code]
<?php
if (isset($_POST['subscribe'])) {
$management = 1;
$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
        $error[1] = "The Name Field was not filled in correctly<br />";    
    }
    if ($_POST['email'] == "") { // checks if email is blank
        $error[2] = "The Email Field was not filled in correctly<br />";
    }
    if ($_POST['email'] != $_POST['verifyemail']) { //checks if email fields match
        $error[3] = "The email address DO NOT match";
    }
    if (!ereg($regex, $_POST['email'])) { //tests emails format with regex variable above
        $error[4] = "The email address is improperly formatted<br />";
    }
    if (isset ($error) && is_array ($error)) { //This tests the error handler to see if it has recieved
        foreach ($error as $msg)
    {
        echo $msg;
            $management = 0;
    }
    }
    if($management == 1) {// 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";
        }
        
        if($management == 1) {
        echo "everything seemed to work all right";
        }
        
        
            
}
?>
[/code]
Link to comment
Share on other sites

I tried changing the managements with 0 and 1 instead of true false, but it still didn't work so I changed it back, does anyone at all see anything else wrong with this script, I tried that, when you said that I was thinking do variables double initialize for instance, do 2 trues make a false, and 2 false's make a true or something I didn't know.
like if I have
$management = true;
Then go and do

$management = false;
$mangement = false;

does that make it true or something, that is what's confusing me [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]
Link to comment
Share on other sites

Uhh what the hell is going on today, I tried even your script, word for word, all the way down to the letter, copied and pasted into a test.php, ran my action through it, when it ran the script it messed up the same thing. What is going on with this, is there something were both missing, I tried your script as a test, and it still ran down the whole thing, when I click subscribe it returned all the error messages, and still gave the error message could not interact with database, what's going on with this. Is my computer possessed by anti-php demons or something.

This is a programmers nightmare, I really am in hell aren't I. I thought programming was heaven, but I have crossed over into hell...
Link to comment
Share on other sites

here let me show you what I mean. For instance, I am back to my old script with true or false.
Here is what I want, I start the script off with
$management = true;
That makes management true right at the start.
if it encounters an error then $management = false;
it changes the script.
now when it gets down to that section it should test whether $management is true or false
if it's true (meaning encountered no errors so far) then it should try to connect to the database, if it can't then return the error problem while interacting with the database.
If it is false, meaning that an error was encounter, see it starts as true, if it hits an error it changes to false, with it being false from an error, when the script tests, and sees it's false, it still runs the script anyway so what it is telling me is
$management = true
at the beginning
later on down every error it hits, when it gets to the error handler, it changes it to false if it detected any errors in validation. If $management is then false, how does it still run a script saying if management is true. Look at the script again and you will see what I mean, I intended to test for validation, and change to false if some was encountered, to prevent the rest of the script from running, but it's not working right.
Link to comment
Share on other sites

FINALLY
I found the problem
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.

[code]<?php
if (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";
  }
  
  
      
}
?>[/code]
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

^ yes this is what I was point out. glad it's fixed

literal script:
John is management checker

you can use things now

if any thing is wrong with the form, make trouble for john

john says there's no trouble. He's going to contact the database.

Otherwise, john says there is trouble, you can't use things and now he's printing an error.

Now John will say "bully me" if there's no trouble.

anyway I dunno that's how i see it.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.