Wordpress Database Values Wrong Format - php

i created a custom database for my wordpress installation. I am able to insert and get variables to/from it. My problem now is that the format of the variables is wrong.
// $pdflink is a url
$datum = date('d-m-y');
global $wpdb;
$tablename=$wpdb->prefix.'offers';
$wpdb->insert($tablename, array(
'benutzer' => $current_user_id,
'datum' => $datum,
'offer' => $pdflink,
),array('%d','%s','%s'));
The database looks like this.
$datum is "203" instead of "02.03.16" and $pdflink is "0" instead of a url.
What is wrong with it? Thanks for your help.

Related

Why am I not able to retrieve data - Codeigniter?

I recently added a column called user_cat to a table. I am not able to get this date to display on the webpage. However, I am able to display the data from columns user_id, email_id on the webpage using session variables using below.
$this->session->set_userdata("user_id", $this->session->userdata('loginUser') );
$this->session->set_userdata("user_id", $this->session->userdata('loginEmail') );
I checked the models page to and found the code to be like this.
$this->db->select('user_id,email_id');
&
'loginUser' => $row->user_id,
'loginEmail' => $row->email_id,
which i then changed to:
$this->db->select('user_id,email_id,user_cat');
&
'loginUser' => $row->user_id,
'loginCat' => $row-> user_cat,
'loginEmail' => $row->email_id,
Now i used the session variable like this:
$this->session->set_userdata("user_id", $this->session->userdata('loginCat') );
This did not work. I need help.
I assume that you didn't write the code yourself.Data from the database already set on the sessions. You can directly retrieve data using
this->session->userdata('loginUser')
So look for code like following in the model
$this->session->loginUser = //something;
//add your code
$this->session->loginCat = //similar to above
Take a look at Database reference.
However , following is the answer to your question
You are using same key to all session data. You should use a unique key for each session variable.
$this->session->set_userdata("user_id", $this->session->userdata('loginUser') );
$this->session->set_userdata("user_email", $this->session->userdata('loginEmail') );
$this->session->set_userdata("user_cat", $this->session->userdata('loginCat') );
Take a look at Session library.
first set you session like this
$data = array(
'loginUser' => $row -> user_id ,
'loginEmail' => $row -> email_id,
'loginCat' => "" ,
);
$this -> session -> set_userdata ( $data );
then update it
$data = array('loginCat' => $row -> user_cat );
$this -> session -> set_userdata ( $data );

multiple value insert using saveField function or other function in cakephp

I insert multiple values into my database using saveField function. Here is my code.
$this->Fuel->saveField(
'device_id', $int_fuel_func[0],
'func_code', $int_fuel_func[1],
'device_data', $int_fuel_func[2]
);
It's not a form value. Value automatically insert when the page is refreshed.
It's only inserts first value 'device_id', $int_fuel_func[0],. Other two values are not insert into my database. Any one suggest me how to insert these values.
Thanks in advance
Cake version 2.7.5
You can simply do this as well.
$data = array(
'device_id' => $int_fuel_value[0],
'func_code' => $int_fuel_value[1],
'device_data' => $int_fuel_value[2]
);
$this->Fuel->save($data);
Also try this blog tutorial (cakephp blog tutorial) if you haven't been there before to be more familiar with these things.
My id is not auto Increment it is defined as varchar. Time is not include there also. I got my answer. I use it and it works.
$this->Fuel->set(
array(
'device_id' => $int_fuel_value[0],
'func_code' => $int_fuel_value[1],
'device_data' => $int_fuel_value[2]
)
);
$this->Fuel->save();
saveField function is only for updating one field! use updateAll and pass an array to it :
$this->Fuel->updateAll(
array(
'device_id', $int_fuel_func[0],
'func_code', $int_fuel_func[1],
'device_data', $int_fuel_func[2]
),
array('Fuel.id' => 234) // conditions for the Fuel you want to update
);

wp_insert_post two values into the post_title

I'm currently working on inserting some data into my posts, I'm trying to insert two sets of data into the post title and I'm kinda stuck.
$my_post = array(
'post_title' => $data['title'],
This works fine, but I need to add another one to the title, how can I do that? for example
'post_title' => $data['title'] && $data['count'],
Any help would be appreciated, thank you.
Use a dot . to concatenate the titles:
'post_title' => $data['title'] . $data['count'],
See the PHP docs on string operators for more info.

why not insert query is working in codeigniter when ever we use right syn.?

why not insert query is working whenever i am using right syn.,i have used this type syntax in my other function of same controller.
code
$reviewData = $this->input->post('reviewData');
$id=1;
$rdaraaa = array(
'id' => $id,
'content' => $reviewData
);
$this->db->insert('reviews', $rdataaa);
please help me
Your variable name is wrong.It should be
$this->db->insert('reviews', $rdaraaa);
You have given wrong array $rdataaa instead of $rdaraaa.And makesure that id,content are the column names in your table reviews.
remove this code print_r($rdaraaa); die; and it should be
$this->db->insert('reviews',$rdaraaa)

Codeigniter says session userdata blank, but exists in db

Whenever i try check for a value in my userdata column of my session it thinks it's blank, when it's actually in the ci_sessions table serialised.
here's the db content unserialised:
array (
'user_data' => '',
'edit' =>
array (
'image_id' => 'HF',
'session_id' => '783c15b057bcd9c19d3fd82f367ee55d',
),
)
here's how im checking for the userdata in my view (note sessions are autoloaded)
<?php if ($this->session->userdata('edit')) : ?>
enter code here
and here's how i set the session userdata:
$values = array(
'image_id' => implode(",",$uploaded_image_ids),
'session_id' => $this->session->userdata('session_id')
);
$this->session->set_userdata('edit', $values);
Can anyone see the problem? (whole controller here http://pastebin.com/aXeRn1VN)
Also heres my config.php http://pastebin.com/A31nrC1b
View variables are separate from other variables in CI. I think (am still a bit of a CI newbie) that $this->session is not available in Views. This CI forum post discusses a couple of possible solutions to the problem http://codeigniter.com/forums/viewthread/100587/#508098 - one is to pass the value of 'userdata' from the session into the $data array you pass to the view - which seems the best solution.
You can use like this
<?php $edit = $this->session->userdata('edit'): if (!empty($edit)) : ?>

Categories