473,549 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how Do I Insert multiple values of Checkbox & textbox corresponding to it in database

5 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.                     include("database.php");
  3. $query2="select prodcode,prodname,id from product";
  4. $result2=mysqli_query($con,$query2);
  5. echo"<table border='2' align='center' cellpadding='0' cellspacing='0' style='width:50%'>";
  6. echo"<tr>";
  7. echo"<thead>";
  8. echo"<th>"."ProductCode"."</th>";
  9. echo"<th>"."ProductName"."</th>";
  10. echo"<th>"."Quantity"."</th>";
  11. echo"</thead>";
  12.                 while($row=mysqli_fetch_array($result2,MYSQL_ASSOC))
  13. {
  14. echo"<tr>";
  15. echo"<td>"."<input type='checkbox' id='chk' value='".$row['prodcode']."'name='checkbox1[]'/>".$row['prodcode']."</td>";
  16. echo"<td>".$row['prodname']."</td>";
  17. echo"<td>"."<input type='text' maxlength='4' id='quan' name='quantity[]'class ='quantity'/>"."</td>";
  18. echo"</tr>";
  19. }
  20. ?>
  21. <?php
  22. include("database.php");
  23. if(isset($_POST["btnsubmit"]))
  24. {
  25. $check=$_POST['checkbox1'];
  26. $quantity=$_POST["quantity"];
  27.  
  28. for ($i=0; $i<sizeof($check);$i++) 
  29. {
  30. $query="INSERT INTO elevconfigdetails(id,prodcode,quantity)
  31. VALUES ('$id','".$check[$i]."','".$quantity."' )";
  32. mysqli_query($con,$query) or die ('Error updating database'.mysqli_error($con));
  33. echo "</br>Record is inserted.";
  34. }
  35.  

when user click on submit button checkbox values(which is checked) and textbox values should be insert into mysql table row by row.i am successful to insert multiple checkbox values but the related textbox value is not inserted into database.
how i can fix this problem??
any help plzzzzzzz??
May 3 '16 #1
7 5411
Dormilich
8,658 Recognized Expert Moderator Expert
$quantity is an array, but you treat it as string, which obviously won’t work.
May 4 '16 #2
priya555
5 New Member
@Dormilich ya the name attribute of textbox is an array..i want to insert multiple textbox values into database
May 4 '16 #3
priya555
5 New Member
i am having multiple checkboxes that are coming from database and i have given a field(textbox) with every checkbox...now suppose 10 checkboxes are coming from database..now i want to insert values in database only of those checkboxes which are checked along with their textbox values.in textbox user insert the quantity.when i click on submit button the checkbox values are getting inserted right but the corresponding textbox values are not getting inserted..help me to solve this problem
May 4 '16 #4
Dormilich
8,658 Recognized Expert Moderator Expert
the problem is that there is no relation between the checkboxes and the text boxes. this is the first problem to solve.

I’d assign the text boxes using the product id. i.e.
Expand|Select|Wrap|Line Numbers
  1. <input type="number" min="0" name="qantity[{product-id}]" value="0">
where {product-id} is the product id.

then you can do in PHP
Expand|Select|Wrap|Line Numbers
  1. // using PDO for insert
  2. foreach ($products as $id) {
  3.     $stmt->execute([
  4.         ':id' => $id, 
  5.         ':quantity' => $quantities[$id],
  6.     ]);
  7. }
  8.  
May 4 '16 #5
priya555
5 New Member
@Dormilich thanks for reply..i am new in PHP.so dont know about PDO...please tell me your suggestion in (mysqli) so it is helpfull me to understand..how i can write the insert query.??
means the id field auto-increment and the last_id field is need to repeated.so tell me that..
May 4 '16 #6
Dormilich
8,658 Recognized Expert Moderator Expert
I find mysqli prepared statements awfully complicated, so I stick to PDO.

and for PDO you can check out the documentation: http://php.net/pdo
May 4 '16 #7
priya555
5 New Member
okk.thank you Dormilich...... ....
May 4 '16 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2610
by: Fareast Adam | last post by:
Here is my code: if(isset($_REQUEST)) { $nopwd= $_POST;//no of password $length = $_POST;//lenght of password $value1= $_POST;//abcdefghijklmnopqrstuvwxyz $value2= $_POST;//ABCDEFGHIJKLMNOPQRSTUVWXYZ $value3= $_POST;//0123456789 $chars = $value1."".$value2."".$value3;
0
1090
by: shantanu | last post by:
hi all I need to read the excel sheet for the values. The requirement is like: For the number of rows in the excel which are not null, i need to store the values of the row in a array and then acess the array to store data in the database. Kindly assist regards
5
2763
parshupooja
by: parshupooja | last post by:
Hello I am trying to create to a Timesheet . I am intiating number of textboxes and label based on criteria chosen by admin. This is what i have written in pageload to generate timesheet for 2 weeks for (int i = 1; i <= 14; i++) { Label date = new Label(); date.ID = "Item" + i.ToString(); ...
3
2780
vijcbe
by: vijcbe | last post by:
Hello PHP veterans, I am new to PHP. I tried to insert the session id of a user into the database table. code: $xyz = "insert into table_name values(' ', '$PHPSESSID', ...)"; The issue is, when I check the session id value in mysql, I could find the word $PHPSESSID instead of having the 32 lettered session id. I tried removing the quotes...
2
5223
by: rajsrmc | last post by:
Hello experts Let's say I have a gridview with some columns like, title, name, funding agency. Here's an example of what I want to do: I want to display all the records in the gridview to start. There would be a dropdownlist that lets the user select whether to search by title, name, funding agency and a text box that lets them type in what...
1
5084
by: dev singh | last post by:
Sir would like to know how to insert date, month and year selected from datepicker into mysql database thorugh php. I am trying to store the value of datepicker but it shows 00-00-00 kindly help with code.
3
17773
by: ROXIT | last post by:
hello every one pls tell me how can i save multiple checkbox value into database. I have created one table into the database named Category_Table and another table named CategoryTitle. for e.x. 1.Graphics and Animation(From Category_Table) 1.Concept Artist(From CategoryTitle Table) ...
1
1898
by: ahmad641 | last post by:
***> here is the code***. > when i search single word like GOOGLE then the result is appear > if i search two or more word search then the result is not appear. <?php include("connection.php"); @ob_start(); session_start(); $GLOBALS=isset($_GET) ? htmlspecialchars(urldecode(urlencode($_GET))):"";
1
1986
by: navsa | last post by:
I have multiple records in mysql database,but i need to fetch all the records from db and store it on seperate dynamic created form.please help me guyz its urgent.. id name 1 aaa 2 bbb 3 ccc 4 ddd <?php $sql = "select * from table"; $query=mysql_query($sql);
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.