php Send Form

I made this form, and when this form been submit I will receive every text fields and labels.

Is any way to receive only the label and comment that have in a number in the qty?

example;
if user entered 8 in Item 1’s qty and 4 in Item 3’s qty

8 Item 1, Comment: Send them in a new box
4 Item 3, Comment: Each two in a box

here is the code

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Send Form</title>
</head>

<form action="" method="post">
<table border="0" cellpadding="5" cellspacing="5">
  <tr>
    <td>Quantity‎</td>
    <td>Item</td>
    <td>Comment</td>
  </tr>
  <tr>
    <td><input name="qty1" type="text" size="3" maxlength="3"></td>
    <td><label>Item 1</label></td>
    <td><input name="comt1" type="text" size="45"></td>
  </tr>
  <tr>
    <td><input name="qty2" type="text" size="3" maxlength="3"></td>
    <td><label>Item 2</label></td>
    <td><input name="comt2" type="text" size="45"></td>
  </tr>
  <tr>
    <td><input name="qty3" type="text" size="3" maxlength="3"></td>
    <td><label>Item 3</label></td>
    <td><input name="comt4" type="text" size="45"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input name="Send" type="submit" value="Submit"></td>
    <td>&nbsp;</td>
  </tr>
</table>


</form>

</body>
</html>

Where is the php code for the form? The action field is blank so the form posts on itself. Or did you want it to go to another page?

:stuck_out_tongue: sorry it sample idea from my form

Here is the form with action

[php]

Send Form
Quantity‎ Item Comment
   
[/php]

Here is the action code

[php]<?php
session_start();
$line1 = $_POST[‘qty1’]. " ". $_POST[‘Item 1’]. " Comments: ". $_POST[‘comt1’] ;
$line2 = $_POST[‘qty2’]. " ". $_POST[‘Item 2’]. " Comments: ". $_POST[‘comt2’] ;
$line1 = $_POST[‘qty3’]. " ". $_POST[‘Item 3’]. " Comments: ". $_POST[‘comt3’] ;

$formcontent= “$line1 \n$line2 \n$line3”;
$email= "[email protected]";
$subject = “New order”;
$mailheader = “From: $email \r\n”;

mail($email, $subject, $formcontent, $mailheader) or die(“Error!”);
?>

Form Sent

Your order was sent.

[/php]

What happens when you run it? I am seeing some errors on the code and I would recommend learning CSS3 to get away from using tables for layout. But, what are you getting when it runs?

There are far better ways to do this which is why I am posting this. It is not normal to do it this way, because most businesses have multiple products normally pulled from a database but,

[php] <?php
session_start();

$items = array(‘Item 1’, ‘Item 2’, ‘Item 3’);

if($_POST[‘qty1’] > 0) {

$line1 = $_POST[‘qty1’]. " ". $items[0] . " Comments: ". $_POST[‘comt1’] ;
$formcontent = “$line1\n”;

}

if($_POST[‘qty2’] > 0) {

$line2 = $_POST[‘qty2’]. " ". $items[1] . " Comments: ". $_POST[‘comt2’] ;
$formcontent .= “$line2\n”;

}

if($_POST[‘qty3’] > 0) {

$line3 = $_POST[‘qty3’]. " ". $items[2] . " Comments: ". $_POST[‘comt3’] ;
$formcontent .= “$line3\n”;
}

$email= "[email protected]";
$subject = “New order”;
$mailheader = “From: $email \r\n”; //This should not be the same email you are sending it to

try {

mail($email, $subject, $formcontent, $mailheader);
//correct sytax for example
// mail($to, $subject, $message, $headers if any)

var_dump($formcontent); //Used for debugging;

$output = “Your order was sent.”; //ensures message it not displayed unless if error is sent

} catch (exception $e) {
$output = $e.message;// Display error
}

?>

Form Sent

<?php echo $output; //Shows success or error ?>

[/php]

:smiley:

Thanks for you, that what I am looking for

Check this picture
http://s11.postimg.org/5ukf21bcj/form2.png

Okay astonecipher, I have question:

I crated php site with sql database using Adobe Dreamwaver CSS 5

I have two tables are attached to my form, the first one is ITEMS, the second one ORDERS

Do u have idea how i will make it works? I did repeat region to display items in the form, but I could not make to read from the form using the same idea of repeat region.

I want make those fields placed on hidden filed orders using
[php][/php]

[php]

<?php require_once('Connections/connection.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO items (id, `order`) VALUES (%s, %s)", GetSQLValueString($_POST['id'], "int"), GetSQLValueString($_POST['order'], "text")); mysql_select_db($database_connection, $connection); $Result1 = mysql_query($insertSQL, $connection) or die(mysql_error()); $insertGoTo = "orderCompleted.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_connection, $connection); $query_orders = "SELECT * FROM items"; $orders = mysql_query($query_orders, $connection) or die(mysql_error()); $row_orders = mysql_fetch_assoc($orders); $totalRows_orders = mysql_num_rows($orders); mysql_select_db($database_connection, $connection); $query_types = "SELECT itemstypes FROM itemstypes"; $types = mysql_query($query_types, $connection) or die(mysql_error()); $row_types = mysql_fetch_assoc($types); $totalRows_types = mysql_num_rows($types); ?> Jason's Online Market <?php do { ?> <?php } while ($row_types = mysql_fetch_assoc($types)); ?>
Quantity‎ Item Comment
<?php echo $row_types['itemstypes']; ?>
   

 

<?php mysql_free_result($orders); mysql_free_result($types); ?>

[/php]

The first thing that jumps out is this,

[php] $query_types = "SELECT itemstypes FROM itemstypes";[/php]

Your field and table are named the same?

The next thing is you are using deprecated functions, where did you find this code? It looks very familiar so I am guessing you figured it would work and changed what you thought you needed to.

I think you need to understand what you are doing first, . look through this link

Sponsor our Newsletter | Privacy Policy | Terms of Service