-
<?php
-
include("database.php");
-
$query2="select prodcode,prodname,id from product";
-
$result2=mysqli_query($con,$query2);
-
echo"<table border='2' align='center' cellpadding='0' cellspacing='0' style='width:50%'>";
-
echo"<tr>";
-
echo"<thead>";
-
echo"<th>"."ProductCode"."</th>";
-
echo"<th>"."ProductName"."</th>";
-
echo"<th>"."Quantity"."</th>";
-
echo"</thead>";
-
while($row=mysqli_fetch_array($result2,MYSQL_ASSOC))
-
{
-
echo"<tr>";
-
echo"<td>"."<input type='checkbox' id='chk' value='".$row['prodcode']."'name='checkbox1[]'/>".$row['prodcode']."</td>";
-
echo"<td>".$row['prodname']."</td>";
-
echo"<td>"."<input type='text' maxlength='4' id='quan' name='quantity[]'class ='quantity'/>"."</td>";
-
echo"</tr>";
-
}
-
?>
-
<?php
-
include("database.php");
-
if(isset($_POST["btnsubmit"]))
-
{
-
$check=$_POST['checkbox1'];
-
$quantity=$_POST["quantity"];
-
-
for ($i=0; $i<sizeof($check);$i++)
-
{
-
$query="INSERT INTO elevconfigdetails(id,prodcode,quantity)
-
VALUES ('$id','".$check[$i]."','".$quantity."' )";
-
mysqli_query($con,$query) or die ('Error updating database'.mysqli_error($con));
-
echo "</br>Record is inserted.";
-
}
-
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??
$quantity is an array, but you treat it as string, which obviously won’t work.
7 5357 $quantity is an array, but you treat it as string, which obviously won’t work.
@Dormilich ya the name attribute of textbox is an array..i want to insert multiple textbox values into database
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
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. - <input type="number" min="0" name="qantity[{product-id}]" value="0">
where {product-id} is the product id.
then you can do in PHP - // using PDO for insert
-
foreach ($products as $id) {
-
$stmt->execute([
-
':id' => $id,
-
':quantity' => $quantities[$id],
-
]);
-
}
-
@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..
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
okk.thank you Dormilich..........
Sign in to post your reply or Sign up for a free account.
Similar topics
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=...
|
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...
|
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...
|
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,...
|
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....
|
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...
|
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.
...
|
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
...
|
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 ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |