Hello,
I have problem in PHP String concatination with html select combo
box.
There are 3 files
addressbook.sql :
concat1.php
concat2.php
In concat1.php , if we select User Name in combo box & give input as 3
in
text box.
It display following output
subhash kanade,3 sk@yahoo.com
But, it is not display in that way.
So, please see that code & tell me correction.
addressbook.sql
-- Table structure for table `addressbook`
--
CREATE TABLE `addressbook` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT= 7 ;
--
-- Dumping data for table `addressbook`
--
INSERT INTO `addressbook` (`id`, `name`, `email`) VALUES (1, 'pradeep
kulkarni', 'pradeep@cotmac-proex.com'),
(2, 'vinod wagh', 'vinod@rediff.c om'),
(3, 'subhash kanade', 'sk@yahoo.com') ,
(4, 'ketan patil', 'kp@hotmail.com ');
concat1.php
<?php
mysql_connect(" localhost","roo t")or die("Database Failed");
mysql_select_db ("pradeep")o r die("Failed to Connect Database");
$arr=array("con cat(concat(name ,','),id)","ema il");
$str="select ".$arr[0].", ".$arr[1]." from addressbook";
$res=mysql_quer y($str) or die("resultset error");
echo "<table><tr><th >User</th><th>Email</th></tr>";
while($row=mysq l_fetch_array($ res)){
echo "<tr><td>". $row[0]."</td><td>".$row[1]."</td></tr>";
}
echo "</table>";
echo "<center>Search </center>";
echo "<form name=frm action=concat2. php method=get>";
echo "<input type=text name=txtField<s elect name=selField>< option
value='".$arr[0]."'>User Name</option><option value='".$arr[1]."'>E-
Mail</option></select>";
echo "<input type=submit>";
echo "</form>";
?>
concat2.php
<?
$arr1=array("co ncat(concat(nam e,','),id)","em ail");
$str="select ".$arr1[0].",".$arr1[1]." from addressbook where ".
$_REQUEST['selField']." like '%".$_REQUEST['txtField']."%'";
echo "<hr>Query : ".$str;
?>
Thanks in advance
I have problem in PHP String concatination with html select combo
box.
There are 3 files
addressbook.sql :
concat1.php
concat2.php
In concat1.php , if we select User Name in combo box & give input as 3
in
text box.
It display following output
subhash kanade,3 sk@yahoo.com
But, it is not display in that way.
So, please see that code & tell me correction.
addressbook.sql
-- Table structure for table `addressbook`
--
CREATE TABLE `addressbook` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT= 7 ;
--
-- Dumping data for table `addressbook`
--
INSERT INTO `addressbook` (`id`, `name`, `email`) VALUES (1, 'pradeep
kulkarni', 'pradeep@cotmac-proex.com'),
(2, 'vinod wagh', 'vinod@rediff.c om'),
(3, 'subhash kanade', 'sk@yahoo.com') ,
(4, 'ketan patil', 'kp@hotmail.com ');
concat1.php
<?php
mysql_connect(" localhost","roo t")or die("Database Failed");
mysql_select_db ("pradeep")o r die("Failed to Connect Database");
$arr=array("con cat(concat(name ,','),id)","ema il");
$str="select ".$arr[0].", ".$arr[1]." from addressbook";
$res=mysql_quer y($str) or die("resultset error");
echo "<table><tr><th >User</th><th>Email</th></tr>";
while($row=mysq l_fetch_array($ res)){
echo "<tr><td>". $row[0]."</td><td>".$row[1]."</td></tr>";
}
echo "</table>";
echo "<center>Search </center>";
echo "<form name=frm action=concat2. php method=get>";
echo "<input type=text name=txtField<s elect name=selField>< option
value='".$arr[0]."'>User Name</option><option value='".$arr[1]."'>E-
Mail</option></select>";
echo "<input type=submit>";
echo "</form>";
?>
concat2.php
<?
$arr1=array("co ncat(concat(nam e,','),id)","em ail");
$str="select ".$arr1[0].",".$arr1[1]." from addressbook where ".
$_REQUEST['selField']." like '%".$_REQUEST['txtField']."%'";
echo "<hr>Query : ".$str;
?>
Thanks in advance