Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    May 2010
    Location
    Atlanta
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy n00b trying to code PHP/MySQL Query

    trying to create a from and query in which the form passes a value for the $membername variable and then the php script processes the MySQL query and populates the email address resulting from the query into the $to variable, also the $membername into the email.

    Here's what I have but I keep getting errors. Any help would be appreciated!

    Heres the form:
    Code:
    <html>
    <form action="mailer/populate.php" method="post" enctype="multipart/form-data" name="lettermail" target="_blank" id="lettermail">
    	<label>Name
        <input name="membername" type="text" id="membername" tabindex="1" size="20" maxlength="30" />
    	</label>
          <input type="submit" name="send" id="send" value="Submit">Send Invitation to Qualify
    </form>
    <form action="mailer/populate2.php" method="post" enctype="multipart/form-data" name="lettermail2" target="_blank" id="lettermail2">
    	<label>Name
        <input name="membername" type="text" id="membername" tabindex="1" size="20" maxlength="30" />
    	</label>
          <input type="submit" name="send" id="send" value="Submit">Send Congratulations
    </form>
    <form action="mailer/sendlease.php" method="post" enctype="multipart/form-data" name="lettermail3" target="_blank" id="lettermail3">
    	<label>Name
        <input name="membername" type="text" id="membername" tabindex="1" size="20" maxlength="30" />
    	</label>
          <input type="submit" name="send" id="send" value="Submit">Send Lease
    </form>
    </html>

    and here's the PHP SCript:

    Code:
    <?php
    $host="localhost";
    $uname="tsw_smcs12";
    $pass="password";
    $database="tsw_tswcb";
    $membername = $HTTP_POST_VARS['membername'];
    $member = $membername;
    
    $connection= mysql_connect ($host, $uname, $pass) or die ("Database connection failed!");
    
    $result = mysql_select_db ($database) or die ("Database could not be selected");
    $query =  mysql_query (SELECT `email` FROM `jos_users` WHERE `name` = " . $_POST['membername'] . ");
    
    $to = $query;
    $subject = "You have been pre qualified to become a Premium Member";
    
    $message = "
    <html>
    <center>
    <table>
    <tr>
    	<td background=#FFFFFF></td>
    </tr>
    <tr>
    	<td>
    	<h1>You are Pre-Qualified!</h1>
    	Dear $member ,*<br><br>
    
    <p>As you know, TSWPlace is the online networking community for anyone that shares a common interest in entertainment. Certain people and profiles on Place stand out above the others in terms of talent, drive and commitment. You have gotten our attention because you have been actively engaged on TSWPlace and have demonstrated a desire to be successful. Therefore, I would like to invite you to the next level of TSW, TSW World.</p>
    <p>Select TSWPlace members that qualify are invited to become part of our exclusive, members-only entertainment network TSW World. I believe you have what it takes to become a TSW World member. *If you qualify and become a World member, we will provide you access to the elite, influential and talented members in the network as well as, help you distribute your product(s) and showcase your talent. Yes, we have distribution and access - it’s called networking with a purpose.</p>
    
    <p>TSW World is a members-only network designed to break the mold for those in the entertainment field by uniting a community that connects talent and opportunities for serious people wanting to break into the business and those already well establish in it. **Success happens through the collaboration of talent, connections, experience and opportunity, but only for those that qualify.</p>
    
    <p>Our members include a qualified group of professionals excelling in their field who benefit from their products and services sold to and promoted by the entertainment community and all that it touches. Including but not limited to: investors, producers, directors song writers, performers, event planners, stylists, make up artists, lawyers, accountants, and designers.*</p>
    
    <p>In order to become a member of the TSW World network, complete the qualification assessment to see if you qualify. Take your time and be thoughtful about your answers. </p>
    <p>The final score of your assessment will determine whether you are eligible to join the network. </p>
    
    <p>Full disclosure: Not everyone qualifies to have access to the members of TSW World.  in fact, the pass rate averages 65% because, like all aspects of the entertainment industry, this is exclusive. </p>
    <p>Click the following link to begin: http://www.tswplace.com/qualify.html  - if the link does not open for you, copy and paste it into your browser to begin.</p><br><br>
    
    See you in the movies,<br><br>
    
    The System
    	</td>
    </tr>
    <tr>
    	<td></td>
    </tr>
    <tr>
    	<td><center></center></td>
    </tr>
    </table>
    </center>
    </html>
    ";
    
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    
    
    $headers .= 'From: <info@thesystemwithin.com>' . "\r\n";
    
    
     echo "<a href='javascript:history.back(1);'>Back</a>";
     
      mail($to,$subject,$message,$headers); 
    
    
    ?>
    Last edited by mike.proimage; 05-21-2010 at 09:50 PM.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by mike.proimage View Post
    but I keep getting errors
    Those errors are... ?
    Are you a Help Vampire?

  • #3
    New Coder
    Join Date
    May 2010
    Location
    Atlanta
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Parse error: syntax error, unexpected T_STRING in ...... line 13 and line 14 but that doesnt seem right....

  • #4
    New Coder
    Join Date
    May 2010
    Location
    Atlanta
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    actually it also reports an error in the $query variable almost like it doesnt want to accept the variable inside the query, and ive tried every method i can think of or google

  • #5
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Look at the end of lines 7 and 14. EDIT: in the form handler - the PHP.
    Are you a Help Vampire?

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Line 12 has a different problem. Consider how strings and concatenation work.
    Are you a Help Vampire?

  • #7
    New Coder
    Join Date
    May 2010
    Location
    Atlanta
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok i see the missing semi-colons, thanks! not sure about line 12 though, and dont really understand it. like i said i'm new to this.

  • #8
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I could give it to you, but that would be too easy. I'll paste a few lines using the forum's PHP tags (and toss in a couple of junk lines for illustration). Check out the color changes:
    PHP Code:
    $thisIsAVariable "This is a string."// Note the different colors.
    $connectionmysql_connect ($host$uname$pass) or die ("Database connection failed!");

    $result mysql_select_db ($database) or die ("Database could not be selected");
    $query =  mysql_query ("SELECT 'email' FROM 'jos_users' WHERE 'name' = " $_POST['membername'] . ");

    $to = $query;
    $subject = "
    You have been pre qualified to become a Premium Member"; 
    See where the string coloring carries over from line 12 ($query) to line 14's variable name? Why does it do that? More to the point, to what are you concatenating that POST variable?
    Are you a Help Vampire?

  • #9
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Just noticed, too, that your field names and table name in the query are wrong. Quoted strings in a query are just that: strings. You want field names. Two options: 1) remove the quotes from the field names, or 2) swap the quote marks with backticks/graves (`). On a standard keyboard, it's the key to the left of the number 1 key.
    Are you a Help Vampire?

  • #10
    New Coder
    Join Date
    May 2010
    Location
    Atlanta
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so, should look like this?

    PHP Code:
    $result mysql_select_db ($database) or die ("Database could not be selected");
    $query =  mysql_query (SELECT `emailFROM `jos_usersWHERE `name` = ' . $_POST['membername'] . ');

    $to $query;
    $subject "You have been pre qualified to become a Premium Member"
    Last edited by mike.proimage; 05-21-2010 at 10:02 PM.

  • #11
    New Coder
    Join Date
    May 2010
    Location
    Atlanta
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh, and you're awesome for being so patient and not just giving me the answer, i don't learn anything like that , right on.

  • #12
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    That's close. But the query itself still needs to be a string or else PHP starts seeing undefined words everywhere and gets confused. In other words, the whole query still needs the quotes. Here's a start (don't use this one):
    PHP Code:
    $query =  mysql_query ("SELECT `email` FROM `jos_users` WHERE `name` = " $_POST['membername']); 
    Compare the forum's PHP coloring between this version and yours. The query string is recognized as a string so it's highlighted red. If I would have left the trailing ." (concatenation operator and double quote), it would have thought you were continuing your string and would have colored everything red until the next double quote - just like in your previous version. Using a syntax highlighting and coloring editor really helps while learning.

    To muddy the waters a bit more, the WHERE portion of the query actually needs more quotes. Here's the structure of a basic query:
    Code:
    SELECT `field1` FROM `table` WHERE `field2`='searchData';
    See the quotes there? They're not required for numbers, but they are for strings. So that changes the query above to:
    PHP Code:
    $query =  mysql_query ("SELECT `email` FROM `jos_users` WHERE `name` = '" $_POST['membername'] ."'"); 
    I think that'll work. However, some people don't like messing with all of those stack of quotes since they can get confusing, so they use a workaround with curly braces. It doesn't look right in the forum's PHP coloring, but it does work:
    PHP Code:
    $query =  mysql_query ("SELECT `email` FROM `jos_users` WHERE `name` = '{$_POST['membername']}'"); 
    And if I didn't overlook something through that, you have a mysql_query line that will work.

    Going farther, I don't think that $to is going to work like you want. mysql_query returns a MySQL result resource from which you need to extract your information. Most tutorials I've seen will show mysql_fetch_array, but there are a couple of brothers you can use, too.
    Are you a Help Vampire?

  • #13
    New Coder
    Join Date
    May 2010
    Location
    Atlanta
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, I would never have found that. I was definitely tackling something way above my expertise ... and you explained it very well, i understand it now. So, now I have to let PHP return the result? but why fetch array? isn't it returning to me a single variable?

    PHP Code:
    return(mysql_query($query)); 

    ???
    Last edited by mike.proimage; 05-21-2010 at 10:40 PM.

  • #14
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    It's returning a single result, but it's wrapped in a resource. Consult the documentation linked to above. That should explain one side of it.
    Are you a Help Vampire?

  • #15
    New Coder
    Join Date
    May 2010
    Location
    Atlanta
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, here is the code I ended up with, I don't get any errors now, but after filling out the form and initiating the PHP script, the page just goes blank white, and it doesn't even show my 'back' link.

    PHP Code:
    <?php
    $host
    ="localhost";
    $uname="tsw_smcs";
    $pass="password";
    $database="tsw_tswc";
    $membername $HTTP_POST_VARS['membername'];
    $member $membername;

    /*$connection = */mysql_connect ($host$uname$pass) or die ("Database connection failed!");

    /*$result = */mysql_select_db ($database) or die ("Database could not be selected");
    $query =  mysql_query ("SELECT `email` FROM `jos_users` WHERE `name` = '" $_POST['membername'] ."'");  

    $result mysql_query($query);
    return 
    $result;

    $to $result;

    $subject "You have been pre qualified to become a Premium Member";

    $message "
    <html>
    <center>
    <table>
    <tr>
        <td background=#FFFFFF></td>
    </tr>
    <tr>
        <td>
        <h1>You are Pre-Qualified!</h1>
        Dear $member ,*<br><br>

    <p>As you know, TSWPlace is the online networking community for anyone that shares a common interest in entertainment. Certain people and profiles on Place stand out above the others in terms of talent, drive and commitment. You have gotten our attention because you have been actively engaged on TSWPlace and have demonstrated a desire to be successful. Therefore, I would like to invite you to the next level of TSW, TSW World.</p>
    <p>Select TSWPlace members that qualify are invited to become part of our exclusive, members-only entertainment network TSW World. I believe you have what it takes to become a TSW World member. *If you qualify and become a World member, we will provide you access to the elite, influential and talented members in the network as well as, help you distribute your product(s) and showcase your talent. Yes, we have distribution and access - it’s called networking with a purpose.</p>

    <p>TSW World is a members-only network designed to break the mold for those in the entertainment field by uniting a community that connects talent and opportunities for serious people wanting to break into the business and those already well establish in it. **Success happens through the collaboration of talent, connections, experience and opportunity, but only for those that qualify.</p>

    <p>Our members include a qualified group of professionals excelling in their field who benefit from their products and services sold to and promoted by the entertainment community and all that it touches. Including but not limited to: investors, producers, directors song writers, performers, event planners, stylists, make up artists, lawyers, accountants, and designers.*</p>

    <p>In order to become a member of the TSW World network, complete the qualification assessment to see if you qualify. Take your time and be thoughtful about your answers. </p>
    <p>The final score of your assessment will determine whether you are eligible to join the network. </p>

    <p>Full disclosure: Not everyone qualifies to have access to the members of TSW World.  in fact, the pass rate averages 65% because, like all aspects of the entertainment industry, this is exclusive. </p>
    <p>Click the following link to begin: http://www.tswplace.com/qualify.html  - if the link does not open for you, copy and paste it into your browser to begin.</p><br><br>

    See you in the movies,<br><br>

    The System
        </td>
    </tr>
    <tr>
        <td></td>
    </tr>
    <tr>
        <td><center></center></td>
    </tr>
    </table>
    </center>
    </html>
    "
    ;

    $headers "MIME-Version: 1.0" "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" "\r\n";


    $headers .= 'From: <info@thesystemwithin.com>' "\r\n";

     
    mail($to,$subject,$message,$headers);

     echo 
    "<a href='javascript:history.back(1);'>Back</a>";
     
    mysql_free_result($result);

    ?>


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •