Jump to content

include() and explode() questions


dadamssg

Recommended Posts

im going back through a login/register script i got from a book and i understand almost everything...few things are givin me some trouble. 1. in the code below

/* check whether email already exists */
     $sql = "SELECT email FROM Member 
                    WHERE email = '$email'";  #177
     $result = mysqli_query($cxn,$sql)
               or die("Couldn't execute select query.");
     $num = mysqli_num_rows($result);                 #180
     if ($num > 0)                                    #181
     {
        $message_new = "There is already an account under $email.";
        include("login_form2.php");
        exit();

 

does the last two lines mean that the script dies and then shows login_form2.php? so if i included another file, it would act as a header?

 

2. in the code below, the posts in the register fields are run through a loop, and then getting imploded/exploded(don't really understand this) and then gets inserted in the db. can anyone explain to me the syntax in this bit? i get SO lost in all the commas, periods, quotations,etc. I want to add another field into the db, such as a confirm # hash for a confirm script ive yet to write, so i definitely need to understand the punctuations.

 


/* Add new member to database */
    else                                            #190
    { 
        $today = date("Y-m-d");
        $fields_str = implode(",",$fields);
        $values_str = implode('","',$values);
        $fields_str .=",createDate";
        $values_str .='"'.",".'"'.$today;
        $fields_str .=",password";
        $values_str .= '"'.","."md5"."('".$password."')";
        $sql = "INSERT INTO Member ";
        $sql .= "(".$fields_str.")";
        $sql .= " VALUES ";
        $sql .= "(".'"'.$values_str.")";
        $result = mysqli_query($cxn,$sql)
                or die("Couldn't execute insert query.");
        $_SESSION['auth']="yes";                      #205
        $_SESSION['logname'] = $loginName;            #206

              header("Location: New_member.php");          #219
      }[/code]

thanks ahead  :)

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/149042-include-and-explode-questions/
Share on other sites

That code is actually out of a book?  Dear God, that book must suck.  Not the worst code I've ever seen, but it's not exactly pretty.

 

 

 

Anyway, in the first snippet, the script sets a variable, outputs a form (assuming that's what happens in the include) and terminates if the email exists.

 

 

So it essentially goes:

 

if(email exists already) {

    show form

    terminate

}

 

Yes, you could include a file before the other include to create a header like effect.  Don't break HTML validity by doing that though, if the included file has <head> and what not in it.

 

 

 

 

 

 

The second snippet is just stringing a bunch of crap together in a really ugly way.

 

 

No idea where fields and values come from, by the way, but unless that's a hard coded array, it's probably not safe.

 

 

 

 

 

In all honesty, I wouldn't recommend that book to someone who was trying to learn PHP based off of those two snippets right there.  Just of curiosity, what is the book called?

Archived

This topic is now archived and is closed to further replies.

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