SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am working on a form for submitting first name ($fname), last name ($lname) and email address ($address) into mySQL.

    I would like to do this one totally myself, but I would like some input though.

    I would like to use one page for the whole thing for simplicitys sake. So my question would be this:

    What would be the best way to break up the HTML and the PHP?

    right now I am thinking that the page will look like this.


    check if the user has pressed the submit button (value=subscribe!).

    if they have then submit to db and give them a nice thank you.

    or else show the form so they can submit


    SO basically, I want to check to see if they have submitted and then enter the info in the DB or give them the form so that they CAN submit.

    Below is the code that I am using...I KNOW that is is broken right now and that is my question. I think this if: else: endif: thing might be what I am looking for, but I am not sure how to implement large chunks of HTML into it...anyone have suggestions?




    <?php include("fragments/connect_info.php"); ?>
    <br><br>

    <table width="300" cellpadding="1" cellspacing="0" align="center">
    <tr>
    <td>
    <img src="images/splash_header.gif" width="300" height="60" />
    </td>
    </tr>
    </table>

    <?php // If the user wants to add a joke
    if (!isset($submit)):


    $connect = mysql_connect ($dbhost, $dbuser, $dbpass);
    $db = mysql_select_db ($dbname);

    if ("subscribe!" == $submit) {
    $sql = "INSERT INTO name (eid, fname, lname), email (id, address) VALUES ('', $fname, &lname), ('', $address)";
    if (mysql_query($sql)) {
    echo("Thank's for signing up." . $fname . " When we launch the site, you will get an email.");
    } else {
    echo("Sorry...it didn't work...please try again.");
    }
    }

    ?>

    <?php
    else:

    <table width="400" cellpadding="1" cellspacing="0" align="center">
    <tr><td>
    <font size="2" face="verdana" color="#ffffff">
    Welcome to <b>by the tree.com</b>. We are in the process of redesigning our website. If you would like to be notified when the new version of the website is launched, or if you want to find out more about the band, please sign up for our mailing list.
    <br><br>
    </font>
    </td>
    </tr>
    </table>

    <table width="350" cellpadding="1" cellspacing="0" align="center">
    <tr>
    <td bgcolor="#ffffff">
    <table width="348" cellpadding="2" cellspacing="1" bgcolor="#BF2727">
    <form method="post" action="<?php echo($PHP_SELF); ?>">
    <tr><td bgcolor="#ffffff" colspan="2"></td></tr>
    <tr><td bgcolor="#A30000" colspan="2">
    <font size="2" face="verdana" color="#ffffff">&nbsp;&nbsp;<B>by the tree</B> version 2.0</font>
    </td></tr>
    <tr><td bgcolor="#ffffff" colspan="2"></td></tr>
    <tr bgcolor="#BF2727">
    <td width="98">
    <font size="2" face="verdana" color="#ffffff">
    &nbsp;<b>first name/b>
    </td>
    <td width="250">
    <input type="text" name="fname" height="5" size="20">
    </td>
    </tr>
    <tr bgcolor="#BF2727">
    <td>
    &nbsp;<font size="2" face="verdana" color="#ffffff"><b>last name/b></font>
    </td>
    <td>
    <input type="text" name="address" height="5" size="25">
    </td>
    </tr>
    <t bgcolor="#BF2727">
    <td>
    &nbsp;<font size="2" face="verdana" color="#ffffff"><b>email/b></font>
    </td>
    <td>
    <input type="text" name="address" height="5" size="30">
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <input type="submit" class="formbutton" name="submit" value="subscribe!">
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table></form>

    endif;
    ?>
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    creole, you're on the right track.

    to start with you want this line :

    Code:
    if (!isset($submit)):
    to look like this :

    Code:
    if (!isset($subscribe!))
    because the value of your submit button is subscribe!

    can i put my version of the form up for you to see? i think it would make more sense if you have a visual for i'm saying.


    ******** vb is giving me some errors when i try to submit the code so i'm going to email it to you *********
    . . . chris

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    atomicmunky, sorry but you are incoorect there

    Code:
    if (!isset($subscribe!))
    should in fact be

    Code:
    if (!isset($submit))

    The value is subscribe! the name is submit

    or you could use

    Code:
    if ($submit != "Subscribe!")
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops !! he he.

    i just looked over my own code and i see what i did. i thought of one thing and typed another. you are right.
    i really should get some more sleep.

    creole, don't listen to me listen to freddy
    . . . chris

  5. #5
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can anyone help me with my original question?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  6. #6
    SitePoint Zealot moshe_be's Avatar
    Join Date
    Dec 2000
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There you go:

    Code:
    <?php include("fragments/connect_info.php"); ?> 
    <br><br> 
    
    <table width="300" cellpadding="1" cellspacing="0" align="center"> 
    <tr> 
    <td> 
    <img src="images/splash_header.gif" width="300" height="60" /> 
    </td> 
    </tr> 
    </table> 
    
    <?php // If the user wants to add a joke 
    if ($submit)
    {
    
    $connect = mysql_connect ($dbhost, $dbuser, $dbpass); 
    $db = mysql_select_db ($dbname); 
    
    $sql = "INSERT INTO name (eid, fname, lname), email (id, address) VALUES ('', $fname, &lname), ('', $address)"; 
    if (mysql_query($sql)) { 
    echo("Thank's for signing up." . $fname . " When we launch the site, you will get an email."); 
    } else { 
    echo("Sorry...it didn't work...please try again."); 
    } 
    
    } else {
    ?>
    <table width="400" cellpadding="1" cellspacing="0" align="center"> 
    <tr><td> 
    <font size="2" face="verdana" color="#ffffff"> 
    Welcome to <b>by the tree.com</b>. We are in the process of redesigning our website. If you would like to be notified when the new version of the website is launched, or if you want to find out more about the band, please sign up for our mailing list. 
    <br><br> 
    </font> 
    </td> 
    </tr> 
    </table> 
    
    <table width="350" cellpadding="1" cellspacing="0" align="center"> 
    <tr> 
    <td bgcolor="#ffffff"> 
    <table width="348" cellpadding="2" cellspacing="1" bgcolor="#BF2727"> 
    <form method="post" action="<?php echo($PHP_SELF); ?>"> 
    <tr><td bgcolor="#ffffff" colspan="2"></td></tr> 
    <tr><td bgcolor="#A30000" colspan="2"> 
    <font size="2" face="verdana" color="#ffffff">  <B>by the tree</B> version 2.0</font> 
    </td></tr> 
    <tr><td bgcolor="#ffffff" colspan="2"></td></tr> 
    <tr bgcolor="#BF2727"> 
    <td width="98"> 
    <font size="2" face="verdana" color="#ffffff"> 
     <b>first name:</b> 
    </td> 
    <td width="250"> 
    <input type="text" name="fname" height="5" size="20"> 
    </td> 
    </tr> 
    <tr bgcolor="#BF2727"> 
    <td> 
     <font size="2" face="verdana" color="#ffffff"><b>last name:</b></font> 
    </td> 
    <td> 
    <input type="text" name="address" height="5" size="25"> 
    </td> 
    </tr> 
    <t bgcolor="#BF2727"> 
    <td> 
     <font size="2" face="verdana" color="#ffffff"><b>email:</b></font> 
    </td> 
    <td> 
    <input type="text" name="address" height="5" size="30"> 
    </td> 
    </tr> 
    <tr> 
    <td colspan="2" align="center"> 
    <input type="submit" class="formbutton" name="submit" value="subscribe!"> 
    </td> 
    </tr> 
    </table> 
    </td> 
    </tr> 
    </table></form> 
    <?
    }
    ?>

  7. #7
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so the HTML doesn't have to be inside a PHP tag?

    Why didn't I think of that...that RULES!
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes


Bookmarks

Posting Permissions

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