Page 1 of 1

Please help me in this

Posted: Thu Feb 18, 2010 11:47 pm
by punithapary
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

Re: Please help me in this

Posted: Fri Feb 19, 2010 5:22 am
by dejvos
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!

Re: Please help me in this

Posted: Fri Feb 19, 2010 6:03 am
by iamroming
could u be more specific so that i can help you

Re: Please help me in this

Posted: Fri Feb 19, 2010 8:04 am
by social_experiment
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']) "; ?>