-
<?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??
7 5411 Dormilich 8,658
Recognized Expert Moderator Expert $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
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. - <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..
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
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= $_POST;//ABCDEFGHIJKLMNOPQRSTUVWXYZ
$value3= $_POST;//0123456789
$chars = $value1."".$value2."".$value3;
|
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
|
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();
...
|
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...
|
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...
| |
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.
|
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)
...
|
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))):"";
|
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);
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |