well, now, i created a form, and this is it:
<html>
<body bgcolor="lightblue">
<form align="center" action="connect2.php" method="post" style="bgcolor:red">
<div style="margin-left:433px" >
Registration No.: <input type="text" name="reg" /><br />
</div>
</br>
Name: <input type="text" name="name" size="50" style="margin-left:7px" />
<span style="margin-left:6px">
Date of Birth: <input type="text" name="birth" size="30" /></br>
</span>
<div style="margin-left:12px">
Age: <input type="text" name="age" size="15" style="margin-left:7px" />
<span style="margin-left:167px">
Class at August 2012 <input type="text" name="class" size="30" />
</span>
</div>
School: <input type="text" name="school" size="102" style="margin-left:5px" />
</br></br>
Father's Name: <input type="text" name="father" size="94" style="margin-left:5px" /> </br>
Father's Occupation: <input type="text" name="focc" size="89" />
</br></br>
Mother's Name:<input type="text" name="mother" size="94" style="margin-left:3px" /> </br>
Mother's Occupation: <input type="text" name="mocc" size="88" />
</br></br>
<center>
<table bgcolor="pink" width="95" height="100"style="margin-left:0px; margin-top:5px" border="0">
<tr>
<td colspan="3">
Siblings, if any:
</td>
</tr>
<tr align="center"style="font-weight:bold">
<td width="5"></td>
<td width="20">Name</td>
<td width="50">Age</td>
<td width="20">School</td>
</tr>
<tr align="right">
<td>1.</td>
<td align="center"><input type="text" name="ssname" size="44" /></td>
<td align="center"><input type="text" name="sage1" size="5" /></td>
<td align="center"><input type="text" name="sschool1" size="44" /></td>
</tr>
<tr align="right">
<td>2.</td>
<td align="center"><input type="text" name="sname2" size="44" /></td>
<td align="center"><input type="text" name="sage2" size="5" /></td>
<td align="center"><input type="text" name="sschool2" size="44" /></td>
</tr>
<tr align="right">
<td >3.</td>
<td align="center"><input type="text" name="sname3" size="44" /></td>
<td align="center"><input type="text" name="sage3" size="5" /></td>
<td align="center"><input type="text" name="sschool3" size="44" /></td>
</tr>
</table>
</center>
</br>
Address: <input type="text" name="address" size="101" /> </br>
<p align="left" style="margin-left:271px">
Phone Number: <input type="text" name="phone" size="20" /> </br>
Cell Number (Mother/Father): <input type="text" name="cp" size="20" /></br>
Email (Mother/Father): <input type="text" name="email" size="28"/>
</p>
<input type="Submit" name="submit" value="submit" />
</form>
</body>
</html>
and then this is my php code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sy_database", $con);
$sq$sql="INSERT INTO sy_form (reg_no, name, birth, age, sclass, school, fname, focc, mname, mocc, address, phone, cp, email)
VALUES('$_POST[reg]','$_POST[name]','$_POST[birth]','$_POST[age]','$_POST[class]','$_POST[school]','$_POST[fname]','$_POST[focc]','$_POST[mname]','$_POST[mocc]','$_POST[address]','$_POST[phone]','$_POST[cp]','$_POST[email]'),
INSERT INTO siblings(sname,sage,sschool) values('$_POST[ssname]','$_POST[sage1]','$_POST[sschool1]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
</body>
</html>
i need to insert data into two tables from that single form.
the 1st table are for the person who wants to register and the second is for the siblings of that person.
and how come that the AGE won't appear? and the class at january does not appear also.
cellphone number would always be 2147483647?
gawd, I'm so ruined!
could anyone please help me with this? i really want to learn. :(
Ahh, you can't merge queries like that. Try following
$sql1="INSERT INTO sy_form (reg_no, name, birth, age, sclass, school, fname, focc, mname, mocc, address, phone, cp, email)".
"VALUES('$_POST[reg]','$_POST[name]','$_POST[birth]','$_POST[age]','$_POST[class]','$_POST[school]','$_POST[fname]','$_POST[focc]','$_POST[mname]','$_POST[mocc]','$_POST[address]','$_POST[phone]','$_POST[cp]','$_POST[email]')";
$sql2="INSERT INTO siblings(sname,sage,sschool)values('$_POST[ssname]','$_POST[sage1]','$_POST[sschool1]')";
if (!mysql_query($sql1,$con))
{
die('Error: ' . mysql_error());
}
if (!mysql_query($sql2,$con))
{
die('Error: ' . mysql_error());
}
Well that is just starting, to make your program run. There are lot to learn.
Related
I want to insert value in a database and it inserted empty. I want help for this necessary.
This is the variable of time :
$rm_time = $_POST['rm-time'];
PHP
if(empty($_POST['rm-name']) or empty($_POST['rm-details'])){
?>
<h3 style="margin-top: 30px;text-align: center;font-size: 25px;color: red;" dir="rtl">Error</h3>
<?php
}else{
$rm_name = $_POST['rm-name'];
$rm_details = $_POST['rm-details'];
$rm_date = $_POST['rm-date'];
$rm_time = $_POST['rm-time'];
$rm_insert_query = $db->query("INSERT INTO reminders (r_name, r_details, r_date, r_time) VALUES ('$rm_name', '$rm_details', '$rm_date', '$rm_time')");
}
}
?>
<form action="reminder.php?rm=make" method="post">
<table class="rm" width="auto" border="0px">
<tr>
<td class="rm-form-text">Reminder date/time :</td>
<td><input autofocus="" name="rm-date" type="date" id="rm" /> / <input name"rm-time" type="time" id="rm" /></td>
</tr>
<tr>
<td class="rm-form-text">Remimnder name :</td>
<td><input name="rm-name" type="text" id="rm" /></td>
</tr>
<tr>
<td class="rm-form-text">Reminder details :</td>
<td><textarea dir="rtl" name="rm-details" id="rm-ta"></textarea></td>
</tr>
<tr>
<td colspan="2"><input name="save-reminder" type="submit" class="sp-submit" value="Save!" /></td>
</tr>
</table>
</form>
<?
exit;
here your syntax is wrong.
Use
<input name= "rm-time" type="time" id="rm" />
instead of
<input name"rm-time" type="time" id="rm" />
change this
FROM : <input name"rm-time" type="time" id="rm" /></td>
TO : <input name="rm-time" type="time" id="rm" /></td>
hello I want to insert my value to the database here my structure .
<tr>
<td>
<b>Vendredi</b> </br><?php echo $date6 ?>
</td>
<td>
<input size="10" type="text" id="projvendredi" name="projvendredi"onkeypress="return handleEnter6(event, this, 'task');"/>
</td>
<td>
<input type="text" name="clientvendredi" class = "client" size="12" id ="clientvendredi" disabled />
</td>
<td>
<input type="text" name="projdesvendredi" size="30" class "desc" id ="projdesvendredi"disabled />
</td>
<td>
<span id="calculTemps5">
<input id="input6" class= "temps" type="number" name="tempsv" size="2" min="0" max="24" value="0" /></br>
</span>
</td>
</tr>
and here my button
<input type="text" id="result" readonly="readonly" name="total" />
<input type="submit" value="Terminé" id="end" />
<input type="hidden" name="data" value="<?php echo $date; ?>" />
</p>
</form>
Here is my insert.php
$date = $_POST['data'] ;
if (isSet($_POST['descprojsam']))
{
$descprojsam = $_POST['descprojsam'] ;
echo($descprojsam);
}
echo($date);
// Connect to the DB
$link = mysqli_connect("localhost","root","","cruel") or die("Error " . mysqli_error($link));
// adding new recherche
if(!empty($_POST['descprojsam']))
{
$sql = " INSERT INTO `projetstaches`(`prtId`, `prtTimeSheetId`, `prtProjetNum`, `prtDate`, `prtTaskId`, `prtTime`, `prtLocation`, `prtDescription`)
([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],'$descprojsam')";
$link->query($sql);
}
?>
I've not finish my insert cause i don't know how really to do it. I have 7 days so I gave you my friday for exemple.
PHP is case sensative, isSet($_POST['descprojsam']) should be isset($_POST['descprojsam'])
I am new in the field of PHP.
I am working on a form to get information from a patient regarding a specific disease.
In this form i have multiple check-boxes and text fields with each check-box. If one check bos is checked then values of its text fields and checkbox values has to insert in database.
Please tell me the code to insert checked values along with textfields into database.
<form>
<table>
<tr>
<td colspan="4">Past Medical History:</td>
</tr>
<tr valign="top">
<td colspan="4" height="290"><table border="0" width="100%">
<tbody>
<tr>
<td width="26%"><div align="center">Problem</div></td>
<td width="18%"><div align="center">From (Year)</div></td>
<td width="56%"><div align="center">Details</div></td>
</tr>
<tr>
<td><input name="chkBP" id="chkBP" value="BP" type="checkbox" />
Blood Pressure</td>
<td><div align="center">
<input name="txtBPfrom" id="txtBPfrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtBPDetail" id="txtBPDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkDiabetes" id="chkDiabetes" value="Diabetes" type="checkbox" />
Diabetes</td>
<td><div align="center">
<input name="txtDiabetesfrom" id="txtDiabetesfrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtDiabetesDetail" id="txtDiabetesDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkHighCholes" id="chkHighCholes" value="HighCholesterol" type="checkbox" />
High Cholesterol</td>
<td><div align="center">
<input name="txtHighCholesfrom" id="txtHighCholesfrom" size="15" value="" type="text"/>
</div></td>
<td><input name="txtHighCholesDetail" id="txtHighCholesDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkArthritis" id="chkArthritis" value="Arthritis" type="checkbox" />
Arthritis</td>
<td><div align="center">
<input name="txtArthritisfrom" id="txtArthritisfrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtArthritisDetail" id="txtArthritisDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkAsthma" id="chkAsthma" value="Asthma" type="checkbox" />
Asthma</td>
<td><div align="center">
<input name="txtAsthmafrom" id="txtAsthmafrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtAsthmaDetail" id="txtAsthmaDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkCirculation" id="chkCirculation" value="Circulation" type="checkbox" />
Circulation</td>
<td><div align="center">
<input name="txtCirculationfrom" id="txtCirculationfrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtCirculationDetail" id="txtCirculationDetail" size="40" value="" type="text" /></td>
</tr>
</table></td>
</tr>
</form>
You will need to establish a connection to the database.
When the form is posted collect this data and insert into the database accordingly using $_POST.
Helpful example can be found here to connect
And to insert data
$link = mysqli_connect("localhost","root","","web_table");
mysqli_query($link,"INSERT INTO web_formitem (`ID`, `formID`, `caption`, `key`, `sortorder`, `type`, `enabled`, `mandatory`, `data`)
VALUES (105, 7, 'Tip izdelka (6)', 'producttype_6', 42, 5, 1, 0, 0)")
or die(mysqli_error($link));
first add any method attribute to your form tag like, get or post
<form>
to
<form action= "" method="post">
and add a submit button too in your form
now on submit your form will post your form value
and you can catch them by php as to insert in database
<?php
if(isset($_POST['submit_btn_name']))
{
//your database connect
//catch all value, for example
$val=$_POST['check_value'];
//your insert query
}
?>
A checkbox will only post when it's checked.
A textfield will always get posted even when it's empty.
Use a form:
<form name="contactform" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
Add a submit button:
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
PHP:
<?php
//var_dump($_POST);
$chkBP = $_POST['chkBP'];
$txtBPfrom = $_POST['txtBPfrom'];
$txtBPDetail = $_POST['txtBPDetail'];
//echo "-- $txtBPfrom $txtBPDetail --";
if ($chkBP == "BP"){
//echo"Bloodpressure = checked";
$sql="INSERT INTO patient_details (from, detail)
VALUES ('$txtBPfrom', '$txtBPDetail')";
mysql_query($sql);
}else{
echo"Bloodpressure = not checked";
}
?>
Demo: here
I have a form that I have created for internal use. I have been able to populate the MySQL database with the data from the form. I have also created a search function that will pull the data back into the fields based on an ID key (in this case a number). All of the text fields come back into the fields, but the Text Area data does not. I go to the MySQL database, and the table fields for those Text Areas are filled in, but they don't seem to pull back into the form. Please help me if you can. Thank you.
My HTML form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>- - = = EPC Print Order Form = = - - </title>
</head>
<body bgcolor="#DFDFD9">
<h1>Digital Print Form    <input type="image" src="http://commonmedia.asicentral.com/180000/182101/EPC_KAPP.jpg"></h1>
<!-- form to get key detail of record in database -->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Request RFQ</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><form name="form" method="POST" action="form1.php">
RFQ#:</td><td><input type="text" name="search"></td><td><input type="submit" value="submit"></td>
</form></tr></table>
</fieldset>
<!--------------------- Print Form Data ------------------>
<form action="mysqlTest.php" method="post" id="prayfrm" name="prayfrm" onsubmit="return checkform(this);" onreset="return confirm('Do you want to clear this form?')">
<input type="hidden" name="drfq" value="6">
<!--********** Basic Job Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Job Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="drepid">Sales Rep</label></td>
<td><input type="text" name="drepid" size="30" required="true"/>
</td>
<td><label>Today's Date</label></td>
<td><input type="text" name="datepicker" size="10"/></td>
</tr>
<tr>
<td><label for="repemail">Rep Email</label></td>
<td><input id="repemail" name="repemail" type="text" size="30" required="true" /></td>
<td><label>Date Needed</label></td>
<td><input id="dateneeded" name="dateneeded" type="text" size="10" required="true" /> </td>
</tr>
<tr>
<td><label for="description">Description</label></td>
<td><input id="description" name="description" type="text" size="30" required="true" /></td>
<td><label for="qty">Quantity</label></td>
<td><input id="qty" name="qty" type="text" size="10" required="true" /></td>
</tr>
<tr>
<td><label for="pgsizeh">Page Size (h) x (w)</label></td>
<td><input id="pgsizeh" name="pgsizeh" type="text" size="10" required="true" /> x <input id="pgsizew" name="pgsizew" type="text" size="13" required="true" /></td>
<td><label for="pageno">Page Number</label></td>
<td><input id="pageno" name="pageno" type="text" size="10" required="true" /></td>
</tr>
<tr>
<td><label for="stock">Stock</label></td>
<td><input id="stock" name="stock" type="text" size="10" required="true" />  <label for="stock">Color   </label>
<input type="text" name="ink" size="6" required="true"/>
</td>
<td><label for="inknote">   Explain </label></td>
<td><input id="inknote" name="inknote" type="text" size="10" /></td>
</tr>
<tr>
<td><label for="rfq">Referenced RFQ:</label></td>
<td><input id="rfq" name="rfq" type="text" size="10" required="true" /><td><label for="finishing">Finishing</label></td>
<td><input id="finishing" name="finishing" type="text" size="10" required="true" />
</tr>
</table></fieldset>
<!--********** Customer Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Customer Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="dfirstname">First Name</label></td><td><input id="dfirstname" name="dfirstname" type="text" size="31" required="true" /></td><td><label for="dlastname">  Last </label></td><td><input id="dlastname" name="dlastname" type="text" size="31" required="true" /></td>
</tr>
<tr>
<td><label for="dorganization">Organization</label></td>
<td><input id="dorganization" name="dorganization" type="text" size="31" required="true" /></td><td><label for="email">Email</label></td>
<td><input id="email" name="email" type="text" size="31" required="true" /></td>
</tr>
<tr>
<td><label for="daddress1">Address</label></td><td><input id="daddress1" name="daddress1" type="text" size="31" required="true" /><td></td><td><input id="daddress2" name="daddress2" type="text" size="31" />
</tr>
<tr>
<td><label for="dcity">City</label></td><td><input id="dcity" name="dcity" type="text" size="25" required="true" /> <label for="dstate"> State</label></td><td><input id="dstate" name="dstate" type="text" size="3" required="true" /> <td><label for="dzip"> Zip </label> <input id="dzip" name="dzip" type="text" size="27" required="true" /></tr>
<tr>
<td><label for="phone">Phone </label><td><input id="phone" name="phone" type="text" size="31" required="true" /></td><td><label for="fax">Fax </label><td><input id="fax" name="fax" type="text" size="31" required="true" /> </td>
</tr></table></fieldset>
<!--********** Delivery Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Delivery Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="proof">Proof?</label>  <input type="checkbox" name="proof" value="yes" required="true" />  </td><td><label for="whoproof">Proof to Whom?</label> <input id="whoproof" name="whoproof" type="text" size="44" required="true" /></td>
</tr>
<tr>
<td><label for="quote">Quote?</label> <input type="checkbox" name="quote" value="yes" required="true" />  </td>
<td><label for="amount">Amount: $</label> <input id="amount" name="amount" type="text" size="50" required="true" /></td>
</tr>
<tr>
<td><label for="delivery">Delivery Instructions</label></td><td><textarea name="delivery" rows="4" cols="50"></textarea></tr>
<tr>
<td><label for="notes">Additional Notes</label></td><td><textarea name="notes" rows="4" cols="50"></textarea>
</tr>
<td align="right"><input name="submit" type="submit" id="submit" value="Submit" /></td>
<td align="left"><input name="Reset" type="reset" id="reset" value="Reset Form" /></table></fieldset>
</body>
</html>
My PHP File for adding fields to database
<?php
$dbhost = 'hostname';
$dbuser = 'username';
$dbpass = '*******';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'dbasename';
mysql_select_db($dbname);
// -------------------------------------------------------------------
// Field Names
// -------------------------------------------------------------------
$drepid=mysql_real_escape_string($_POST['drepid']);
$datepicker=mysql_real_escape_string($_POST['datepicker']);
$repemail=mysql_real_escape_string($_POST['repemail']);
$dateneeded=mysql_real_escape_string($_POST['dateneeded']);
$description=mysql_real_escape_string($_POST['description']);
$qty=mysql_real_escape_string($_POST['qty']);
$pgsizeh=mysql_real_escape_string($_POST['pgsizeh']);
$pgsizew=mysql_real_escape_string($_POST['pgsizew']);
$pageno=mysql_real_escape_string($_POST['pageno']);
$stock=mysql_real_escape_string($_POST['stock']);
$ink=mysql_real_escape_string($_POST['ink']);
$inknote=mysql_real_escape_string($_POST['inknote']);
$rfq=mysql_real_escape_string($_POST['rfq']);
$finishing=mysql_real_escape_string($_POST['finishing']);
$dfirstname=mysql_real_escape_string($_POST['dfirstname']);
$dlastname=mysql_real_escape_string($_POST['dlastname']);
$dorganization=mysql_real_escape_string($_POST['dorganization']);
$email=mysql_real_escape_string($_POST['email']);
$daddress1=mysql_real_escape_string($_POST['daddress1']);
$daddress2=mysql_real_escape_string($_POST['daddress2']);
$dcity=mysql_real_escape_string($_POST['dcity']);
$dstate=mysql_real_escape_string($_POST['dstate']);
$dzip=mysql_real_escape_string($_POST['dzip']);
$phone=mysql_real_escape_string($_POST['phone']);
$fax=mysql_real_escape_string($_POST['fax']);
$proof=mysql_real_escape_string($_POST['proof']);
$whoproof=mysql_real_escape_string($_POST['whoproof']);
$quote=mysql_real_escape_string($_POST['quote']);
$amount=mysql_real_escape_string($_POST['amount']);
$delivery=mysql_real_escape_string($_POST['delivery']);
$notes=mysql_real_escape_string($_POST['notes']);
$sql = "INSERT INTO epc_print (drepid, datepicker, repemail, dateneeded, description, qty, pgsizeh, pgsizew, pageno, stock, ink, inknote, rfq, finishing, dfirstname, dlastname, dorganization, email, daddress1, daddress2, dcity, dstate, dzip, phone, fax, proof, whoproof, quote, amount, delivery, notes) values ('$drepid', '$datepicker', '$repemail', '$dateneeded', '$description', '$qty', '$pgsizeh', '$pgsizew', '$pageno', '$stock', '$ink', '$inknote', 'rfq', '$finishing', '$dfirstname', '$dlastname', '$dorganization', '$email', '$daddress1', '$daddress2', '$dcity', '$dstate', '$dzip', '$phone', '$fax', '$proof', '$whoproof', '$quote', '$amount', '$delivery', '$notes')";
mysql_query($sql) or die(mysql_error());
echo "
<code><pre></code>";
echo "POST:";
print_r($_POST);
echo "<code></pre></code>
";
echo "1 record added";
?>
Then my php file to retrieve data:
<?php
$connection = mysql_connect('hostname','username','*****') or die ("Couldn't connect to server.");
$db = mysql_select_db('databasename', $connection) or die ("Couldn't select database.");
$search=$_POST['search'];
$data = 'SELECT * FROM `epc_print` WHERE `drfq` = "'.$search.'"';
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$data2 = mysql_fetch_array($query);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>- - = = EPC Print Form = = - - </title>
</head>
<body bgcolor="#DFDFD9">
<h1>Digital Print Form    <input type="image" src="http://commonmedia.asicentral.com/180000/182101/EPC_KAPP.jpg"></h1>
<!-- form to get key detail of record in database -->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Request RFQ</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><form name="form" method="POST" action="form1.php">
RFQ#:</td><td><input type="text" name="search"></td><td><input type="submit" value="submit"></td>
</form></tr></table>
</fieldset>
<!--------------------- Print Form Data ------------------>
<form action="form2.php" method="post" id="prayfrm" name="prayfrm" onsubmit="return checkform(this);" onreset="return confirm('Do you want to clear this form?')">
<input type="hidden" name="drfq" value="6">
<!--********** Basic Job Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Job Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="drepid">Sales Rep</label></td>
<td><input id="drepid" name="drepid" type="text" size="30" value="<?php echo htmlspecialchars ($data2[drepid])?>" required="true" /></td>
</td>
<td><label>Today's Date</label></td>
<td><input id="datepicker" name="datepicker" type="text" size="10" value="<?php echo htmlspecialchars ($data2[datepicker])?>" required="true" /></td>
</tr>
<tr>
<td><label for="repemail">Rep Email</label></td>
<td><input id="repemail" name="repemail" type="text" size="30" value="<?php echo htmlspecialchars ($data2[repemail])?>" required="true" /></td>
<td><label>Date Needed</label></td>
<td><input id="dateneeded" name="dateneeded" type="text" size="10" value="<?php echo htmlspecialchars ($data2[dateneeded])?>" required="true" /></td></td>
</tr>
<tr>
<td><label for="description">Description</label></td>
<td><input id="description" name="description" type="text" size="30" value="<?php echo htmlspecialchars ($data2[description])?>" required="true" /></td>
<td><label for="qty">Quantity</label></td>
<td><input id="qty" name="qty" type="text" size="10" value="<?php echo htmlspecialchars ($data2[qty])?>"required="true" /></td>
</tr>
<tr>
<td><label for="pgsizeh">Page Size (h) x (w)</label></td>
<td><input id="pgsizeh" name="pgsizeh" type="text" size="10" value="<?php echo htmlspecialchars ($data2[pgsizeh])?>" required="true" /> x <input id="pgsizew" name="pgsizew" type="text" size="14" value="<?php echo htmlspecialchars ($data2[pgsizew])?>" required="true" /></td>
<td><label for="pageno">Page Number</label></td>
<td><input id="pageno" name="pageno" type="text" size="10" value="<?php echo htmlspecialchars ($data2[pageno])?>" required="true" /></td>
</tr>
<tr>
<td><label for="stock">Stock</label></td>
<td><input id="stock" name="stock" type="text" size="10" value="<?php echo htmlspecialchars ($data2[stock])?>" required="true" /> <label for="ink">Color </label> <input id="ink" name="ink" type="text" size="10" value="<?php echo htmlspecialchars ($data2[ink])?>" required="true" /></td>
<td><label for="inknote">   Explain </label></td>
<td><input id="inknote" name="inknote" type="text" size="10" value="<?php echo htmlspecialchars ($data2[inknote])?>"/></td>
</tr>
<tr>
<td><label for="rfq">Referenced RFQ:</label></td>
<td><input id="rfq" name="rfq" type="text" size="10" value="<?php echo htmlspecialchars ($data2[rfq])?>" required="true"/></td> <td><label for="finishing">Finishing</label></td>
<td><input id="finishing" name="finishing" type="text" size="10" value= "<?php echo htmlspecialchars ($data2[finishing])?>" required="true" />
</tr>
</table></fieldset>
<!--********** Customer Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Customer Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="dfirstname">First Name</label></td><td><input id="dfirstname" name="dfirstname" type="text" size="31" value="<?php echo htmlspecialchars ($data2[dfirstname])?>" required="true" /></td><td><label for="dlastname">  Last </label></td><td><input id="dlastname" name="dlastname" type="text" size="31" value= "<?php echo htmlspecialchars ($data2[dlastname])?>"required="true" /></td>
</tr>
<tr>
<td><label for="dorganization">Organization</label></td>
<td><input id="dorganization" name="dorganization" type="text" size="31" value="<?php echo htmlspecialchars ($data2[dorganization])?>" required="true" /></td><td><label for="email">Email</label></td>
<td><input id="email" name="email" type="text" size="31" value="<?php echo htmlspecialchars ($data2[email])?>" required="true" /></td>
</tr>
<tr>
<td><label for="daddress1">Address</label></td><td><input id="daddress1" name="daddress1" type="text" size="31" value="<?php echo htmlspecialchars ($data2[daddress1])?>" required="true" /><td></td><td><input id="daddress2" name="daddress2" type="text" size="31" value="<?php echo htmlspecialchars ($data2[daddress2])?>"/>
</tr>
<tr>
<td><label for="dcity">City</label></td><td><input id="dcity" name="dcity" type="text" size="25" value="<?php echo htmlspecialchars ($data2[dcity])?>" required="true" /> <label for="dstate"> State</label></td><td><input id="dstate" name="dstate" type="text" size="3" value="<?php echo htmlspecialchars ($data2[dstate])?>" required="true" /> <td><label for="dzip"> Zip </label> <input id="dzip" name="dzip" type="text" size="27" value="<?php echo htmlspecialchars ($data2[dzip])?>" required="true" /></tr>
<tr>
<td><label for="phone">Phone </label><td><input id="phone" name="phone" type="text" size="31" value="<?php echo htmlspecialchars ($data2[phone])?>" required="true" /></td><td><label for="fax">Fax </label><td><input id="fax" name="fax" type="text" size="31" value="<?php echo htmlspecialchars ($data2[fax])?>"/> </td>
</tr></table></fieldset>
<!--********** Delivery Information for the form******************-->
<fieldset style='width:570px; text-align:left; border-width:2px;'>
<legend><h3>Delivery Information</h3></legend>
<table bgcolor="beige" border="0" width="570px">
<tr>
<td><label for="proof">Proof?</label>  <input type="checkbox" name="proof" value="<?php echo ($data2[proof])?>" />  </td><td><label for="whoproof">Proof to Whom?</label> <input id="whoproof" name="whoproof" type="text" size="44" value="<?php echo htmlspecialchars ($data2[whoproof])?>"required="true" /></td>
</tr>
<tr>
<td><label for="quote">Quote?</label> <input type="checkbox" name="quote" value="<?php echo htmlspecialchars ($data2[quote])?>" required="true" />  </td>
<td><label for="amount">Amount: $</label> <input id="amount" name="amount" type="text" size="50" value="<?php echo htmlspecialchars ($data2[amount])?>" required="true" /></td>
</tr>
<tr>
<td><label for="delivery">Delivery Instructions</label></td><td><textarea name="delivery" rows="4" cols="50" value="<?php echo htmlspecialchars ($data2[delivery])?>" /></textarea></tr>
<tr>
<td><label for="notes">Additional Notes</label></td><td><textarea name="notes" rows="4" cols="50" value="<?php echo htmlspecialchars ($data2[notes])?>"/></textarea>
</tr>
<td align="right"><input name="submit" type="submit" id="submit" value="Submit" /></td>
<td align="left"><input name="Reset" type="reset" id="reset" value="Reset Form" /></table></fieldset>
</body>
</html>
The default value of a text area is provided by the text node inside the element, not a value attribute.
<textarea>Default value
Which can have new lines</textarea>
value isn't a valid attribute for textareas, you need to use <textarea>value</textarea>
I have gone through a bunch of question posts, and found one person with the same issue as me, but the answer he/she received I did not find to help at all.
I created a form which uses checkboxes. Once submitted my entire form is processed beautifully and I do receive the mail, but when it comes to the checkboxes it only displays "Array" in the email in stead of the checked checkbox values....
What am I doing wrong?
HTML Form Code: as requested, the full form
<form name="busquoteform" method="post" action="FormToEmail.php">
<fieldset>
<legend>Contact Information</legend>
<table width="100%">
<tr>
<td width="40%">
<label><strong>Name *:</strong></label><br/>
<input name="name" type="text" id="name" value="" />
</td>
<td width="10%"> </td>
<td width="40%">
<label><strong>Lastname *:</strong></label><br />
<input name="lname" type="text" id="lname" value="" />
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="25%">
<label><strong>Contact Number:</strong></label><br/>
<input name="contactno" type="text" id="contactno" value="" />
</td>
<td width="25%">
<label><strong>Mobile Number * </strong></label><br/>
<input name="mobno" type="text" id="mobno" value="" />
</td>
<td width="40%">
<label><strong>Email *:</strong></label><br/>
<input name="email" type="text" id="email" value="" />
</td>
</tr>
</table>
</fieldset>
<br/>
<fieldset>
<legend>Company Information</legend>
<table width="100%">
<tr>
<td width="40%">
<label><strong>Company Name *:</strong></label><br/>
<input name="compname" type="text" id="compname" value="" />
</td>
<td width="10%">
<label><strong>Position Held *:</strong></label><br />
<input name="position" type="text" id="position" value="" />
</td>
<td width="40%">
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="16%">
<label><strong>Company Address*:</strong></label><br/><br/><br/><br/>
</td>
<td width="2%">
</td>
<td>
<input name="street" type="text" id="street" value="Street" size="30" /><br/>
<input name="suburb" type="text" id="suburb" value="Suburb" size="30" /><br/>
<input name="city" type="text" id="city" value="City" size="30" /><br/>
<input name="code" type="text" id="code" value="Postal Code" size="10" /><br/>
</td>
</tr>
</table>
</fieldset>
<br/>
<fieldset>
<legend>Project Information</legend>
<table>
<tr>
<td>
<label><strong>Service Type/s*:</strong></label><br/>
Please select all applicable types.
</td>
</tr>
<tr>
<td>
Graphic Design <input name="serviceType[]" id="design" type="checkbox" value="Graphic Design" />
Web Development <input name="serviceType[]" id="webdev" type="checkbox" value="Web Development" />
Application Development <input name="serviceType[]" id="appdev" type="checkbox" value="App Development" />
Embroidery <input name="serviceType[]" id="embroidery" type="checkbox" value="Embroidery" />
Engraving <input name="serviceType[]" id="engrave" type="checkbox" value="Engraving" /><br/><br/>
</td>
</tr>
<tr>
<td>
<label><strong>Please supply a detailed description of your requirements*:</strong></label><br/>
<textarea name="projectDes" cols="60" rows="10" id="projectDes"></textarea>
<br/><br/>
<input name="quoteBus" type="submit" class="ZD-button" value="Send Request"/>
</td>
</tr>
</table>
</fieldset>
</form>
and the php processing code:
$mailBody = "Name : ".$_REQUEST['name']. " ".$_REQUEST['lname'].
" <br/>Email : ".$_REQUEST['email'].
" <br/>Contact No : ".$_REQUEST['contactno']. " Mobile No: ".$_REQUEST['mobno'].
"<br/><br/>Company Name : ".$_REQUEST['compname'].
" <br/>Postion Held : ".$_REQUEST['position'].
"<br/><br/>Company Address : <br/>".$_REQUEST['street']."<br/>".$_REQUEST['suburb']."<br/>".$_REQUEST['city']."<br/>".$_REQUEST['code'].
"<br/><br/> Service Type/s :" .(is_array($_REQUEST['serviceType'])?implode("\n", $_REQUEST['serviceType']):$_REQUEST['serviceType'])."<br />".
"<br/><br/>Details of Project : ".$_REQUEST['projectDes'];
I've also tried:
" Service Type/s :" .$serviceType = $_POST["serviceType"];$serviceType = implode(', ', $serviceType);"".
and also does not seem to work...
I got this code from a project my hubby did a while back - but he is not a php developer, he's into Java...
Help Please?
Update
I just tried your code and it works fine, and results what you want. So can you please show your <form> tag.
Code that I tested
<?php
echo (is_array($_REQUEST['serviceType']) ? implode("\n", $_REQUEST['serviceType']) : $_REQUEST['serviceType']);
?>
<form action="" method="post">
Graphic Design <input name="serviceType[]" id="design" type="checkbox" value="Graphic Design" />
Web Development <input name="serviceType[]" id="webdev" type="checkbox" value="Web Development" />
Application Development <input name="serviceType[]" id="appdev" type="checkbox" value="App Development" />
Embroidery <input name="serviceType[]" id="embroidery" type="checkbox" value="Embroidery" />
Engraving <input name="serviceType[]" id="engrave" type="checkbox" value="Engraving" /><br/><br/>
<input type="submit" />
</form>
Hm, that's strange.. It should show all the serviceType values seperated by \n, due to this line:
(is_array($_REQUEST['serviceType'])?implode("\n", $_REQUEST['serviceType']):$_REQUEST['serviceType'])
What if you change $_REQUEST to $_POST?
You can use foreach this way:
$serviceTypes = "";
if (is_array($_REQUEST['serviceType']))
{
foreach ($_REQUEST['serviceType'] as $serviceType)
{
$serviceTypes.= "$serviceType\n";
}
}
It's a possibility.