Page 1 of 1

Adding <select opttions> more than one value into mysql

Posted: Mon Nov 30, 2009 3:22 am
by ibom
Hey.
I traying to add more than one value into the database. by using the the option.
Ex. USA country -> into table country. And Dollar currency -> into table currency.

Code: Select all

 
<select name="country" id="select8">
            <option value="USA,Dollar">USA</option>
            <option value="Germany,EURO">Germany</option>
</select>
 
I'm using this mysql connection to insert into tables. :

Code: Select all

 
mysql_query("INSERT INTO users
                  (`user_email`,`user_pwd`,`country`,`transacc`,`joined`,`activation_code`,`full_name`,`Website`)
                  VALUES
                  ('$_POST[email]','$md5pass','$_POST[country]','$_POST[transacc]',now(),'$activ_code','$_POST[full_name]','$_POST[Website]')") or die(mysql_error());
 
What is the correct code for inserting Country and Currency, Ehat do I need the change... Plzz help

Re: Adding <select opttions> more than one value into mysql

Posted: Mon Nov 30, 2009 7:29 am
by ibom
PLZZZ NEED SOME HELP....

Re: Adding <select opttions> more than one value into mysql

Posted: Mon Nov 30, 2009 9:50 am
by AbraCadaver

Code: Select all

$fields = explode(",", mysql_real_escape_string($_POST['country']));
 
mysql_query("INSERT INTO country (`country`) VALUES ('$fields[0]')");
mysql_query("INSERT INTO currency (`currency`) VALUES ('$fields[1]')");
-Shawn

Re: Adding <select opttions> more than one value into mysql

Posted: Mon Nov 30, 2009 12:08 pm
by ibom
Thanks for your replay..

I'm getting an error.: Column count doesn't match value count at row 1

I have looked at the table names and it match...

What does the error means......

Re: Adding <select opttions> more than one value into mysql

Posted: Mon Nov 30, 2009 12:17 pm
by AbraCadaver
ibom wrote:Thanks for your replay..

I'm getting an error.: Column count doesn't match value count at row 1

I have looked at the table names and it match...

What does the error means......
That was just an example. I have no idea what your tables look like. Either give all of the column names and values in your insert, or use this syntax:

Code: Select all

mysql_query("INSERT INTO country SET `country` = '{$fields[0]}'");
-Shawn

Re: Adding <select opttions> more than one value into mysql

Posted: Mon Nov 30, 2009 12:37 pm
by ibom
This is my table... Thanks


CREATE TABLE `users` (
`id` int(20) NOT NULL auto_increment,
`full_name` varchar(200) character set latin1 collate latin1_general_ci NOT NULL default '',
`user_pwd` varchar(200) character set latin1 collate latin1_general_ci NOT NULL default '',
`user_email` varchar(200) character set latin1 collate latin1_general_ci NOT NULL default '',
`activation_code` int(10) NOT NULL default '0',
`user_payment` int(1) NOT NULL default '0',
`joined` date NOT NULL default '0000-00-00',
`country` varchar(100) character set latin1 collate latin1_general_ci NOT NULL default '',
`user_activated` int(1) NOT NULL default '0',
`transacc` varchar(10) NOT NULL,
`currency` varchar(10) character set latin1 collate latin1_bin NOT NULL,
`Website` varchar(255) character set latin1 collate latin1_general_ci NOT NULL,
`User_Phone` int(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;