Not Submitting to Database

Discussion in 'PHP' started by Alley Cat, May 17, 2007.

  1. #1
    Can anybody tell me why the following code is not submitting to it's database? The table is the correct name, as are the fields, and the field types. Have I put too much in the script or do I need to add a little more to it so that it will be enterred into it's table.

    <?php
    ob_start();
    session_start();

    // Include the configuration file for error management and such.
    require_once ('includes/config.inc.php');

    if (isset($_POST['submitted'])) { // Handle the form.

    require_once ('includes/mysql_connect.php'); // Connect to the database.

    // Check for an email address.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
    $e = escape_data($_POST['email']);
    } else {
    $e = FALSE;
    echo '<p>Please enter a valid email address!</p>';
    }

    // Check for pages quantity.
    if (eregi ('^[[:digit:]][0-9\.\-]*@[0-9\.\-]+\.[0-9]{2,4}$', stripslashes(trim($_POST['pages'])))) {
    $p = escape_data($_POST['pages']);
    } else {
    $p = FALSE;
    echo '<p>Please enter a number between 1 and 99!</p>';
    }

    // Check for site design.
    if (eregi ('^[[:alpha:]\.\' \-]{2,30}$', stripslashes(trim($_POST['design'])))) {
    $d = escape_data($_POST['design']);
    } else {
    $d = FALSE;
    echo '<p>Please select the design you require!</p>';
    }

    // Check for page titles.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['titles'])))) {
    $t = escape_data($_POST['titles']);
    } else {
    $t = FALSE;
    echo '<p>Please enter your titles for each page!</p>';
    }

    // Check for a header colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['header'])))) {
    $h = escape_data($_POST['header']);
    } else {
    $h = FALSE;
    echo '<p>Please enter a colour for your header section!</p>';
    }

    // Check for a left column colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['left'])))) {
    $l = escape_data($_POST['left']);
    } else {
    $l = '<i>No left column required!</i>';
    }

    // Check for a centre section colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['centre'])))) {
    $c = escape_data($_POST['centre']);
    } else {
    $c = FALSE;
    echo '<p>Please enter a colour for your centre section!</p>';
    }

    // Check for a right column colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['right'])))) {
    $r = escape_data($_POST['right']);
    } else {
    $r = '<i>No right column required!</i>';
    }

    // Check for a footer colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['footer'])))) {
    $f = escape_data($_POST['footer']);
    } else {
    $f = '<i>No footer section required!</i>';
    }

    // Check for extra auxillary pages.
    if (eregi ('^[[:alpha:]\.\' \-]{2,30}$', stripslashes(trim($_POST['extra'])))) {
    $x = escape_data($_POST['extra']);
    } else {
    $x = '<i>Extra pages not essential!</i>';
    }

    if ($p < 4) {
    $cost = £30;
    } elseif (4 <= $p && $p < 8) {
    $cost = £25;
    } elseif ($p >= 8) {
    $cost = £23;
    }

    $subject = "Site Creation Request";
    $body = "Thank you for requesting us to build a site for you. Although you have told us that you would like us to create $p pages at a cost of '&pound;'.$cost per page, there are still some details we would require from you which we will request in an forthcoming email. The pages will be designed in the $d style, with each page using the titles, $t. The colour scheme for the site will be $h for the header, $l for the left column, $c for the centre, $r for the right column, and $f for the footer. The site will also contain $x supplementary page(s).";

    $subject = "Site Creation Request";
    $body = "A request for a site to be created has been received. The site consists of $p pages, in the $d style, using the following colour scheme: header, $h, left column, $l, centre, $c, right column, $r and footer, $f. $x supplementary page(s) are also required.";

    if(!mail("alleycat@home-groan.com", $subject, $body, "accident@accidentrecordings.com")){
    print 'Your message has not been received, please try contacting us later.';
    }

    $total = $p * $cost;
    if ($e && $p && $d && $t && $h && $l && $c && $r && $f && $x && $cost && $total) {

    $didit = mail($email, $subject, $body, "alleycat@home-groan.com");

    // Add the request to the database.
    $query = "INSERT INTO site_request (email, pages, design, titles, header, left, centre, right, footer, extra, cost, total, request_date) VALUES ($e, $p, $d, $t, $h, $l, $c, $r, $f, $x, $cost, $total, NOW() )";
    $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());

    if (!$didit){
    echo("Your request has not been received, please try contacting us later");
    } else {
    echo("Thank you for your web site creation request, we will get back to you about further details at $e.");
    }

    // Complete the page.
    echo ("Thank you for your request to create a web site, an email has been sent to $e with the details you have selected for it, and further developements.");
    include ("includes/foot.html");

    } else { // If it did not run OK.
    echo '<p>You request could not be processed due to a system error. We apologize for any inconvenience.</p>';
    }

    mysql_close(); // Close the database connection.
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <title>Site Creation Request</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>

    <meta name="keywords" content="Home-Groan, Music downloads, MP3 downloads, MP3, Music, MP3 Music downloads, Accident downloads, Accident Music downloads, Accident MP3 downloads, Accident MP3 Music downloads, HG 001, Accident Albums, Home of Accident Recordings, Alley Cat, Brill O'Padd, Alley Cat and Brill O'Padd, Alley Cat and Brill O'Padd Song Writers, Accident Fated to Happen album, Child of War, Dearest Helen, Indian Lament, Sleepless Nights, Graveyard Sign, Help Me Nurze, Harmony in B E D, Glencoe, Remembering, Lambs to the Slaughter, Girl When I Loved You, Pretty Princess, See The City, Symphony of Romance, Dancing Between Silk Sheets, Is This Our Future" />

    <link href="error.css" rel="stylesheet" type="text/css"/>
    </head>

    <body>

    <div class="header">
    <a href="http://www.home-groan.com/"><img src="images/logo2.JPG" alt="Accident Recordings" /></a><p>Site Creation<br />Request Form</p>

    </div>

    <div class="leftcolumn">
    <table>

    <tr>
    <td><a href="index.php"><img src="images/logo_button.JPG" alt="Home-Groan Home" />Home</a></td>
    </tr>

    <tr>
    <td><a href="albums.php"><img src="images/logo2_button.JPG" alt="Accident Albums" />Accident Albums</a></td>
    </tr>

    <tr>
    <td><a href="screensavers.php"><img src="images/screen-saver_button.JPG" alt="Home-Groan Screen Savers" />Screen Savers </a></td>
    </tr>

    <tr>
    <td><a href="websites.php"><img src="images/website_button.JPG" alt="Home-Groan Web Sites"/>Web Sites</a></td>
    </tr>

    <tr>
    <td><a href="http://www.accidentrecordings.com/contact.php">Contact Us</a></td>
    </tr>

    </table>

    <p>
    <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88"></img></a><br />
    <br />
    <a href="http://jigsaw.w3.org/css-validator/">
    <img style="border:0;width:88px;height:31px"
    src="http://jigsaw.w3.org/css-validator/images/vcss"
    alt="Valid CSS!"></img>
    </a>
    </p>

    </div>
    <div class="centre">
    <form action="site_request.php" method="post">
    <fieldset>
    <p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>
    <p>How many HTML pages would you require?<br /><b>Number of Pages:</b> <input type="text" name="pages" size="3" maxlength="3" value="<?php if (isset($_POST['pages'])) echo $_POST['pages']; ?>" /> </p>
    <p>Please enter the style of page you require.<br /><b>Design Style:</b> <input type="text" name="design" size="15" maxlength="30" /></p>
    <p>Please enter the titles you want for each of your pages, with a comma to separate each title.<br /><b>Page Titles:</b> <textarea name="titles" cols="60" rows="5"></textarea></p>
    <p>Please select the colour you require for each section of your site, you can choose either the colour name or hexadecimal number.<br /></p>
    <p><b>Header:</b> <input type="text" name="header" size="15" maxlength="15" /></p>
    <p><b>Left Column:</b> <input type="text" name="left" size="15" maxlength="15" /></p>
    <p><b>Centre:</b> <input type="text" name="centre" size="15" maxlength="15" /></p>
    <p><b>Right Column:</b> <input type="text" name="right" size="15" maxlength="15" /></p>
    <p><b>Footer:</b> <input type="text" name="footer" size="15" maxlength="15" /></p>
    <p>If you require a Search or Contact Page, please enter either the page name, or <strong>both </strong>if both are required.<br />
    <b>Extra Pages:</b> <input type="text" name="extra" size="15" maxlength="15" /></p>
    </fieldset>

    <p><input type="submit" name="Send" value="Place Request" />

    <input type="reset" name="Submit2" value="Amend Request" /></p>

    </form>
    <table><tr><td><img src="images/page1.JPG" alt="Surround Style" /></td><td><img src="images/page2.JPG" alt="Alternative Surround Style" /></td><td><img src="images/page3.JPG" alt="3 Rows Style" /></td><td><img src="images/page4.JPG" alt="Triangle Style" /></td><td><img src="images/page5.JPG" alt="Alternative Triangle Style" /></td></tr></table>
    </div>
    <div class="footer">
    <h5>&copy; www.home-groan.com 2007, designed and built by <a href="http://www.home-groan.com">www.home-groan.com.</a></h5>
    </div>
    </body>
    </html>
    <?php
    ob_end_flush();
    ?>
     
    Alley Cat, May 17, 2007 IP
  2. WebHive

    WebHive Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    wow!... a lot of text, man.
    what error do you get?
     
    WebHive, May 17, 2007 IP
  3. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Didn't get any error, just got the form returned with email and numer in pages box.
     
    Alley Cat, May 18, 2007 IP
  4. WebHive

    WebHive Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try to change lines 88-94
    from


    if ($p < 4) {
    $cost = £30;
    } elseif (4 <= $p && $p < 8) {
    $cost = £25;
    } elseif ($p >= 8) {
    $cost = £23;
    }
    
    Code (markup):
    to

    if ($p < 4) {
    $cost = "£30";
    } elseif (4 <= $p && $p < 8) {
    $cost = "£25";
    } elseif ($p >= 8) {
    $cost = "£23";
    }
    Code (markup):
     
    WebHive, May 18, 2007 IP
  5. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Tried that WebHive, but still not submitting, this has the feel of a stinker.
     
    Alley Cat, May 18, 2007 IP
  6. Arson

    Arson Well-Known Member

    Messages:
    622
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    120
    #6
    change your query from:
    $query = "INSERT INTO site_request (email, pages, design, titles, header, left, centre, right, footer, extra, cost, total, request_date) VALUES ($e, $p, $d, $t, $h, $l, $c, $r, $f, $x, $cost, $total, NOW() )";
    Code (markup):
    to this:

    
    
    $query = "INSERT INTO `site_request` (email, pages, design, titles, header, left, centre, right, footer, extra, cost, total, request_date) VALUES ('$e', '$p', '$d', '$t', '$h', '$l', '$c', '$r', '$f', '$x', '$cost', '$total', 'NOW()' )";
    
    
    Code (markup):
    let me know how that works.... also try it with ' apostrophies around the fieldnames if the one i said doesnt work.. if neither work, make sure you are printing the mysql_error correctly, because if its not inserting, then there should be an error of some sort
     
    Arson, May 18, 2007 IP
  7. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Have just tried your suggestion but still to no avail, but you did mention something that struck a chord, I'm not getting any error messages, which now you mention it, is kinda unusual. All I get is the form reloading, but thanks for trying to help buddy.
     
    Alley Cat, May 18, 2007 IP
  8. WebHive

    WebHive Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Could you give a dump of database? I will check...
     
    WebHive, May 21, 2007 IP
  9. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    [​IMG]
     
    Alley Cat, May 21, 2007 IP
  10. donteatchicken

    donteatchicken Well-Known Member

    Messages:
    432
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    118
    #10
    i'd comment out all the if statements and see if the info at least goes into the database
     
    donteatchicken, May 21, 2007 IP
  11. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Got a step closer, a friend found that my submit button had a different name to the isset function, so now I'm actually getting the errors when I try to submit to database, so if anyone can help with these details I would very much appreciate it.

    The errors I am getting when I try to submit are:
    Please enter a page quantity between 1 and 99!

    Please enter your titles for each page!

    Please enter a colour for your header section!

    Please enter a colour for your centre section!

    You request could not be processed due to a system error. We apologize for any inconvenience.

    this is the code I have for this section:

    // Check for an email address.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
    $e = escape_data($_POST['email']);
    } else {
    $e = FALSE;
    echo '<p>Please enter a valid email address!</p>';
    }
    // Check for pages quantity.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['pages'])))) {
    $p = escape_data($_POST['pages']);
    } else {
    $p = FALSE;
    echo '<p>Please enter a page quantity between 1 and 99!</p>';
    }
    // Check for site design.
    if (eregi ('^[[:alnum:]\.\' \-]{2,30}$', stripslashes(trim($_POST['design'])))) {
    $d = escape_data($_POST['design']);
    } else {
    $d = FALSE;
    echo '<p>Please select the design you require!</p>';
    }
    // Check for page titles.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['titles'])))) {
    $t = escape_data($_POST['titles']);
    } else {
    $t = FALSE;
    echo '<p>Please enter your titles for each page!</p>';
    }
    // Check for a header colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['header'])))) {
    $h = escape_data($_POST['header']);
    } else {
    $h = FALSE;
    echo '<p>Please enter a colour for your header section!</p>'; } // Check for a left column colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['left'])))) {
    $l = escape_data($_POST['left']);
    } else {
    $l = '<i>No left column required!</i>';
    }
    // Check for a centre section colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['centre'])))) {
    $c = escape_data($_POST['centre']);
    } else {
    $c = FALSE;
    echo '<p>Please enter a colour for your centre section!</p>';
    }
    // Check for a right column colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['right'])))) {
    $r = escape_data($_POST['right']);
    } else {
    $r = '<i>No right column required!</i>';
    }
    // Check for a footer colour.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['footer'])))) {
    $f = escape_data($_POST['footer']);
    } else {
    $f = '<i>No footer section required!</i>';

    this is the code that delivers the final statement,

    // Complete the page.
    echo ("Thank you for your request to create a web site, an email has been sent to $e with the details you have selected for it, and further developements.");
    include ("includes/foot.html");
    } else { // If it did not run OK.
    echo '<p>You request could not be processed due to a system error. We apologize for any inconvenience.</p>';
    }
     
    Alley Cat, May 24, 2007 IP