how to insert value in database while field value in array
Moderator: General Moderators
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
how to insert value in database while field value in array
how can i insert two field value in database while field value in array
script are
if(isset($_POST['check']))
{
foreach($_POST['check'] as $key => $val)
{
$sql1="insert into studentmarkstb values('$val','$obtmark','$subjectid')";
echo $sql1;
}
//$rs1 = mysql_query($sql1) or die(mysql_errormsg());
} }
above obtmark value also in array iam attaching a jpg file here in this file iam using Two array field frist Sno in Checkbox array and obtainmarks is also in array field. user can select any one value and submit in the database.
but how can i insert obtmarks value, while it is in array type.
regards,
script are
if(isset($_POST['check']))
{
foreach($_POST['check'] as $key => $val)
{
$sql1="insert into studentmarkstb values('$val','$obtmark','$subjectid')";
echo $sql1;
}
//$rs1 = mysql_query($sql1) or die(mysql_errormsg());
} }
above obtmark value also in array iam attaching a jpg file here in this file iam using Two array field frist Sno in Checkbox array and obtainmarks is also in array field. user can select any one value and submit in the database.
but how can i insert obtmarks value, while it is in array type.
regards,
- Attachments
-
- marks.JPG (20.46 KiB) Viewed 7557 times
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: how to insert value in database while field value in array
Any PHPian give some answer...................
Re: how to insert value in database while field value in array
foreach works with arrays.
$_POST['check'] is not an array.
$_POST is an array.
$_POST['check'] is not an array.
$_POST is an array.
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: how to insert value in database while field value in array
Thanks for your reply
here i know that foreach is for array but here check is array variable u see in the image i used sno and serialno iam using check box ad each checkbox having an studentid and their related marks when user select the student the marks should be insert the database with their id. here obtmarks is also array type variables.
here i know that foreach is for array but here check is array variable u see in the image i used sno and serialno iam using check box ad each checkbox having an studentid and their related marks when user select the student the marks should be insert the database with their id. here obtmarks is also array type variables.
Re: how to insert value in database while field value in array
Code: Select all
<?php
// Let's say that array $a contains the values you want to insert in the database
$a = array();
$a['check'] = "Whatever";
$a['obtmark'] = "65";
$a['subjectid'] = "33";
// the sql statement would go like this
$sql = "insert into studentmarkstb values('{$a['check']}','{$a['obtmark']}','{$a['subjectid']}')";
echo $sql; // insert into studentmarkstb values('Whatever','65','33')
?>-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: how to insert value in database while field value in array
the above image the course is having n numbers of student and i have to enter the selected students obtainmarks.
while Sno and ObtainMarks value is in Array how we can use both array value insert to the database.
i had tried and use loop but no result...........
pl send some solution..........
while Sno and ObtainMarks value is in Array how we can use both array value insert to the database.
i had tried and use loop but no result...........
pl send some solution..........
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: how to insert value in database while field value in array
any phpian is there who can solve my Problem..............
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: how to insert value in database while field value in array
manojsemwal1 wrote:any phpian is there who can solve my Problem..............
Re: how to insert value in database while field value in array
I use this in one of my scripts, feel free to adapt it to your needs.
Output:
INSERT INTO myTable (a,n) VALUES ('23','66')
You can iterate the above for each record you want to enter.
Code: Select all
<?php
$array = array('a'=> 23, 'n'=>66);
$sql = "INSERT INTO myTable (".implode(",", array_keys($array)).")
VALUES ('".implode("','", array_values($array))."')";
echo $sql;
?> INSERT INTO myTable (a,n) VALUES ('23','66')
You can iterate the above for each record you want to enter.
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: how to insert value in database while field value in array
i had applied your idea but its working only for one array type value but in my case iam using two array type value frist one when user select the student and enter the marks.
here obtainmarks and Sno is array type value.
when inserting into database obtainmarks and Regdid value should be enter in same query........
see the image
here obtainmarks and Sno is array type value.
when inserting into database obtainmarks and Regdid value should be enter in same query........
see the image
- Attachments
-
- entermarks.JPG (45.5 KiB) Viewed 7414 times
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: how to insert value in database while field value in array
hai manohoo
send some solution iam waiting.......................
send some solution iam waiting.......................