Reputation: 549
i looked around and can't find info on this, and the things i did find are close but no cigar.
lets' say i have these form fields:
<input type="text" name="field1" />
<input type="text" name="field2" />
<input type="text" name="field3" />
<select name="selectfield">
<option value="">select</option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
<input type="text" name="textfield" />
and a database table like so:
id, field1, field2, field3, field4
so what i want is for form fields 1 through 3 to go into table columns 1 through 3, then i want the values of the 4th and 5th form fields to go into the 4th table column. something like this, but i doubt this is how it's done...
mysql_query("INSERT tableName SET field1='$field1', field2='$field2', field3='field3', field4='$selectfield + $textfield' ") or die(mysql_error());
edit: sorry meant fields 1 - 3 go into columns 2 through 4, and the last 2 fields go into 5th column. forgot to count id column.
Upvotes: 0
Views: 4584
Reputation: 1254
In database design it is not a good idea to keep the sum in table, it is better to keep in two fields,(also I think seems that you need a foreign key ) and before view the data to user concat them,
or
mysql_query("INSERT tableName SET field1='$field1', field2='$field2', field3='field3', field4='".$selectfield.$textfield."' ") or die(mysql_error());
Upvotes: 0
Reputation: 1496
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
$field3 = $_POST['field3'];
$selectfield = $_POST['selectfield'];
$textfield = $_POST['textfield'];
$newtext = $selectfield . $textfield ; // concatenation
mysql_query("INSERT into tablename SET field1='$field1', field2='$field2', field3='field3', field4='$newtext' ") or die(mysql_error());
You can use something like this for youe ease. Thanks.
Upvotes: 1