Request Form not submitting

Discussion in 'PHP' started by Alley Cat, Feb 9, 2008.

  1. #1
    I have a form which people can complete to request a screen saver being built for them, but it is not submitting to the Screen_Saver table in my database, can anybody tell me what I am doing wrong with the following script, and how I need to adjust it?
    One oddity is that it is sending out the following message even when the fields have been typed in.

    A title is required for your Screen Saver!

    Please give us a brief description!

    
    <?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_connects.php'); // Connect to the database.
    
    	$sr=$_POST['screen_resolution'];
    	$te=$_POST['transition_effect'];
    	$t=$_POST['track'];
    	$display=$_POST['display'];
    	$p=$_POST['pictures'];
    	
    	$cost = 0.10;
    	$price = 0.30;
    	$total = ($p * $cost) + $price;
    
    	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>';
    	}
    
    	if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['title'])))) {
    		$title = escape_data($_POST['title']);
    	} else {
    		$title = FALSE;
    		echo '<p>A title is required for your Screen Saver!</p>';
    	}
    
    	if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['description'])))) {
    		$d = escape_data($_POST['description']);
    	} else {
    		$d = FALSE;
    		echo '<p>Please give us a brief description!</p>';
    	}
    	
    	if (eregi ('^[[:digit:]]{1,3}$', stripslashes(trim($_POST['pictures'])))) {
    		$p = escape_data($_POST['pictures']);
    	} else {
    		$p = FALSE;
    		echo '<p>Please enter the number of pictures you uploaded!</p>';
    	}
    	
    	if (isset($_POST['display'])) {
    		$display = ($_POST['display']);
    	} else {
    		$display = "FALSE";
    		echo '<p>Please select the length of time each image is to be displayed for.</p>';
    	}
    	
    	if (isset($_POST['track'])) {
    		$t = ($_POST['track']);
    	} else {
    		$t = "FALSE";
    		echo '<p>A track needs to be selected.</p>';
    	}
    	
    	if (isset($_POST['transition_effect'])) {
    		$te = ($_POST['transition_effect']);
    	} else {
    		$te = "FALSE";
    		echo '<p>A transition effect is required.</p>';
    	}
    
    	if (isset($_POST['screen_resolution'])) {
    		$sr = ($_POST['screen_resolution']);
    	} else {
    		$sr = "FALSE";
    		echo '<p>Your screen resolution is needed.</p>';
    	}
    
    	if ($e && $title && $d && $p && $t && $display && $te && $sr) {
    
    	$query = "Insert into Screen_Saver (email, title, description, pictures, display, track, screen_resolution, transition_effect, order_date, total) values('$e', '$title', '$d', '$p', '$display', '$t', '$sr', '$te', NOW(), $total)";
    	$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
    
    	if (!$result){
    		echo("Update unsuccessful");
    	}
    
    	if (!$didit){
    		echo("Your message has not been received, please try contacting us later");
    	} else {
    		echo("Thank you for your screen saver order, we will send it to you at $email.");
    	}
    
    	$subject = "Screen Saver Order";
    	$body = "Thank you for ordering the screen saver ".$title.".  You have informed us that you have submitted ".$p." images to display for ".$display." seconds with ".$te." as your transition effect, and you want them to fit a screen size of ".$sr.".  You have chosen ".$t." as your backing track.  This screen saver will be sent to ".$e." when it is ready.  Shortly after you are satisfied with the screen saver you will be billed by email for ".$total.".";
    
    	$didit = mail($email, $subject, $body, "alleycat@home-groan.com");
    
    	$subject = "Screen Saver Order";
    	$body = "An order has been placed for a Screen Saver called $title.  It contains $p images, which will have $te as transition effect for display upon $sr pixels.  The track required is $t , and they want the description of $d.  When completed, send it to $e.  The charge for this will be '&pound;'.$total.";
    
    	if(!mail("alleycat@home-groan.com", $subject, $body, "accident@accidentrecordings.com")){
    		print 'Your message has not been received, please try contacting us later.';
    	}
    	
    	}
    
    	}else{
    		?>
    
    <!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>Screen Saver Request</title>
    <script type="text/JavaScript">
    <!--
    var ref = document.referrer;
    document.write("<script language=\"JavaScript\" src=\"http://www.accidentrecordings.com/tracker.php?refer=" + escape(ref) + "\"></script>");
    //-->
    </script>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    
    <meta name="keywords" content="Home-Groan, 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, Accident Black Spot album, Accident In The Home album, Accident In The Making album, Accident Zone Ahead album" />
    
    <link href="error.css" rel="stylesheet" type="text/css"/>
    
    <script type="text/javascript">
    <!--
    var currentPic = "Album1";
    
    function hot(name){
     
        document.getElementById(currentPic).style.display = 'none';
        document.getElementById(name).style.display = 'inline';
        document.getElementById('mainPic').src ="images/" + name + '.JPG';
    
        currentPic = name;
    
      }
    // -->
    </script>
    
    </head>
    
    <body>
    
    <div class="header">
    <a href="http://www.home-groan.com"><img src="images/logo2.JPG" alt="Accident Recordings" /></a><p>Home Groan<br />Screen Saver Request Form</p>
    
    </div>
    
    <div class="leftcolumn">
    <a href="index.php"><img src="images/logo_button.JPG" alt="Home-Groan Home" />Home</a><br /><br /><br />
    <a href="albums.php"><img src="images/logo2_button.JPG" alt="Accident Albums" />Accident Albums</a><br /><br /><br />
    <a href="screensavers.php"><img src="images/screen-saver_button.JPG" alt="Home-Groan Screen Savers" />Screen Savers</a><br /><br /><br />
    <a href="http://www.accidentrecordings.com/contact.php">Contact Us</a>
    <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 method="post" action="Screen_Saver.php">
    <h2>All Fields are Required</h2>
    <p>Enter your registered PayPal email address here.<br />Email: <input name="email" type="text" size="40" maxlength="60" /></p>
    <p>Enter the name you want to give to your Screen Saver.<br />Title: <input name="title" type="text" size="30" maxlength="40" /></p>
    <p>Please enter a brief description here.<br />Description: <textarea name="description" cols="40" rows="2"></textarea></p>
    <p>How many images have you uploaded?<br />Number: <input name="pictures" type="text" size="5" maxlength="5" /></p>
    <p>Please choose your Screen Resolution (pixels):<br /><input type="radio" name="screen_resolution" value="640 * 480" />640 * 480,	<input type="radio" name="screen_resolution" value="800 * 600" />800 * 600,	<input type="radio" name="screen_resolution" value="1024 * 768" checked />1024 * 768, <input type="radio" name="screen_resolution" value="1280 * 960" />1280 * 960</p>
    <p>Select your transition effect for the images.<br />
    
    <?php
    
    $te = array ('Clock', 
                         'Clock Back', 
                         'Curtain', 
                         'Double Clock', 
                         'Mist', 
                         'Mosaic', 
                         'Mosaic Large', 
                         'Round Rain', 
                         'Rain',
                         'Alternate', 
                         'Slide in Left to Right',
                         'Slide in Right to Left',
                         'Slide in Top to Bottom', 
                         'Slide in Bottom to Top', 
                         'Roll in Left to Right', 
                         'Roll in Right to Left', 
                         'Roll in Top to Bottom', 
                         'Roll in Bottom to Top',
                         'Round In', 
                         'Round Out',
                         'Square In', 
                         'Square Out', 
                         'Circles', 
                         'Squares', 
                         'Horizontal Lines', 
                         'Vertical Lines',
                         'Power On', 
                         'Power Off', 
                         'Fan', 
                         'Fan Back', 
                         'Circles Spiral', 
                         'Double Circles Spiral', 
                         'Back Circles Spiral', 
                         'Back Double Circles Spiral', 
                         'Sierpinski Fractal', 
                         'Rhombus In', 
                         'Rhombus Out', 
                         'Arrow', 
                         'Towers', 
                         'Muntains');
                         
    echo '<select name="transition_effect">';
    
    foreach ($te as $value) {
    	echo "<option value=\"$value\">$value</option>\n";
    }
    
    echo '</select>';
    
    ?>
    
    </p>
    <p>Select the track you would like as the backing track to your Screen Saver.<br />
    
    <?php
    
    $t = array ('500 A Day', 
                    'Act of Union', 
                    'Angel Eyes', 
                    'Angel of Mercy', 
                    'Angelic Innocense', 
                    'Arizona Boots', 
                    'Big Girl', 
                    'Bug Eyed Sea Monster', 
                    'Can You Hear Me', 
                    'Caravan', 
                    'Child of War', 
                    'Come Along to Me', 
                    'Dancing Between Silk Sheets', 
                    'Dearest Helen', 
                    'Depths of Hell', 
                    'Dreaming of the Sun', 
                    'Drifting', 
                    'Flying High', 
                    'Girl When I Loved You', 
                    'Glencoe', 
                    'Graveyard Sign', 
                    'Harmony in B E D', 
                    'Help Me Nurze', 
                    'Honey To My Lips', 
                    'I Am She', 
                    'Image Makers', 
                    'Indian Lament', 
                    'Is This Our Future', 
                    'It\'s Too Late', 
                    'Lambs to the Slaughter', 
                    'Love It Babe', 
                    'Lovely Lady', 
                    'Macho Man', 
                    'Maybe Tomorrow', 
                    'Misty Was The Morning', 
                    'Moaning Sod', 
                    'Moorland Trip', 
                    'Muddley', 
                    'My Ballerina', 
                    'My Pleasures Are Simple', 
                    'My Poetry Rhymes', 
                    'Never Be Mine', 
                    'Odd Job Man', 
                    'Painting Pictures', 
                    'Passion for Loving', 
                    'Planting Different Seeds', 
                    'Poets Corner', 
                    'Potent Images', 
                    'Pretty Maiden', 
                    'Pretty Princess', 
                    'Remembering', 
                    'Rhythm Method', 
                    'Ring My Bell', 
                    'Rock n Roll Singer', 
                    'Sacrificial Man', 
                    'See The City', 
                    'Sleepless Nights', 
                    'Song of Your Land', 
                    'Songs of Yesterday', 
                    'Supermarket Blues', 
                    'Symphony of Romance', 
                    'Thank God For Love', 
                    'The River', 
                    'Think', 
                    'Tortured Lady', 
                    'Travelling Around', 
                    'Undisputed Magician', 
                    'Warrior Forlorn', 
                    'When I First Came To This Town', 
                    'Wings of Freedom', 
                    'Woman Love Me', 
                    'Zombie');
                    
    echo '<select name="track">';
    
    foreach ($t as  $value) {
    	echo "<option value=\"$value\">$value</option>\n";
    }
    
    echo '</select>';
    
    ?>
    
    </p>
    
    <?php
    
    $display = range (1, 30);
    
    echo '<p>Please select the number of seconds each image will display for.&nbsp;
    <select name="display">';
    
    foreach ($display as $value) {
    	echo "<option value=\"$value\">$value</option>\n";
    }
    
    echo '</select></p>';
    
    ?>
    <p><input type="submit" name="Send" value="Place Order" /> 
    
    <input type="reset" name="Submit2" value="Amend Order" /></p>
    <input type="hidden" name="submitted" value="TRUE" />
    
    </form> 
    
    </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();
    ?>
    
    Code (markup):
    Is there something that I have in my connection script that is stopping the submission?
    
    <?php
    
    DEFINE ('DB_USER', 'name');
    DEFINE ('DB_PASSWORD', 'password');
    DEFINE ('DB_HOST', 'localhost');
    DEFINE ('DB_NAME', 'good_name');
    
    if ($dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)) {
    
    	if (!mysql_select_db (DB_NAME)) {
    	
    		trigger_error("Could not select the database!\n<br />MYSQL Error: " . mysql_error());
    		include ('/includes/footer.html');
    		exit();
    		
    	}
    
    } else {
    
    trigger_error("Could not connect to MYSQL!\n<br />MYSQL  Error: " . mysql_error());
    	include ('/includes/footer.html');
    	exit();
    }
    function escape_data ($data) {
    
    	if (ini_get('magic_quotes_gpc')) {
    		$data = stripslashes($data);
    	}
    	
    	if (function_exists('mysql_real_escape_string')) {
    		global $dbc;
    		$data = mysql_real_escape_string (trim($data) , $dbc);
    	} else {
    		$data = mysql_escape_string (trim($data));
    	}
    	return $data;
    
    }
    ?>
    
    Code (markup):
    I hope someone on here can help me.

    I think it may have something to do with the following code, I have the feeling that I need to add more code in this section.
    
    
    	$query = "Insert into Screen_Saver (email, title, description, pictures, display, track, screen_resolution, transition_effect, order_date, total) values('$e', '$title', '$d', '$p', '$display', '$t', '$sr', '$te', NOW(), $total)";
    	$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
    
    	if (!$result){
    		echo("Update unsuccessful");
    	}
    
    	if (!$didit){
    		echo("Your request has not been received, please try contacting us later");
    	} else {
    		echo("Thank you for your screen saver order, we will send it to you at $email.");
    	}
    
    Code (markup):
     
    Alley Cat, Feb 9, 2008 IP
  2. barts2108

    barts2108 Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can try to use the submit button for the isset()

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

    change to

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

    when it works, you don't need the hidden field
     
    barts2108, Feb 9, 2008 IP
  3. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for trying Barts2108 but did just the same.
     
    Alley Cat, Feb 9, 2008 IP
  4. barts2108

    barts2108 Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ah.. now I see what I missed in your text.

    assuming the code is in file Screen_Saver.php and the form also points
    to this file, then the submit does work, as you get an error message
    which is echo'd after the isset($_POST['submitted']).

    The check for a valid email address is executed, and it evaluates to a
    valid email address.

    I see that you use the same eregi function for title and all the others. I am
    not a nerd with eregi functions, but I can see this

    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['title'])))) {

    will check if there is a valid email address containing the @ sign, at least
    something before the at sign, a domain name and a 2 to 4 character 'country code'

    Try this: Put an email address in all fields and check if you get through the submit.

    If so, reconsider using eregi for checking if a title fields contains text. If it should contain text either numeric, or alpha numeric try something like this

    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*', stripslashes(trim($_POST['title'])))) {

    not 100% sure the syntax is correct, but it will not check for @ signs, nor for domain names and country codes.

    Easier would be :

    if (!empty(stripslashes(trim($_POST['title'])))) {

    Then you only check if something has been filled in, while white spaces only are not valid.

    Good luck
     
    barts2108, Feb 9, 2008 IP
  5. Alley Cat

    Alley Cat Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks everyone, I owe you all a great big debt of thanks for all the advice I received from you, but what I thought was a failure to submit to the table was actually in the echoing of the successful message, the $didit was referring to the sending of mail, and so I adjusted it so that it made sense.
    
    
    	if ($e && $title && $d && $p && $t && $display && $te && $sr) {
    
    	$query = "Insert into Screen_Saver (email, title, description, pictures, display, track, screen_resolution, transition_effect, order_date, total) values('$e', '$title', '$d', '$p', '$display', '$t', '$sr', '$te', NOW(), $total)";
    	$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
    
    	if (!$result){
    		echo("Update unsuccessful");
    	}
    
    	$subject = "Screen Saver Order";
    	$body = "Thank you for ordering the screen saver ".$title.".  You have informed us that you have submitted ".$p." images to display for ".$display." seconds with ".$te." as your transition effect, and you want them to fit a screen size of ".$sr.".  You have chosen ".$t." as your backing track.  This screen saver will be sent to ".$e." when it is ready.  Shortly after you are satisfied with the screen saver you will be billed by email for ".$total.".";
    
    	$subject = "Screen Saver Order";
    	$body = "An order has been placed for a Screen Saver called $title.  It contains $p images, which will have $te as transition effect for display upon $sr pixels.  The track required is $t , and they want the description of $d.  When completed, send it to $e.  The charge for this will be '&pound;'.$total.";
    
    	if(!mail($subject, $body, "server.email.address")){
    		print 'Your message has not been received, please try contacting us later.';
    	}
    
    	$didit = mail($e, $subject, $body, "my.email.address");
    
    	if (!$didit){
    		echo("Your request has not been received, please try contacting us later");
    	} else {
    		echo("Thank you for your screen saver order, we will send it to you at $e.");
    	}
    	
    
    Code (markup):
     
    Alley Cat, Feb 9, 2008 IP