Hi,
<?php
// include database config file
require_once('config.php');
// include database connecting file
require_once('connect.php');
// include common function file
require_once('inc_functions.php');
// starting session
startSesstion();
//check admin user validation
adminValidateUser();
// include some php function library
require_once('lib.php');
$query = "select * from intranet_clientfields";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$i = 0;
$rCount = 0;
while($i < $num)
{
$name= mysql_result($result,$i,"fname");
$finputname1 = mysql_result($result,$i,"finputname");
$input = $finputname1 ;
echo $_REQUEST[$finputname1];
$insert ="INSERT INTO `intranet_clientregistration`($input) values('$_REQUEST[finputname]')";
mysql_query($insert);
$rCount = $rCount + 1;
$i = $i + 1;
}
?>
In the above code its taking the data's from the form but in that form all fields and fields data's are coming from the database .In that $input is the field name which is in the intranet_clientfields table .In that table totally i ahve 5 data's when i am running this code i have to get 5 fields like this (data1,data2,data3) instead of $input in the output side.
for example i have data's in the intranet_clientfields table
data
data1
data2
data3
data4
i want to show these data's inthe insert query so i gave like this
$query = "select * from intranet_clientfields";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$i = 0;
$rCount = 0;
while($i < $num)
{
$name= mysql_result($result,$i,"fname");
$finputname1 = mysql_result($result,$i,"finputname");
$input = $finputname1 ;
echo $_REQUEST[$finputname1];
$insert ="INSERT INTO `intranet_clientregistration`($input) values('$_REQUEST[finputname]')";
mysql_query($insert);
$rCount = $rCount + 1;
$i = $i + 1;
}
i have to show like this
INSERT INTO `intranet_clientregistration`(data,data1,data2,data3,data4) values('fdf','dsd,'dsd','dsdsd','dsd');
but its taking like this
INSERT INTO `intranet_clientregistration`(data) values('fdf')
INSERT INTO `intranet_clientregistration`(data1) values('dsd')
INSERT INTO `intranet_clientregistration`(data2) values('dsd')
INSERT INTO `intranet_clientregistration`(data3) values('dsdsd')
INSERT INTO `intranet_clientregistration`(data4) values('dsd')
Even its adding 5 times in to the database but i want only one time with all data's
Please can anyone tell me how to do this?
Thanks in advance
Punitha Pary
Please help me in this
Moderator: General Moderators
Re: Please help me in this
Hi!
Why you don't use one insert?
[sql] INSERT INTO my_table (col) VALUES ("Hello"),("World"),("!"); [/sql]
You can generate one query and them use mysql_query only once.
I recommand you to look into MySQL or other SQL documentation.
Good luck!
Why you don't use one insert?
[sql] INSERT INTO my_table (col) VALUES ("Hello"),("World"),("!"); [/sql]
You can generate one query and them use mysql_query only once.
I recommand you to look into MySQL or other SQL documentation.
Good luck!
-
iamroming
- Forum Commoner
- Posts: 27
- Joined: Sun Jan 31, 2010 4:02 am
- Location: Hyderabad, India
- Contact:
Re: Please help me in this
could u be more specific so that i can help you
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Please help me in this
From what you type i gather that you are trying to add the data by submitting the form. [Please correct me if i am wrong]. If this is indeed the case, why don't you do a once off insert as dejvos suggests ?
Code: Select all
<?php $query = "INSERT INTO table ($_POST['fieldname'], $_POST['fieldname1']) VALUES ($_POST['value'], $_POST['value']) "; ?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering