I want to received 4,5 row data in php. When I put values in the form like 3 or 4 row than I want to received the same data in php :(
I am trying to make a pos. When the customer order multiple product than the order row automatically increase but there is no limit 5, 10, 15 or else.
And I want to received the data value in same rows like
<form name="data" method="post" action="data_rec.php" enctype="multipart/form-data">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
</table>
<input name="Submit" type="submit" value="SEND">
</form>
<?php
foreach (array_combine($_POST['data'], $_POST['data']) as $i => $data) {
$i."<br />";
echo $data."<br />";
echo "SAGOR"."<br />";
}
?>
Output :
1
SAGOR
2
SAGOR
3
SAGOR
4
SAGOR
5
SAGOR
6
SAGOR
7
SAGOR
8
SAGOR
SAGOR
But I need :
1 2 3 4
SAGOR
5 6 7 8
You can add rows to your form on the browser with JS or JQuery.
You must give each row's elements unique ids/names like: <input name="data2" type="text" id="data2" /> <input name="data3" type="text" id="data3" />...
You will receive them all in you $_POST when the user submit the form
Related
I want to submit a form which posts the input text field when the current line checkbox is checked.
When I submit, I get the productID of the checked box but all of the productLink. I want to only get the input text of the corresponding checked box.
How do I go about this?
<form action="process.php" method="post">
<table>
<tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr><tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr><tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr><tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr><tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr>
</table>
<input type="submit" name="formSubmit" value="Submit" />
</form>
You can find a lot of solution, so in my opinion you should look this one
HTML Element Array, name="something[]" or name="something"?
You can't this way, but there are some alternative method for example, when user check to checkbox then you could call a javascript function create an array and send json stringify data your php.
another way like below;
in your html
<form method="post">
<table>
<tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[<?= $products->id; ?>"]"></td>
</tr>
<tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[<?= $products->id; ?>"]"></td>
</tr>
<tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[<?= $products->id; ?>"]"></td>
</tr>
<tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[<?= $products->id; ?>"]"></td>
</tr>
<tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[<?= $products->id; ?>"]"></td>
</tr>
</table>
<input type="submit" name="formSubmit" value="Submit" />
</form>
in your php (suppose in codeigniter because you tagged it)
function some_func_name(){
$product_ids = $this->input->post('productId');
$posted_product_links = $this->input->post('productLink');
$selected_links = [];
for($product_ids as $id){
$p_link = $posted_product_links[$id];
array_push($selected_links, array('id' => $id, 'link' => $p_link));
}
}
I hope this may help you..
update your by following codes
HTML
<form action="process.php" method="post">
<table>
<tr>
<td>
<input type="checkbox" name="productId[1]" value="<?=$products->id;?>" <?= set_checkbox('productId[1]', $products->id);?> />
<input type="text" name="productLink[1]" value="<?= set_value('productLink[1]');?>"/>
</td>
</tr><tr>
<td>
<input type="checkbox" name="productId[2]" value="<?=$products->id;?>" <?= set_checkbox('productId[2]', $products->id);?> />
<input type="text" name="productLink[2]" value="<?= set_value('productLink[2]');?>" />
</td>
</tr><tr>
<td>
<input type="checkbox" name="productId[3]" value="<?=$products->id;?>" <?= set_checkbox('productId[3]', $products->id);?>/>
<input type="text" name="productLink[3]" value="<?= set_value('productLink[3]');?>" />
</td>
</tr><tr>
<td>
<input type="checkbox" name="productId[4]" value="<?=$products->id;?>" <?= set_checkbox('productId[4]', $products->id);?> />
<input type="text" name="productLink[4]" value="<?= set_value('productLink[4]');?>" />
</td>
</tr><tr>
<td>
<input type="checkbox" name="productId[5]" value="<?=$products->id;?>" <?= set_checkbox('productId[5]', $products->id);?> />
<input type="text" name="productLink[5]" value="<?= set_value('productLink[5]');?>" />
</td>
</tr>
</table>
<input type="submit" name="formSubmit" value="Submit" />
</form>
Controller
public function some_func_name(){
if($this->input->post()){
$checkbox = $this->input->post('productId');
$textbox = $this->input->post('productLink');
$selected = #array_intersect_key($textbox, $checkbox);
echo '<pre>';
print_r($selected);
}
}
codes here : https://pastebin.com/UC1UFPRF
I ended up using jquery to remove the obj when they were empty.
$(document).ready(function(){
$("form").submit(function(){
$("input").each(function(index, obj){
if($(obj).val() == "") {
$(obj).remove();
}
});
});
});
I have a table with these columns (database)
like this http://netelity.com/table.JPG.
and i have a static form through which user define the installments. Static 24 input boxes are there like this
<form name="installment" method="post" action="" enctype="multipart/form-data" onsubmit="return validate()">
<table id="dt_hScroll" class="table table-striped">
<thead>
<tr>
<th>SL No.</th>
<th>Amount</th>
<th>Due Date</th>
</tr>
<tr>
<td> 1. </td>
<td>
<input type="text" name="installment1" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date1" class="tcal span4" value="<?php //echo date("Y-m-d"); ?>" />
</td>
</tr>
<tr>
<td> 2. </td>
<td>
<input type="text" name="installment2" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date2" class="tcal span4" />
</td>
</tr>
<tr>
<td> 3. </td>
<td>
<input type="text" name="installment3" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date3" class="tcal span4" />
</td>
</tr>
<tr>
<td> 4. </td>
<td>
<input type="text" name="installment4" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date4" class="tcal span4" />
</td>
</tr>
<tr>
<td> 5. </td>
<td>
<input type="text" name="installment5" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date5" class="tcal span4" />
</td>
</tr>
<tr>
<td> 6. </td>
<td>
<input type="text" name="installment6" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date6" class="tcal span4" />
</td>
</tr>
<tr>
<td> 7. </td>
<td>
<input type="text" name="installment7" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date7" class="tcal span4" />
</td>
</tr>
<tr>
<td> 8. </td>
<td>
<input type="text" name="installment8" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date8" class="tcal span4" />
</td>
</tr>
<tr>
<td> 9. </td>
<td>
<input type="text" name="installment9" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date9" class="tcal span4" />
</td>
</tr>
<tr>
<td> 10. </td>
<td>
<input type="text" name="installment10" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date10" class="tcal span4" />
</td>
</tr>
<tr>
<td> 11. </td>
<td>
<input type="text" name="installment11" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date11" class="tcal span4" />
</td>
</tr>
<tr>
<td> 12. </td>
<td>
<input type="text" name="installment12" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date12" class="tcal span4" />
</td>
</tr>
<tr>
<td> 13. </td>
<td>
<input type="text" name="installment13" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date13" class="tcal span4" />
</td>
</tr>
<tr>
<td> 14. </td>
<td>
<input type="text" name="installment14" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date14" class="tcal span4" />
</td>
</tr>
<tr>
<td> 15. </td>
<td>
<input type="text" name="installment15" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date15" class="tcal span4" />
</td>
</tr>
<tr>
<td> 16. </td>
<td>
<input type="text" name="installment16" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date16" class="tcal span4" />
</td>
</tr>
<tr>
<td> 17. </td>
<td>
<input type="text" name="installment17" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date10" class="tcal span4" />
</td>
</tr>
<tr>
<td> 18. </td>
<td>
<input type="text" name="installment18" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date18" class="tcal span4" />
</td>
</tr>
<tr>
<td> 19. </td>
<td>
<input type="text" name="installment19" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date19" class="tcal span4" />
</td>
</tr>
<tr>
<td> 20. </td>
<td>
<input type="text" name="installment20" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date20" class="tcal span4" />
</td>
</tr>
<tr>
<td> 21. </td>
<td>
<input type="text" name="installment21" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date21" class="tcal span4" />
</td>
</tr>
<tr>
<td> 22. </td>
<td>
<input type="text" name="installment22" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date22" class="tcal span4" />
</td>
</tr>
<tr>
<td> 23. </td>
<td>
<input type="text" name="installment23" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date23" class="tcal span4" />
</td>
</tr>
<tr>
<td> 24. </td>
<td>
<input type="text" name="installment24" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date24" class="tcal span4" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="save" id="save" value="Save" class="btn btn-info span3" />
<input type="hidden" readonly="readonly" name="roll_no" value="<?php echo $roll_no; ?>" class="span5" />
</td>
<td></td>
</tr>
</thead>
</table>
</form>
Here i am not getting how to store it in that table. Actually all the 24 inputs are not mandatory. If user fills only 2 then also it should store it in the database table.
I tried to do like this
if(isset($_POST['save']))
{
$roll_no = $_POST['roll_no'];
$ins_amt1 = $_POST['installment1'];
$due_date1 = $_POST['due_date1'];
$ins_amt2 = $_POST['installment2'];
$due_date2 = $_POST['due_date2'];
$ins_amt3 = $_POST['installment3'];
$due_date3 = $_POST['due_date3'];
$ins_amt4 = $_POST['installment4'];
$due_date4 = $_POST['due_date4'];
$ins_amt5 = $_POST['installment5'];
$due_date5 = $_POST['due_date5'];
$ins_amt6 = $_POST['installment6'];
$due_date6 = $_POST['due_date6'];
$ins_amt7 = $_POST['installment7'];
$due_date7 = $_POST['due_date7'];
$ins_amt8 = $_POST['installment8'];
$due_date8 = $_POST['due_date8'];
$ins_amt9 = $_POST['installment9'];
$due_date9 = $_POST['due_date9'];
$ins_amt10 = $_POST['installment10'];
$due_date10 = $_POST['due_date10'];
$ins_amt11 = $_POST['installment11'];
$due_date11 = $_POST['due_date11'];
$ins_amt12 = $_POST['installment12'];
$due_date12 = $_POST['due_date12'];
$ins_amt13 = $_POST['installment13'];
$due_date13 = $_POST['due_date13'];
$ins_amt14 = $_POST['installment14'];
$due_date14 = $_POST['due_date14'];
$ins_amt15 = $_POST['installment15'];
$due_date15 = $_POST['due_date15'];
$ins_amt16 = $_POST['installment16'];
$due_date16 = $_POST['due_date16'];
$ins_amt17 = $_POST['installment17'];
$due_date17 = $_POST['due_date17'];
$ins_amt18 = $_POST['installment18'];
$due_date18 = $_POST['due_date18'];
$ins_amt19 = $_POST['installment19'];
$due_date19 = $_POST['due_date19'];
$ins_amt20 = $_POST['installment20'];
$due_date20 = $_POST['due_date20'];
$ins_amt21 = $_POST['installment21'];
$due_date21 = $_POST['due_date21'];
$ins_amt22 = $_POST['installment22'];
$due_date22 = $_POST['due_date22'];
$ins_amt23 = $_POST['installment23'];
$due_date23 = $_POST['due_date23'];
$ins_amt24 = $_POST['installment24'];
$due_date24 = $_POST['due_date24'];
$items = array();
$installment[] =array($ins_amt1, $ins_amt2, $ins_amt3, $ins_amt4, $ins_amt5, $ins_amt6, $ins_amt7, $ins_amt8, $ins_amt9, $ins_amt10, $ins_amt11, $ins_amt12, $ins_amt13, $ins_amt14, $ins_amt15, $ins_amt16, $ins_amt17, $ins_amt18, $ins_amt19, $ins_amt20, $ins_amt21, $ins_amt22, $ins_amt23, $ins_amt24);
//$in_values= serialize($installment);
$due_date[] = array($due_date1, $due_date2, $due_date3, $due_date4, $due_date5, $due_date6, $due_date7, $due_date8, $due_date9, $due_date10, $due_date11, $due_date12, $due_date13, $due_date14, $due_date15, $due_date16, $due_date17, $due_date18, $due_date19, $due_date20, $due_date21, $due_date22, $due_date23, $due_date24);
//$in_dates= serialize($due_date);
//$s1 = "insert into installment(id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) values ('', ".$fee_id.", '".$roll_no."', ".$in_values.", '".$in_dates."', '', 'unpaid', ''";
foreach($installment as $row_key => $value)
{
$item = $value;
$uom = $due_date[$row_key];
$items[] = sprintf("(%d, %d, '%s', %d, '%s', '%s', '%s', '%s')", '',
$fee_id,
mysql_real_escape_string($roll_no),
intval($item),
$uom,
'',
'',
''
);
}
$msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES '.implode(', ', $items);
But it is taking only one data. Can somebody please suggest.
The data has to be saved like this:
Like This http://netelity.com/saveddata.JPG
A normal INSERT statement should look like:
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
So try changing
$msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES '.implode(', ', $items);
To:
$values = implode(', ', $items);
$msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES ('.$values.');
And don't forget to actually run the sql command. I don't see that in your script anywhere :)
I had tried to insert bulk data with same name field contains multiple rows. But only single row is inserted.
How to insert bulk data as different values to insert into the database.
INSERT INTO table_name (username, luck_number, test, tester) VALUES (('$username', '$luck_number', '$test', '$tester').
<tr>
<td>1</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number" value="" />
</td>
<td>
<input type="text" name="big" value="" />
</td>
<td>
<input type="text" name="test" value="" />
</td>
<td>
<input type="text" name="tester" value="" />
</td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number" value="" />
</td>
<td>
<input type="text" name="big" value="" />
</td>
<td>
<input type="text" name="test" value="" />
</td>
<td>
<input type="text" name="tester" value="" />
</td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number" value="" />
</td>
<td>
<input type="text" name="big" value="" />
</td>
<td>
<input type="text" name="test" value="" />
</td>
<td>
<input type="text" name="tester" value="" />
</td>
</tr>
#nisha,In your scenario only single row is inserted because variables are same name so it's overridden, Please try below code, It will give you array of fields so you can easily create for-loop & do multiple insert with your query.
<form method="post" name="userdata">
<tr>
<td>1</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<input type="submit" name="submit">
</form>
**Note:**you can worry about the security issue letter. read the answer with the comment.
Store them in array by adding [ ] this in your input field
<tr>
<td>1</td>
<form action="" method="POST">
<input type="hidden" name="username" value="<?php echo $login_session; ?>"/>
<td><input type="text" name="luck_number[]" value=""/></td>
<td><input type="text" name="big[]" value=""/></td>
<td><input type="text" name="test[]" value=""/></td>
<td><input type="text" name="tester[]" value=""/></td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>"/>
<td><input type="text" name="luck_number[]" value=""/></td>
<td><input type="text" name="big[]" value=""/></td>
<td><input type="text" name="test[]" value=""/></td>
<td><input type="text" name="tester[]" value=""/></td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>"/>
<td><input type="text" name="luck_number[]" value=""/></td>
<td><input type="text" name="big[]" value=""/></td>
<td><input type="text" name="test[]" value=""/></td>
<td><input type="text" name="tester[]" value=""/></td>
</tr>
<tr></td><input type="submit" name="submit" value="submit"/><tr></td>
</form>
<?php
//connect with your database
for($i=0;$i<count($_POST['luck_number']);$i++)
{
//set the value for variable
$luck_number=$_POST['luck_number'][$i];
$test=$_POST['test'][$i];
$tester=$_POST['tester'][$i];
//run your query
//INSERT INTO table_name (username, luck_number, test, tester) VALUES (('$username', '$luck_number', '$test', '$tester').
}
First of all change all field names by adding [] at the end.
Second step, to parsing all values you may use something like this
for($i=0; $i < $count($_GET['username']); $i++)
{
$username = $_GET['username'][$i];
$luck_number= $_GET['luck_number'][$i];
$big= $_GET['big'][$i];
$test= $_GET['test'][$i];
$tester= $_GET['tester'][$i];
// insert into database
}
The reason of inserting single row instead of multiple rows is your input field name. You are using same name in different input field so when the server gets the reply it replace the duplicate name and the last occurrence is outputted.
The thing you have to do is to use array. If you use known number of rows then you can simply use a for loop to insert data.
<tr>
<td>1</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<?php
for ($i=0; $i<count($_POST['username']); $i++)
{
mysql_query("INSERT INTO table_name (`username`, `luck_number`, `test`, `tester`) VALUES (('".$_POST['username'][$i]."', '".$_POST['luck_number'][$i]."', '".$_POST['test'][$i]."', '".$_POST['tester'][$i]."')");
}
?>
Note: Sanitizing variable is always been a good practice and strongly recommended.
It is a regitration page in php where image is also uploading along with other user data but it is always showing error please help me to figure out the problem.It is always showing fail but i am using correct image. I also want to know how to set default value for profile image in phpmyadmin and how to query to update it when user enter his choice along with other user data that is to be inserted into database with insert query. and how to do insertion and updation at same time i.e inserting user data and updating default image.
<?php
include_once 'conn.inc';
if(isset($_POST["btnsave"])) {
$filename=$_FILES['file']['name'];
$size=$_FILES['file']['name'];
$extenstion=pathinfo($filename,PATHINFO_EXTENSION);
if($extenstion=='jpeg' || $extenstion=='png' || $extenstion=='jpg' && $size<=30000) {
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
}
else {
echo "failhhhhhhhhhh";
}
$name=mysql_real_escape_string($_POST["txtname"]);
$fname=mysql_real_escape_string($_POST["txtfname"]);
$gender=mysql_real_escape_string($_POST["gender"]);
$image=$_FILES['file']['name'];
$des=mysql_real_escape_string($_POST["des"]);
$job=mysql_real_escape_string($_POST["txtjob"]);
$country=mysql_real_escape_string($_POST["txtcountry"]);
$state=mysql_real_escape_string($_POST["txtstate"]);
$city=mysql_real_escape_string($_POST["txtcity"]);
$contact=mysql_real_escape_string($_POST["txtcontact"]);
$contactst=mysql_real_escape_string($_POST["contactst"]);
$email=mysql_real_escape_string($_POST["txtemail"]);
$emailst=mysql_real_escape_string($_POST["emailst"]);
$query="insert into tblregistration values
('','$name','$fname','$gender','$image','$des','$job','$country','$state','$city','$contact','$contactst','$email','$emailst')" or die('neverve'.mysql_error());
$res=mysql_query($query) or die('error 1'.mysql_error());
if(mysql_affected_rows())
{
echo "success";
}
else {
echo "failure";
}
}
?>
html form
<form method="post" action="registration.php" enctype="multipart/form-data">
<table>
<tr>
<td><label for="txtname">Name</label></td>
<td><input type="text" name="txtname" value="Enter your name"/></td>
</tr>
<tr>
<td><label for="txtfname">Father Name</label></td>
<td><input type="text" name="txtfname" value="Enter your father's name"/></td>
</tr>
<tr>
<td><label>Gender</label></td>
<td>Male<input type="radio" name="gender" checked="checked" value="m" />
Female<input type="radio" name="gender" value="f" />
</td>
</tr>
<tr>
<td>
<input onchange="readURL(this);" type="file" name="file" /></td>
<td><img alt="Image Display Here" id="test" src="./upload/icon3.jpg" height="100px" width="100px" /></td>
</tr>
<tr>
<td><label>Designation</label></td>
<td><select name="des">
<option value="-1">Select Designation</option>
<option value="Employed">Employed</option>
<option value="selfemployed">Self-Employed</option>
<option value="retired">Retired</option>
</select></td>
</tr>
<tr>
<td>
<label>Title of Job</label></td>
<td><input type="text" name="txtjob" value="title of job" /></td>
</tr>
<tr>
<td>
<label>Country</label></td>
<td><input type="text" name="txtcountry" value="Enter your country" /></td>
</tr>
<tr>
<td>
<label>State</label></td>
<td><input type="text" name="txtstate" value="Enter your State" /></td>
</tr>
<tr>
<td>
<label>City</label></td>
<td><input type="text" name="txtcity" value="Enter your city" /></td>
</tr>
<tr>
<td>
<label>Contact no</label></td>
<td><input type="tel" name="txtcontact" value="Enter your contact no" />
Private<input type="radio" name="contactst" value="0" /> Public<input type="radio" name="contactst" checked="checked" value="1"/>
</td>
</tr>
<tr>
<td>
<label>Email</label></td>
<td><input type="email" name="txtemail" value="Enter your email" />
Private<input type="radio" name="emailst" value="0" /> Public<input type="radio" name="emailst" checked="checked" value="1" />
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btnsave" value="submit" /></td>
</tr>
</table>
</form>
$size=$_FILES['file']['name']; please check this condition
Replace
$size=$_FILES['file']['name'];
with
$size=$_FILES['file']['size'];
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.