I have one form input like
<input type="text" class="form-control" name="SITE_URL" id="SITE_URL" required>
So what I want is to add name's value SITE_URL
in one database column and the value I insert in other column like
v_name l_value
---------- ----------
SITE_URL "Inserted value "
l_value
is inserted completely but v_name
is not inserted my $_post
array is like:
Array
(
[SITE_URL] => value that i inserted
)
My code is:
if($_SERVER['REQUEST_METHOD'] == "POST"){
$post["l_value"] = $this->input->post('SITE_URL');
$post["v_name"] = $this->input->post('');
$addPage = $this->admin_model->addSiteSetting($post);
exit;
}
And addSiteSetting
function is:
public function addSiteSetting($ins){
$this->db->insert('tbl_setting', $ins);
return 1;
}
You should pass SITE_URL
as static name for $post["v_name"]
you need to change just one line $post["v_name"] = $this->input->post('');
To $post["v_name"] = 'SITE_URL';
if($_SERVER['REQUEST_METHOD'] == "POST"){
$post["l_value"] = $this->input->post('SITE_URL');
$post["v_name"] = 'SITE_URL';
$addPage = $this->admin_model->addSiteSetting($post);
exit;
}
You can process $_POST
in foreach
loop to get both names and their values, like this:
if($_SERVER['REQUEST_METHOD'] == "POST"){
$post = array();
foreach ($_POST as $name => $value) {
$post["l_value"] = $value;
$post["v_name"] = $name;
}
$addPage = $this->admin_model->addSiteSetting($post);
exit;
}
You just need to remove the following line. Because here you store the blank value into the v_name. That's why v_name doesn't get any value and keep it empty.
$post["v_name"] = $this->input->post('');
And Instead of the above line you need to add this line:
$post["v_name"] = 'SITE_URL';
You have
$post["l_value"] = $this->input->post('SITE_URL');
$post["v_name"] = $this->input->post('');
remove
$post["v_name"] = $this->input->post('');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.