0

I want to take two variables from two different fields of a form and insert into one column... but can't understand how to do?? here is what i've tried..

$name= $_GET['name'];
$age = $_GET['age'];
$sex = $_GET['sex'];
$wpm = $_GET['wpm'];   
$query = "INSERT INTO ajax_example (name,age,sex,wpm) values ('$name','$age','$sex','$wpm.$age')";

I want the combination of age and wpm to be stored in wpm

Ash
  • 3
  • 5
  • 2
    concatenate **first** then assign a new variable to the ones you want to be combined. – Funk Forty Niner Nov 11 '15 at 14:38
  • This should do the work `$query = "INSERT INTO ajax_example (name,age,sex,wpm) values ('name','age','sex','{$wpm}{$age}')";` – xwlee Nov 11 '15 at 14:47
  • `$query = "INSERT INTO ajax_example (name, age, sex, wpm) values ('$name', '$age', '$sex', '".$wpm.$age."')";` – TGrif Nov 11 '15 at 14:50

1 Answers1

0

You can just join the strings first:

$col = $wpm.$age;
$query = "INSERT INTO ajax_example (name,age,sex,wpm) values ('$name','$age','$sex','$col')";

Notice that using the code like this is very dangerous - SQL injection.

Ron Dadon
  • 2,666
  • 1
  • 13
  • 27
  • it's not working i've tried it.. i think i shouldn't store this value and concatenate in echo... – Ash Nov 11 '15 at 15:27
  • The only way it will not work is if wpm field length is set to a length that can only conatin $wpm value. for example if it is varchar(3) and the length of $wpm is 3 and $age is 2, than only the first 3 characters from the concatenate string will be store, and those equals to $wpm value. – Ron Dadon Nov 11 '15 at 15:48