Jump to content

j05hr

Members
  • Posts

    237
  • Joined

  • Last visited

    Never

Posts posted by j05hr

  1. The other code didn't work

    throw new Exception('<p style="font-weight: bold; color: #C00">Please use a valid email address</p>');

     

    It comes up with

     

    Parse error: syntax error, unexpected T_NEW in /homepages/32/d244452625/htdocs/quote.php on line 27

     

  2. Thanks, that

    die('<p style="font-weight: bold; color: #C00">Please use a valid email address</p>');

    works but as you said die function stops all the code after it so it doesn't submit it on the same page, is there any way to substitute die for something else so the error message will come up in the same page?

  3. It comes out blank with no message,

     

    Is this how it should look?

     

    <?php 
    
    // Check for form submission:
    if (isset($_POST['submitted'])) {
    
    // Minimal form validation:
    if (!empty($_POST['name']) && !empty($_POST['number']) && !empty($_POST['eMail']) && !empty($_POST['address']) && !empty($_POST['size']) 
    && !empty($_POST['quantity']) && !empty($_POST['paperType']) && !empty($_POST['colours']) && !empty($_POST['finishing']) && !empty($_POST['otherInfo']) ) {
    
    function validateEmailAddr($email){
    		return preg_match('/[^\x00-\x20()<>@,;:\\".
    		[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]
    		\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]
    		\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]
    		\x7f-\xff]+)+/i', $email);
    	}
    
    	if(!validateEmailAddr($email)){
    		die($message);
    	}
    
    	// Create the body:
    	$body = "Name: {$_POST['name']} \n\nNumber: {$_POST['number']} \n\nemail: {$_POST['eMail']}  \n\nAddress: {$_POST['address']} \n\nsize: {$_POST['size']} 
    	\n\nQuantity: {$_POST['quantity']} \n\nPaperType: {$_POST['paperType']} \n\nColours: {$_POST['colours']} \n\nFinishing: {$_POST['finishing']} \n\nOther Info: {$_POST['otherInfo']}";
    
    	// Make it no longer than 70 characters long:
    	$body = wordwrap($body, 70);
    
    	// Send the email:
    	mail('', 'Contact Form Submission', $body, "From: {$_POST['eMail']}");
    
    	// Print a message:
    	$message = "<p style=\"font-weight: bold; color: #ed008c\">Thank you for contacting us {$_POST['name']}. We will reply to you on {$_POST['eMail']} within 48 hours.";
    
    
    	// Clear $_POST (so that the form's not sticky):
    	$_POST = array();
    
    } else {
    	$message = '<p style="font-weight: bold; color: #C00">Please fill out all the the fields in the form.</p>';
    
    }
    
    } // End of main isset() IF.
    
    // Create the HTML form:
    ?>
    

  4. Thanks for the help,  Am I supposed to use both the functions or are they doing the same thing?  The first one worked but the error message came up on a new page.

     

    I tried to turn

     

    if(!validateEmailAddr($email)){
    die("Invalid email");
    }
    

     

    into

     

    if(!validateEmailAddr($email)){
    		$message = '<p style="font-weight: bold; color: #C00">Please use a valid email address</p>';
    	}
    

     

    But then the form submitted after I did that.  How can I write my error message to come out on the same page using $message? 

     

    I'm sorry my PHP skills aren't great,

     

    Thanks again for your help,

    Josh

  5. Hi,

     

    I have this script that submits my form, it makes you fill out all the fields but I want it to be able to make you use an @ sign as a valid email address.  How can I do this?

     

    Here is my code,  I've taken all sensitive information out like my email address and links.

     

    
    <!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" lang="en" xml:lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <?php 
    
    // Check for form submission:
    if (isset($_POST['submitted'])) {
    
    // Minimal form validation:
    if (!empty($_POST['name']) && !empty($_POST['number']) && !empty($_POST['eMail']) && !empty($_POST['address']) && !empty($_POST['size']) 
    && !empty($_POST['quantity']) && !empty($_POST['paperType']) && !empty($_POST['colours']) && !empty($_POST['finishing']) && !empty($_POST['otherInfo']) ) {
    
    	// Create the body:
    	$body = "Name: {$_POST['name']} \n\nNumber: {$_POST['number']} \n\nemail: {$_POST['eMail']}  \n\nAddress: {$_POST['address']} \n\nsize: {$_POST['size']} 
    	\n\nQuantity: {$_POST['quantity']} \n\nPaperType: {$_POST['paperType']} \n\nColours: {$_POST['colours']} \n\nFinishing: {$_POST['finishing']} \n\nOther Info: {$_POST['otherInfo']}";
    
    	// Make it no longer than 70 characters long:
    	$body = wordwrap($body, 70);
    
    	// Send the email:
    	mail('', 'Contact Form Submission', $body, "From: {$_POST['eMail']}");
    
    	// Print a message:
    	$message = "<p style=\"font-weight: bold; color: #ed008c\">Thank you for contacting us {$_POST['name']}. We will reply to you on {$_POST['eMail']} within 48 hours.";
    
    
    	// Clear $_POST (so that the form's not sticky):
    	$_POST = array();
    
    } else {
    	$message = '<p style="font-weight: bold; color: #C00">Please fill out all the the fields in the form.</p>';
    
    }
    
    } // End of main isset() IF.
    
    // Create the HTML form:
    ?>
    <body>
    
    <div class="wrapper">
            <div id="header">
            	<img src="images/logo.jpg" alt="logo" />
                <div id="headerImage">
                 
                </div>
             </div>
    	<div id="navigation">
        	<div id="nav">
    			<ul>
    				<li class="about"><a href="about.html">About</a></li>
    				<li class="print"><a href="print.html">Print</a></li>
    				<li class="design"><a href="design.html">Design</a></li>
    				<li class="web"><a href="web.html">Web</a></li>
    				<li class="shop"><a href="shop.html">Shop</a></li>
    				<li class="quotationActive"><a href="quote.php">Quotation</a></li>
    				<li class="contact"><a href="contact.html">Contact</a></li>
    			</ul>
    	</div>
    	</div>
            <div id="quoteContent">
    	      <div id="contentLeftQuote">
                <form action="quote.php" method="post" class="mailing" />
    			<h3>Contact Information</h3>
    			<h4>Contact Name</h4>
    			<input class="contactInput" type="text" name="name" class="contact" id="name" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>"/>
    			<h4>Phone Number</h4>
    			<input class="contactInput" type="text" name="number" class="contact" id="number" value="<?php if (isset($_POST['number'])) echo $_POST['number']; ?>"/>
    			<h4>Email Address</h4>
    			<input class="contactInput" type="text" name="eMail" class="contact" id="eMail" value="<?php if (isset($_POST['eMail'])) echo $_POST['eMail']; ?>"/>
    			<h4>Address</h4>
    			<textarea class="contactInput" name="address" rows="5" cols="30" id="address" value="<?php if (isset($_POST['address'])) echo $_POST['address']; ?>" ></textarea>
    
                </div>
                <div id="contentRightQuote"> 
    			<div class="contentQuote">
    			<h3>Quotation</h3>
    			<div class="floatLeft">
    			<h4>Size:</h4>
    			<input type="text" name="size" id="size" value="<?php if (isset($_POST['size'])) echo $_POST['size']; ?>" />
    			</div>
    			<div class="floatRight">
    			<h4>Quantity:</h4>
    			<input type="text" name="quantity" id="quantity" value="<?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>" />
    			</div>
    			<div class="clear">
    			<h4>Paper Type/Weight:</h4>
    			<input class="longInput" type="text" name="paperType" id="paperType" value="<?php if (isset($_POST['paperType'])) echo $_POST['paperType']; ?>" />
    			</div>
    			<div class="floatLeft">
    			<h4>Number of Colours:</h4>
    			<input type="text" name="colours" id="colours" value="<?php if (isset($_POST['colours'])) echo $_POST['colours']; ?>" />
    			</div>
    			<div class="floatRight">
    			<h4>Finishing Info:</h4>
    			<input type="text" name="finishing" id="finishing" value="<?php if (isset($_POST['finishing'])) echo $_POST['finishing']; ?>" />
    			</div>
    			<div class="clear">
    			<h4>Other Info:</h4>
    			<textarea name="otherInfo" rows="5" cols="40" id="otherInfo" <?php if (isset($_POST['otherInfo'])) echo $_POST['otherInfo']; ?>></textarea>
    			<p class="submit"><input type="submit" name="submitted" value="" /></p>
    			</div>
    			</div>
    
            	</div>
            </div>
            <div id="footer">
            <div id="footerlinks"><a href="about.html">About</a> <a href="print.html">Print</a> <a href="design.html">Design</a> <a href="web.html">Web</a> <a href="quotation.php">Quotation</a> <a href="contact.html">Contact</a> <a href="terms.html">Terms</a></div>
    	<div id="digitalStudio">© </a>
            </div>
            </div>
        </div>
    </body>
    </html>
    

     

    Thanks for any help,

    Josh

  6. That's exactly what I wanted it to do, thanks so much.  Is it possible to explain what you did as I'm trying to learn as well rather then get someone to do my work and not learn what's happening. 

     

    Yeah they should be checked after you do the calculation, otherwise it's very confusing.

     

    The next bit is adding two upload files for the double sided (like the one for the single side)

     

    I'm sure I will be back here asking for help.

     

    Thanks again,

     

    It's really appreciated.

  7. That's ok,

     

    They are still coming out as the same price which I don't understand as they have different values

     

    
    <?php # Script 3.10 - calculator.php #5
    
    $page_title = 'Digital Studio Cost Calculator';
    include ('includes/header.html');
    
    /* This function calculates a total
    and then returns the results. */
    function calculate_total ($qty, $cost, $tax = 0) {
    $single = ($qty * 5);
    $double = ($qty * 10);
    $total = ($qty * 0.05);
    
    return number_format($total, 2);
    
    } // End of function.
    
    // Check for form submission:
    if (isset($_POST['q1'])) 
    {
    $Q1_Value = $_POST['q1'];
    }
    //Dump the value of the radio into a variable
    
    //Then do an if statements for what the value of that variable is
    
    if($Q1_Value == "SINGLE")
    {
      //Do something if single sided
    }
    if($Q1_Value == "DOUBLE")
    {
    //Do something if doublesided
    }
    {
    
    
    
    // Minimal form validation:
    if ( is_numeric($_POST['quantity']) ) {
    
    	// Print the heading:
    	$success = 'Upload front side of card: <input name="image" accept="image/jpeg" type="file"> ';
    
    	// Call the function, with or without tax:
    	if (is_numeric($_POST['tax'])) {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price'], $_POST['tax']);
    	} else {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price']);
    	}
    
    	// Print the results:
    	//echo '<p style="font-weight: bold; color: #C00">The total cost of purchasing ' . $_POST['quantity'] . ' business card(s), is £' . $sum . '.</p>';
    
    } else { // Invalid submitted values.
    	echo '<h1>Error!</h1>
    	<p class="error">Please enter a valid quantity and price.</p>';
    }
    
    } // End of main isset() IF.
    
    // Leave the PHP section and create the HTML form:
    ?>
    <h1>Digital Studio Order Form</h1>
    <form action="calculator.php" method="post">
      <p>Quantity:
           <select name="quantity">
    			<option value= "100" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 100) echo 'selected="selected"'; ?>>100</option>
                    <option value= "250" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 250) echo 'selected="selected"'; ?>>250</option>
                    <option value= "500" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 500) echo 'selected="selected"'; ?>>500</option>
      </select> </p>
            <p>Double sided:
              <INPUT TYPE="radio" NAME="q1" VALUE="DOUBLE">
    	  <br />
    	  <br />
               Single Sided:
               <INPUT TYPE="radio" NAME="q2" VALUE="SINGLE">
    	    <?php if (!empty($success)) {
                echo "<p class=\"messge\">" . $success . "</p>";
             } ?>
    
            <p>Total: £<?php echo $sum?></p>
    
        <p><input type="submit" name="submit" value="Calculate!" /></p>
      <input type="hidden" name="submitted" value="TRUE" />
    </form>
    <?php // Include the footer:
    include ('includes/footer.html');
    ?>
    

  8. The single one now works but the double one doesn't.  I made an if statement for it.

     

    <?php # Script 3.10 - calculator.php #5
    
    $page_title = 'Digital Studio Cost Calculator';
    include ('includes/header.html');
    
    /* This function calculates a total
    and then returns the results. */
    function calculate_total ($qty, $cost, $tax = 0) {
    $single = ($qty * 5);
    $double = ($qty * 10);
    $total = ($qty * 0.05);
    
    return number_format($total, 2);
    
    } // End of function.
    
    // Check for form submission:
    if (isset($_POST['q1'])) {
    }
    if (isset($_POST['q2'])) {
    
    
    
    // Minimal form validation:
    if ( is_numeric($_POST['quantity']) ) {
    
    	// Print the heading:
    	$success = 'Upload front side of card: <input name="image" accept="image/jpeg" type="file"> ';
    
    	// Call the function, with or without tax:
    	if (is_numeric($_POST['tax'])) {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price'], $_POST['tax']);
    	} else {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price']);
    	}
    
    	// Print the results:
    	//echo '<p style="font-weight: bold; color: #C00">The total cost of purchasing ' . $_POST['quantity'] . ' business card(s), is £' . $sum . '.</p>';
    
    } else { // Invalid submitted values.
    	echo '<h1>Error!</h1>
    	<p class="error">Please enter a valid quantity and price.</p>';
    }
    
    } // End of main isset() IF.
    
    // Leave the PHP section and create the HTML form:
    ?>
    <h1>Digital Studio Order Form</h1>
    <form action="calculator.php" method="post">
      <p>Quantity:
           <select name="quantity">
    <option value= "100" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 100) echo 'selected="selected"'; ?>>100</option>
                    <option value= "250" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 250) echo 'selected="selected"'; ?>>250</option>
                    <option value= "500" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 500) echo 'selected="selected"'; ?>>500</option>
      </select> </p>
            <p>Double sided:
              <INPUT TYPE="radio" NAME="q1" VALUE="double">
    	  <br />
    	  <br />
               Single Sided:
               <INPUT TYPE="radio" NAME="q2" VALUE="single">
    	    <?php if (!empty($success)) {
                echo "<p class=\"messge\">" . $success . "</p>";
             } ?>
    
            <p>Total: £<?php echo $sum?></p>
    
        <p><input type="submit" name="submit" value="Calculate!" /></p>
      <input type="hidden" name="submitted" value="TRUE" />
    </form>
    <?php // Include the footer:
    include ('includes/footer.html');
    ?>
    

  9. Yeah retrieving the radio select.

     

    I changed the radio buttons so now I have

     

    
    <?php # Script 3.10 - calculator.php #5
    
    $page_title = 'Digital Studio Cost Calculator';
    include ('includes/header.html');
    
    /* This function calculates a total
    and then returns the results. */
    function calculate_total ($qty, $cost, $tax = 0) {
    $single = ($qty * 5);
    $double = ($qty * 10);
    $total = ($qty * 0.05);
    
    return number_format($total, 2);
    
    } // End of function.
    
    // Check for form submission:
    if (isset($_POST['submitted'])) {
    
    // Minimal form validation:
    if ( is_numeric($_POST['quantity']) ) {
    
    	// Print the heading:
    	$success = 'Upload front side of card: <input name="image" accept="image/jpeg" type="file"> ';
    
    	// Call the function, with or without tax:
    	if (is_numeric($_POST['tax'])) {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price'], $_POST['tax']);
    	} else {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price']);
    	}
    
    	// Print the results:
    	//echo '<p style="font-weight: bold; color: #C00">The total cost of purchasing ' . $_POST['quantity'] . ' business card(s), is £' . $sum . '.</p>';
    
    } else { // Invalid submitted values.
    	echo '<h1>Error!</h1>
    	<p class="error">Please enter a valid quantity and price.</p>';
    }
    
    } // End of main isset() IF.
    
    // Leave the PHP section and create the HTML form:
    ?>
    <h1>Digital Studio Order Form</h1>
    <form action="calculator.php" method="post">
      <p>Quantity:
           <select name="quantity">
    <option value= "100" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 100) echo 'selected="selected"'; ?>>100</option>
                    <option value= "250" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 250) echo 'selected="selected"'; ?>>250</option>
                    <option value= "500" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 500) echo 'selected="selected"'; ?>>500</option>
      </select> </p>
            Double sided: <INPUT TYPE="radio" NAME="q1" VALUE="DOUBLE"> <br />
    	Single Sided: <INPUT TYPE="radio" NAME="q1" VALUE="SINGLE">
    	    <?php if (!empty($success)) {
                echo "<p class=\"messge\">" . $success . "</p>";
             } ?>
    
            <p>Total: £<?php echo $sum?></p>
    
        <p><input type="submit" name="submit" value="Calculate!" /></p>
      <input type="hidden" name="submitted" value="TRUE" />
    </form>
    <?php // Include the footer:
    include ('includes/footer.html');
    ?>
    

     

    Which $_POST am I checking for q1?

     

    this one?

     

    if (isset($_POST['submitted'])) {
    

  10. I have a form http://www.bulletproofwebdesign.co.uk/orderform/calculator.php which calculates the quantity of the business cards you have ordered. 

     

    What I want to do is charge different prices for single sided or double sided cards.

     

    This is the function that does that calculation

    function calculate_total ($qty, $cost, $tax = 0) {
    $single = ($qty * 5);
    $double = ($qty * 10);
    $total = ($qty * 10);
    

     

    And this is the bit that returns the data

    return number_format($total, 2);

     

    How can I make the radio buttons select the or $double or $single? and then return them?

     

    Whole code

     

    <?php # Script 3.10 - calculator.php #5
    
    $page_title = 'Digital Studio Cost Calculator';
    include ('includes/header.html');
    
    /* This function calculates a total
    and then returns the results. */
    function calculate_total ($qty, $cost, $tax = 0) {
    $single = ($qty * 5);
    $double = ($qty * 10);
    $total = ($qty * 10);
    
    return number_format($total, 2);
    
    } // End of function.
    
    // Check for form submission:
    if (isset($_POST['submitted'])) {
    
    // Minimal form validation:
    if ( is_numeric($_POST['quantity']) ) {
    
    	// Print the heading:
    	$success = 'Upload front side of card: <input name="image" accept="image/jpeg" type="file"> ';
    
    	// Call the function, with or without tax:
    	if (is_numeric($_POST['tax'])) {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price'], $_POST['tax']);
    	} else {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price']);
    	}
    
    	// Print the results:
    	//echo '<p style="font-weight: bold; color: #C00">The total cost of purchasing ' . $_POST['quantity'] . ' business card(s), is £' . $sum . '.</p>';
    
    } else { // Invalid submitted values.
    	echo '<h1>Error!</h1>
    	<p class="error">Please enter a valid quantity and price.</p>';
    }
    
    } // End of main isset() IF.
    
    // Leave the PHP section and create the HTML form:
    ?>
    <h1>Digital Studio Order Form</h1>
    <form action="calculator.php" method="post">
      <p>Quantity:
           <select name="quantity">
    <option value= "100" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 100) echo 'selected="selected"'; ?>>100</option>
                    <option value= "250" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 250) echo 'selected="selected"'; ?>>250</option>
                    <option value= "500" <?php if (isset($_POST['quantity']) && $_POST['quantity'] == 500) echo 'selected="selected"'; ?>>500</option>
      </select> </p>
            <p>Double sided:
              <INPUT TYPE="radio" NAME="q1" VALUE="yes">
               Single Sided
               <INPUT TYPE="radio" NAME="q1" VALUE="no">
    	    <?php if (!empty($success)) {
                echo "<p class=\"messge\">" . $success . "</p>";
             } ?>
    
            <p>Total: £<?php echo $sum?></p>
    
        <p><input type="submit" name="submit" value="Calculate!" /></p>
      <input type="hidden" name="submitted" value="TRUE" />
    </form>
    <?php // Include the footer:
    include ('includes/footer.html');
    ?>
    

     

  11. I've got a dropdown box and when you submit the value, the drop down resets itself.

     

    http://www.bulletproofwebdesign.co.uk/orderform/calculator.php

     

    <form action="calculator.php" method="post">
      <p>Quantity: 
        	<select name="quantity">
    <option value= "100" <?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>>100</option>
                    <option value= "250" <?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>>250</option>
                    <option value= "500" <?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>>500</option>
      </select> </p>
            <p>Double sided
              <INPUT TYPE="radio" NAME="q1" VALUE="yes">
               Single Sided
               <INPUT TYPE="radio" NAME="q1" VALUE="no">
      
            <p>Total: £<?php echo $sum?></p> 
        <p><input type="submit" name="submit" value="Calculate!" /></p>
      <input type="hidden" name="submitted" value="TRUE" />
    </form>
    

     

    Is there a way I can make it not reset after you change the value?

     

    Thanks,

    Josh

  12. So what would you put in there as the text to set the number?

     

    I know this doesn't work but this is my attempt just to show that I am trying to learn

     

    <p>Price: <?php $price =  (10); /></p>

  13. Hi,

     

    I'm trying to make an online order form

     

    http://www.bulletproofwebdesign.co.uk/orderform/calculator.php

     

    I want it to be like this one

     

    http://www.dyn-web.com/code/order_form/example1.php#

     

    So that the user can't choose the price, just the quantity.

     

    How can I add that to my code?

     

    <?php # Script 3.10 - calculator.php #5
    
    $page_title = 'Digital Studio Cost Calculator';
    include ('includes/header.html');
    
    /* This function calculates a total
    and then returns the results. 
    The $tax argument is optional (it has a default value). */
    function calculate_total ($qty, $cost, $tax = 0) {
    
    
    $total = ($qty * $cost);
    $taxrate = ($tax / 100); // Turn 5% into .05.
    $total += ($total * $taxrate); // Add the tax.
    
    return number_format($total, 2);
    
    } // End of function.
    
    // Check for form submission:
    if (isset($_POST['submitted'])) {
    
    // Minimal form validation:
    if ( is_numeric($_POST['quantity']) && is_numeric($_POST['price']) ) {
    
    	// Print the heading:
    	echo '<h1>Total Cost</h1>';
    
    	// Call the function, with or without tax:
    	if (is_numeric($_POST['tax'])) {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price'], $_POST['tax']);
    	} else {
    		$sum = calculate_total ($_POST['quantity'], $_POST['price']);
    	}
    
    	// Print the results:
    	echo '<p style="font-weight: bold; color: #C00">The total cost of purchasing ' . $_POST['quantity'] . ' business card(s) at £' . number_format ($_POST['price'], 2) . ' each, is £' . $sum . '.</p>';
    
    } else { // Invalid submitted values.
    	echo '<h1>Error!</h1>
    	<p class="error">Please enter a valid quantity and price.</p>';
    }
    
    } // End of main isset() IF.
    
    // Leave the PHP section and create the HTML form:
    ?>
    <h1>Digital Studio Online Order Form</h1>
    <form action="calculator.php" method="post">
    <p>Quantity: <input type="text" name="quantity" size="5" maxlength="5" value="<?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>" /></p>
    <p>Price: <input type="text" name="price" size="5" maxlength="10" value="<?php if (isset($_POST['price'])) echo $_POST['price']; ?>" /></p>
    <p><input type="submit" name="submit" value="Calculate!" /></p>
    <input type="hidden" name="submitted" value="TRUE" />
    </form>
    <?php // Include the footer:
    include ('includes/footer.html');
    ?>
    

  14. Can anyone explain why this wouldn't upload my image to my ftp, it loads the blob into the database so I know the name of the database is ok.  I also made the directory in my ftp called uploads.  So why will the image not upload to the folder?

     

    <?php require_once("includes/session.php"); ?>
    <?php require_once("includes/connection.php"); ?>
    <?php require_once("includes/functions.php"); ?>
    <?php confirm_logged_in(); ?>
    <?php
          if (intval($_GET['subj']) == 0) {
             redirect_to("content1.php");
          }
          if (isset($_POST['submit'])) {
             $errors = array();
    
             $required_fields = array('menu_name', 'position', 'visible', 'content', 'house_price', 'bedrooms', 'propType');
             foreach($required_fields as $fieldname) {
                if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) { 
                   $errors[] = $fieldname; 
                }
             }
             $fields_with_lengths = array('menu_name' => 30);
             foreach($fields_with_lengths as $fieldname => $maxlength ) {
                if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; }
             }
             
             if (empty($errors)) {
                // Perform Update
                $id = mysql_prep($_GET['subj']);
                $menu_name = mysql_prep($_POST['menu_name']);
                $position = mysql_prep($_POST['position']);
                $visible = mysql_prep($_POST['visible']);
                $content = mysql_prep($_POST['content']);
                $house_price = str_replace(",", "", $_POST['house_price']);
    		$house_price = mysql_prep($house_price);
                $bedrooms = mysql_prep($_POST['bedrooms']);
                $propType = mysql_prep($_POST['propType']);
    		$typeofsale = mysql_prep($_POST['typeofsale']);
    		$image = mysql_prep($_POST['image']);
    
    		///////////////////////
    		///////////////////////
    		///////////////////////
    		///////////////////////
    			if (is_uploaded_file ($_FILES['image']['tmp_name']))
        {
          $message = "The file has been uploaded";
            $test = 'uploads/'.$_FILES['image']['name'];
            //$temp = 'uploads/fred.jpg';
            echo $temp;
            if (move_uploaded_file ($_FILES['image']['tmp_name'], $test))
            {
               $message = "The file has been moved";
            }
            else
            {
                $errors[] = 'The file could not be moved';
                $test = $_FILES['image']['tmp_name'];
                echo 'failed';
            }
            $image = $test;
        }
    	/////////////////////////
    	/////////////////////////
    	/////////////////////////
    	/////////////////////////
                
                $query = "UPDATE subjects SET 
                         menu_name = '{$menu_name}', 
                         position = {$position}, 
                         visible = {$visible},
                         content = '{$content}',
                         house_price = '{$house_price}',
                         bedrooms = '{$bedrooms}',
                         propType = '{$propType}',
    				 buyRentNew = '{$typeofsale}',
    				 image = '{$image}'
                      WHERE id = {$id}";
                $result = mysql_query($query, $connection);
                if (mysql_affected_rows() == 1) {
                   // Success
                   $message = "The subject was successfully updated.";
                } else {
                   // Failed
                   $message = "The subject update failed.";
                   $message .= "<br />". mysql_error();
                }
                
             } else {
                // Errors occurred
                $message = "There were " . count($errors) . " errors in the form.";
             }
             
             
             
             
          } // end: if (isset($_POST['submit']))
    ?>
    <?php find_selected_page();?>
    <?php include("includes/header.php"); ?>
    <div id="content">
          <h2> Buying Edit Page</h2>
          <br />
          <h5>Edit Subject: <?php echo $sel_subject ['menu_name']; ?></h5>
             <?php if (!empty($message)) {
                echo "<p class=\"messge\">" . $message . "</p>";
             } ?>
             <?php
             // output a list of the fields that had errors
             if (!empty($errors)) {
                echo "<p class=\"errors\">";
                //echo "Please review the following fields:<br />";
                foreach($errors as $error) {
                   echo " - " . $error . "<br />";
                }
                echo "</p>";
             }
             ?>
             <form enctype="multipart/form-data" action="edit_subject.php?subj=<?php echo urlencode($sel_subject['id']);?>" method="post">
                <p>Subject name:
                   <input type="text" name="menu_name" value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" />
                </p>
                <p>House Price:
                   <input type="text" name="house_price" value="<?php echo $sel_subject['house_price']; ?>" id="house_price" />
                </p>
                <p>Bedrooms:
                   <select name="bedrooms"/>
                      <option <?php echo $sel_subject['bedrooms'] == '1' ? 'selected="selected"' : ''; ?>>1</option>
                      <option <?php echo $sel_subject['bedrooms'] == '2' ? 'selected="selected"' : ''; ?>>2</option>
                      <option <?php echo $sel_subject['bedrooms'] == '3' ? 'selected="selected"' : ''; ?>>3</option>
                      <option <?php echo $sel_subject['bedrooms'] == '4' ? 'selected="selected"' : ''; ?>>4</option>
                      <option <?php echo $sel_subject['bedrooms'] == '5' ? 'selected="selected"' : ''; ?>>5+</option>
                   </select>
                </p>
                <p>Type of Property:
                   <select name="propType" />
                      <option <?php echo $sel_subject['propType'] == 'House' ? 'House"' : ''; ?>>House</option>
                      <option <?php echo $sel_subject['propType'] == 'Bungalow' ? 'selected="selected"' : ''; ?>>Bungalow</option>
                      <option <?php echo $sel_subject['propType'] == 'Flat' ? 'selected="selected"' : ''; ?>>Flat</option>
                      <option <?php echo $sel_subject['propType'] == 'Detached' ? 'selected="selected"' : ''; ?>>Detached</option>
                      <option <?php echo $sel_subject['propType'] == 'Semi_Detached' ? 'selected="selected"' : ''; ?>>Semi_Detached</option>
                      <option <?php echo $sel_subject['propType'] == 'Terraced' ? 'selected="selected"' : ''; ?>>Terraced</option>
                   </select>
                </p>
                <p>Edit content:
                   <textarea name="content" rows="10" cols="70"><?php echo $sel_subject['content']; ?> </textarea>
                   </p>
                <p>Position:
                   <select name="position">
                      <?php
                         $subject_set = get_all_subjects();
                         $subject_count = mysql_num_rows($subject_set);
                         // $subject_count + 1 b/c we are adding a subject
                         for($count=1; $count <= $subject_count+1; $count++) {
                            echo "<option value=\"{$count}\"";
                            if ($sel_subject['position'] == $count) {
                               echo " selected";
                            } 
                            echo ">{$count}</option>";
                         }
                      ?>
                   </select>
                </p>
                <p>Visible:
                   <input type="radio" name="visible" value="0"<?php 
                   if ($sel_subject['visible'] == 0) { echo " checked"; } 
                   ?> /> No
                    
                   <input type="radio" name="visible" value="1"<?php 
                   if ($sel_subject['visible'] == 1) { echo " checked"; } 
                   ?> /> Yes
                </p>
        <p>Type of Sale: 
    	<select name="typeofsale">
    		<option value="buy" <?php echo $sel_subject['buyRentNew'] == 'buy' ? 'selected="selected"' : ''; ?>>Buying</option>
    		<option value="rent" <?php echo $sel_subject['buyRentNew'] == 'rent' ? 'selected="selected"' : ''; ?>>Renting</option>
    		<option value="new" <?php echo $sel_subject['buyRentNew'] == 'new' ? 'selected="selected"' : ''; ?>>New House</option>
    	</select>
    	</p>
    	<p>
    	Image:
    	<input name="image" accept="image/jpeg" type="file">
    	</p>
    
                <input type="submit" name="submit" value="Update Subject" />
                </p>
                
                <h5 id="link"><a href="delete_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" onclick="return confirm('Are you sure?');">Delete Subject</a></h5>
             </form>
             <br />
             <h5 id="link"><a href="edit_page.php?page=<?php echo urlencode($sel_subject['id']); ?>">Edit Page</a></h5>
             <h5 id="link"><a href="content1.php">Cancel</a></h5>
             <h5 id="link"><a href="new_page.php?subj=<?php echo $sel_subject['id']; ?>">+ Add a new page to this subject</a></h5>
    </div>
    
    <?php require("includes/footer.php"); ?>

  15. Yeah sorry I don't need them to upload an image  as it's an edit page although they might want to edit a new image in?

     

    I have the upload image in create_subject.php

     

    <?php require_once("includes/session.php"); ?>
    <?php require_once("includes/connection.php"); ?>
    <?php require_once("includes/functions.php"); ?>
    <?php confirm_logged_in(); ?>
    <?php
        $errors = array();
        
        // Form Validation
        $required_fields = array('menu_name', 'position', 'visible');
        foreach($required_fields as $fieldname) {
            if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) {
                $errors[] = $fieldname;
            }
        }
        
        $fields_with_lengths = array('menu_name' => 30);
        foreach($fields_with_lengths as $fieldname => $maxlength ) {
            if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; }
        }
        
        if (!empty($errors)) {
            redirect_to("new_subject.php");
        }
    ?>
    <?php
        $menu_name = mysql_prep($_POST['menu_name']);
        $position = mysql_prep($_POST['position']);
        $visible = mysql_prep($_POST['visible']);
        $content = mysql_prep($_POST['content']);
        $image = mysql_prep($_POST['image']);
    $banner = mysql_prep($_POST['banner']);
    
        if (is_uploaded_file ($_FILES['image']['tmp_name']))
        {
         echo '<p>The file has been uploaded</p>';
            $temp = 'uploads/'.$_FILES['image']['name'];
            //$temp = 'uploads/fred.jpg';
            echo $temp;
            if (move_uploaded_file ($_FILES['image']['tmp_name'], $temp))
            {
               echo '<p>The file has been moved</p>';
            }
            else
            {
                $errors[] = 'The file could not be moved';
                $temp = $_FILES['image']['tmp_name'];
                echo 'failed';
            }
            $image = $temp;
        }
        else
        {
            $errors[] = 'No file was uploaded';
        }
    
    //banner
    //banner
    if (is_uploaded_file ($_FILES['banner']['tmp_name']))
        {
         echo '<p>The file has been uploaded</p>';
            $test = 'uploads/'.$_FILES['banner']['name'];
            //$temp = 'uploads/fred.jpg';
            echo $temp;
            if (move_uploaded_file ($_FILES['banner']['tmp_name'], $test))
            {
               echo '<p>The file has been moved</p>';
            }
            else
            {
                $errors[] = 'The file could not be moved';
                $test = $_FILES['banner']['tmp_name'];
                echo 'failed';
            }
            $banner = $test;
        }
        else
        {
            $errors[] = 'No file was uploaded';
        }
    //banner
    //banner
    ?>
    <?php
        $query = "INSERT INTO subjects (
                    menu_name, position, visible, content, image, banner
                ) VALUES (
                    '{$menu_name}', {$position}, {$visible}, '{$content}', '{$image}', '{$banner}'
                )";
        $result = mysql_query($query, $connection);
        if($result) {
            // Succes!
            header("Location: content.php");
            //if (is_uploaded_file ($_FILES['image']['tmp_name'])) {
             //echo '<p>The file has been uploaded</p>';
              //}
              //else {
              //echo 'nothing uploaded';
              //}
            exit;
        } else {
            // Display error message.
            echo "<p>Subject creation failed.</p>";
            echo "<p>" . mysql_error() . "</p>";
        }
    ?>

     

    The desired result will just be so when say you edit the menu_name but don't want to touch the picture the picture will still be there.  I guess I eventually will want to be able to upload new images to the edit page.

     

    Thanks for all your help so far.

  16. This is my edit page

     

    <?php require_once("includes/session.php"); ?>
    <?php require_once("includes/connection.php"); ?>
    <?php require_once("includes/functions.php"); ?>
    <?php confirm_logged_in(); ?>
    <?php 
    	if (intval($_GET['subj']) == 0) {
    		redirect_to("content.php");
    	}
    	if (isset($_POST['submit'])) {
    		$errors = array();
    
    		$required_fields = array('menu_name', 'position', 'visible', 'content');
    		foreach($required_fields as $fieldname) {
    			if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) { 
    				$errors[] = $fieldname; 
    			}
    		}
    		$fields_with_lengths = array('menu_name' => 30);
    		foreach($fields_with_lengths as $fieldname => $maxlength ) {
    			if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; }
    		}
    
    		if (empty($errors)) {
    			// Perform Update
    			$id = mysql_prep($_GET['subj']);
    			$menu_name = mysql_prep($_POST['menu_name']);
    			$position = mysql_prep($_POST['position']);
    			$visible = mysql_prep($_POST['visible']);
    			$content = mysql_prep($_POST['content']);
    			$image = mysql_prep($_POST['image']);
    			$banner = mysql_prep($_POST['banner']);
    
    			$query = "UPDATE subjects SET 
    						menu_name = '{$menu_name}', 
    						position = {$position}, 
    						visible = {$visible},
    						content = '{$content}',
    						image = '{$image}',
    						banner = '{$banner}'
    					WHERE id = {$id}";
    			$result = mysql_query($query, $connection);
    			if (mysql_affected_rows() == 1) {
    				// Success
    				$message = "The subject was successfully updated.";
    			} else {
    				// Failed
    				$message = "The subject update failed.";
    				$message .= "<br />". mysql_error();
    			}
    
    		} else {
    			// Errors occurred
    			$message = "There were " . count($errors) . " errors in the form.";
    		}
    
    
    
    
    	} // end: if (isset($_POST['submit']))
    ?>
    <?php find_selected_page(); ?>
    <?php include("includes/header.php"); ?>
    	<div id="nav">
    	<?php echo navigation($sel_subject, $sel_page); ?><a href="content.php""onclick="return confirm('Warning: Anything you have edited will not save if you click ok');">Back to Menu </a>
    	</div>
    		<div id="banner">
    		</div>
    		<div id="line">
    		</div>
    	<div id="content">
    	<h3>Edit Subject: <?php echo $sel_subject['menu_name']; ?></h3>
    	<br />
    	<form action="edit_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" method="post" class="editContent">
    	<br />
    	<?php if (!empty($message)) {
    			echo "<p class=\"message\">" . $message . "</p>";
    		} ?>
    		<?php
    		// output a list of the fields that had errors
    		if (!empty($errors)) {
    			echo "<p class=\"errors\">";
    			echo "Please review the following fields:<br />";
    			foreach($errors as $error) {
    				echo " - " . $error . "<br />";
    			}
    			echo "</p>";
    		}
    
    
    		?>
    		<br />
    			<p>Subject name: 
    				<input type="text" name="menu_name" value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" />
    			</p>
    			<br />
    			<p>Header Image:
    			<input name="banner" accept="image/jpeg" type="file">
    			<br />
    			<br />
    			<p>Position: 
    				<select name="position">
    					<?php
    						$subject_set = get_all_subjects();
    						$subject_count = mysql_num_rows($subject_set);
    						// $subject_count + 1 b/c we are adding a subject
    						for($count=1; $count <= $subject_count+1; $count++) {
    							echo "<option value=\"{$count}\"";
    							if ($sel_subject['position'] == $count) {
    								echo " selected";
    							} 
    							echo ">{$count}</option>";
    						}
    					?>
    				</select>
    			</p>
    			<br />
    			<p>Visible: 
    				<input type="radio" name="visible" value="0"<?php 
    				if ($sel_subject['visible'] == 0) { echo " checked"; } 
    				?> /> No
    				 
    				<input type="radio" name="visible" value="1"<?php 
    				if ($sel_subject['visible'] == 1) { echo " checked"; } 
    				?> /> Yes
    			</p>
    			<br />
    			<p>Content:<br />
    			<textarea name="content" rows="10" cols="75"><?php echo $sel_subject['content']; ?></textarea>
    			</p>
    			<br />
    			<p>Right Sided Image:
    			<input name="image" accept="image/jpeg" type="file">
    			<br />
    			<br />
    			<input type="submit" name="submit" value="Edit Subject" />  
    			<br />
    			<br />
    			<a href="delete_subject.php?subj=<?php echo urlencode($sel_subject['id']);?>"onclick="return confirm('Are you sure?');">Delete Subject</a>
    		<br />
    		<br />
    	<a href="content.php">Cancel</a>
    		</form>
    	</div>
    <?php require("includes/footer.php"); ?>
    

  17. Thanks for that reply, it made sense.

     

    I've just realised another problem, say if I was updating a text field in the same form as the images unless you reselect the same image, it will delete the image because nothing is selected so you have to reapply the image every time you update something.  How can you work around this?

  18. I have a CMS where you can add new pages and edit existing pages, it all works fine apart from the file upload bit to edit.

     

    <p>Position: 
    				<select name="position">
    					<?php
    						$subject_set = get_all_subjects();
    						$subject_count = mysql_num_rows($subject_set);
    						// $subject_count + 1 b/c we are adding a subject
    						for($count=1; $count <= $subject_count+1; $count++) {
    							echo "<option value=\"{$count}\"";
    							if ($sel_subject['position'] == $count) {
    								echo " selected";
    							} 
    							echo ">{$count}</option>";
    						}
    					?>
    				</select>
    			</p>
    			<br />
    			<p>Visible: 
    				<input type="radio" name="visible" value="0"<?php 
    				if ($sel_subject['visible'] == 0) { echo " checked"; } 
    				?> /> No
    				 
    				<input type="radio" name="visible" value="1"<?php 
    				if ($sel_subject['visible'] == 1) { echo " checked"; } 
    				?> /> Yes
    			</p>
    			<br />
    			<p>Content:<br />
    			<textarea name="content" rows="10" cols="75"><?php echo $sel_subject['content']; ?></textarea>
    			</p>
    			<br />
    			<input name="image" accept="image/jpeg" type="file"> <?php echo $sel_subject['image']; ?>
    			<br />
    			<br />
    			<input type="submit" name="submit" value="Edit Subject" />  
    			<a href="delete_subject.php?subj=<?php echo urlencode($sel_subject['id']);?>"onclick="return confirm('Are you sure?');">Delete Subject</a>
    		<br />
    		<br />
    	<a href="content.php">Cancel</a>
    		</form>
    

     

    How can I make it so the picture already selected will be selected in the iinput="image" box?

  19. I need a PHP contact form that will allow users to upload jpg, .pdf, .eps, .psd and .ai files,

     

    Can you do this without a database?

     

    The form will also have fields of,

     

    First name:

     

    Last name:

     

    Company

     

    Email:

     

    Address:

     

    Phone Number:

     

    Comments:

     

    Please send quotes how much you would charge for this,

     

    Kind Regards

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.