SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi folks, I have been creating a php form that also has a confirmation page...However, when I successfully add information, the final result is not being added to database...is my syntax incorrect?

    <?php

    //Check to see if the form was submitted
    if ($submit) {

    //Sets the intial error flag to 0
    $error = 0;

    //If name was submitted empty set $error = 1 and add error msg to errors array
    if (!$contactname) {
    $error = 1;
    $errors[] = "Missing Contact Name";
    }
    //If email was submitted empty set $error = 1 and add error msg to errors array
    if (!$email) {
    $error = 1;
    $errors[] = "Missing Email";
    }

    //If data had no errors
    if ($error == 0) {$dbcnx = @mysql_connect(
    "localhost", "XXXXXX", "XXXXXXXX");
    mysql_select_db("XXXXXXXXXX");

    $sql = "INSERT INTO Database SET "
    "E_Mail='$email', " .
    "Contact_Name='$contactname', " .

    }

    }
    ?>
    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>
    <?

    //Check to see if either the form wasn't submitted or there was an error and display the form
    if (!$submit || ($error == 1)) {

    print '<h2>Sample Form</h2>';
    //If $error = 1 loop through the errors array and print each error
    if ($error == 1) {
    print "<ul>";
    while (list ($key, $val) = each ($errors)) {
    printf('<li>%s', $val);
    }
    print "</ul>";
    }
    printf('<form action="%s" method="post">', $PHP_SELF);

    printf('Email: <input type="text" name="contactname" value="%s"><br>', $contactname);
    printf('Email: <input type="text" name="email" value="%s"><br>', $email);
    printf('<input type="submit" name="submit" value="submit">');
    print '</form>';
    }

    //If no errors print the confirmation page
    else {
    printf('Thank you %s, your information was submitted successfully', $contactname);
    }


    ?>



    </body>
    </html>

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dylan - maybe I am missing something - but where is the query?

    ie:$inserted=mysql_query($sql");

    - I can not see it anywhere?

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    firepages has nailed it, but there's also a syntax error in your code:

    Code:
    $sql = "INSERT INTO Database SET " . // added missing dot
    "E_Mail='$email', " . 
    "Contact_Name='$contactname', " . 
    // where's the rest of the query?
    -Kev.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •