我有一张看起来像这样的表:
ID | Name | Address
我有一个看起来像这样的表格:
<input type="text" class="form-control" name="name"/>
<input type="text" class="form-control" name="address"/>
我的PHP代码:
$name = $_POST['name'];
$address = $_POST['address'];
$sql = "Insert into staff(client_name,address) VALUES ('$client_name','$address')";
$this->db->query($sql);
我想要做的是,将用户发布的值加入一列。如果用户在名称字段中键入JOHN,在地址字段中键入USA。 我想在我的数据库表中跟随
ID | Name | Address
1 | JOHN USA | USA
答案 0 :(得分:2)
使用这样的东西:
select * from test1 t1 inner join test2 t2 on t1.id = t2.id;
答案 1 :(得分:0)
在插入数据库之前,只需将$_POST['name']
与$_POST['address']
中的$client_name
连接即可。像这样:
$client_name = $_POST['name'] .' '. $_POST['address'];
$address = $_POST['address'];
$sql = "Insert into staff(client_name,address) VALUES ('$client_name','$address')";
$this->db->query($sql);
答案 2 :(得分:0)
$client_name = $_POST['name'];
$address = $_POST['address'];
$name = $client_name .' '. $address;
$sql = "Insert into staff(client_name,address) VALUES ('$name','$address')";
$this->db->query($sql);
答案 3 :(得分:0)
试试这个
$name = $_POST['name'];
$address = $_POST['address'];
$client_name = $name.' | '.$address;
$sql = "Insert into staff(client_name,address) VALUES ('$client_name','$address')";
$this->db->query($sql);
答案 4 :(得分:0)
使用json_encode对内容进行编码,然后将其存储在数据库字段中,当您检索该值时,请使用json_decode
$form_data_json = json_encode( $_POST );
// store $form_data_json in database.
// When you want to get stored data, just fetch it from db. let it be stored in $fetch
$original_post_array = json_decode( $fetch, true );