Trying to insert random emails like test''#test.com, etc.. and they are inserted into the database. Shouldn't this be automatically prevented by Active Record?
My query:
$data = array(
'name' => ''.$name.'' ,
'email' => ''.$email.'' ,
'country' => ''.$country.'' ,
'phone' => ''.$phone.'' ,
'compid' => ''.$compID.''
);
$this->db->insert('people', $data);
Where all variables are taken from user POST input, such as
$this->input->post('address')
for address.
shouldn't this be:
$data = array(
'name' => $name,
'email' => $email,
'country' => $country,
'phone' => $phone,
'compid' => $compID
);
$this->db->insert('people', $data);
Related
I needed to add some params to the order_data array in(v2/class-wc-api-order.php) woocommere and i've created a plugin so my changes wouldn't be overwritten by every update but i cant manage to get the id from the class?
I want $id to be the same the id i send in with my API
$id =
$order = wc_get_order( $id );
$olddata = array(
'first_name' => $order->shipping_first_name,
'last_name' => $order->shipping_last_name,
'company' => $order->shipping_company,
'address_1' => $order->shipping_address_1,
'address_2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country,
);
I want to create a custom registration for wordpress and I need to create a new custom field for each profile. For example a phone field.
Here's my code
function registration()
{
$userdata = array(
'user_login' => esc_attr($this->username),
'phone' => esc_attr($this->username),
'pre_user_email' => esc_attr($this->email),
'user_pass' => esc_attr($this->password),
'user_url' => esc_attr($this->website),
'first_name' => esc_attr($this->first_name),
'last_name' => esc_attr($this->last_name),
'nickname' => esc_attr($this->nickname),
'description' => esc_attr($this->bio),
);
The phone line is my custom field for profile.
It doesn't work, I've tried creating a custom field in the admin user panel, and it works! But I can't insert data to that field phone
function registration()
{
$userdata = array(
'user_login' => esc_attr($this->username),
'phone' => esc_attr($this->phone),
'pre_user_email' => esc_attr($this->email),
'user_pass' => esc_attr($this->password),
'user_url' => esc_attr($this->website),
'first_name' => esc_attr($this->first_name),
'last_name' => esc_attr($this->last_name),
'nickname' => esc_attr($this->nickname),
'description' => esc_attr($this->bio),
);
}
You should add 'phone' string on MySQL db
how to see what is the actual problem if we enter the data through a form in a textbox to insert in the database table, but there is not displayed any error
after commenting on the error reporting(0) also
code for database:
<?php
include('connection_temp.inc.php');
include('functions.inc.php');
?>
<?php
sm_registerglobal('MEMBER_ACCOUNT_INFO_ID', 'FIRST_NAME', 'LAST_NAME', 'EMAIL_ID', 'PHONE_NO', 'STATES_ID', 'CITIES_ID', 'PASS', 'LOCALITY');
$tbl_registrations = array(
'FIRST_NAME' => $FIRST_NAME,
'LAST_NAME' => $LAST_NAME,
'STATES_ID' => $STATES_ID,
'CITIES_ID' => $CITIES_ID,
'EMAIL_ID' => $EMAIL_ID,
'PHONE_NO' => $PHONE_NO,
'PASS' => $PASS,
'LOCALITY' => $LOCALITY,
);
/*$tbl_member_account_info = array(
'FIRST_NAME' => 'ssk',
'LAST_NAME' => 'sss',
'STATES_ID' => '6',
'CITIES_ID' => '12',
'EMAIL_ID' => 'asd#w.com',
'PHONE_NO' => '3324234',
'PASS' => '123',
'LOCALITY' => 'abad',
);*/
//$registrations_id = insert($con, "tbl_registrations", $tbl_registrations);
$member_account_info_id = insert($con, "tbl_member_account_info", $tbl_member_account_info);
//echo $member_account_info_id;
?>
Do not add comma with last element in array. try below code
<?php
include('connection_temp.inc.php');
include('functions.inc.php');
?>
<?php
sm_registerglobal('MEMBER_ACCOUNT_INFO_ID', 'FIRST_NAME', 'LAST_NAME', 'EMAIL_ID', 'PHONE_NO', 'STATES_ID', 'CITIES_ID', 'PASS', 'LOCALITY');
$tbl_registrations = array(
'FIRST_NAME' => $FIRST_NAME,
'LAST_NAME' => $LAST_NAME,
'STATES_ID' => $STATES_ID,
'CITIES_ID' => $CITIES_ID,
'EMAIL_ID' => $EMAIL_ID,
'PHONE_NO' => $PHONE_NO,
'PASS' => $PASS,
'LOCALITY' => $LOCALITY
);
/*$tbl_member_account_info = array(
'FIRST_NAME' => 'ssk',
'LAST_NAME' => 'sss',
'STATES_ID' => '6',
'CITIES_ID' => '12',
'EMAIL_ID' => 'asd#w.com',
'PHONE_NO' => '3324234',
'PASS' => '123',
'LOCALITY' => 'abad',
);*/
//$registrations_id = insert($con, "tbl_registrations", $tbl_registrations);
$member_account_info_id = insert($con, "tbl_member_account_info", $tbl_member_account_info);
//echo $member_account_info_id;
?>
Error reporting must be set as error_reporting(E_ALL) to see all the errors. if you set error_reporting(0) no error will be displayed as it is used to hide all the error generally in production mode.
And remove the comma in the end as you are passing the array that comma should not be there, and check the $con variable once whether you have properly declared the database connection or not, if the problem is still not resolved check the error by setting the error_reporting(E_ALL) and debug and check whether any error appears in the console.
//here is my function block
public function create_accnt()
{
$post = $this->input->post(); //gets all possible posts in array form
echo "Post array: ";print_r($post); // just to make sure that my array has values
$data = array(
'userid' => $post['user_id'],
'lastname' => $post['lname'],
'firstname' => $post['fname'],
'username' => $post['username'],
'password' => $post['password'],
'usertype' => $post['user_type'],
'status' => 'A'
); // assigning my values to their specific fields where they will be inserted
$query = $this->db->insert('accounts', $data); //insertion via active record
echo "<br/>Result of db last query: ";
echo $this->db->last_query();//to see how my query looks in code form
if($query)
{
return true;
}
else
return false;
// end if
} // end function
//here is the result of the code above
//Post array: Array ( [user_id] => 123456 [lname] => Smith [fname] => John [username] => John [password] => password [c_password] => password [user_type] => S [btn_create] => Create )
//Result of db last query: INSERT INTO accounts (userid, lastname, firstname, username, password, usertype, status) VALUES ('', '', '', '', '', '', '')
here why is it that after the query my VALUES were all spaces? by the way i am using CodeIgniter and my db driver is PDO and my database is DBFoxPro.
I ended up using $this->db->query() function of CI and manualy providing my query statement with it. I think $this->db->insert() wont work on my db DBF-foxpro via PDO driver. I also had a problem about $this->db->where() function. now Im just using $this->db->query(). Thank you for all your help.
instead of
$data = array(
'userid' => $post['user_id'],
'lastname' => $post['lname'],
'firstname' => $post['fname'],
'username' => $post['username'],
'password' => $post['password'],
'usertype' => $post['user_type'],
'status' => 'A'
);
use
$data = array(
'userid' => $this->input->post('user_id'),
'lastname' => $this->input->post('lname'),
'firstname' => $this->input->post('fname'),
'username' => $this->input->post('username'),
'password' => $this->input->post('password'),
'usertype' => $this->input->post('user_type'),
'status' => 'A'
);
If I need to retrieve a single row of data from the database, why can't I do this when I want to insert that id into another table:
'user_id' => $query->row()->id
Is there any way to do this without a foreach loop if all I want is a single piece of data?
The full code is:
$this->db->where('username', $this->input->post('username'));
$query = $this->db->get('members');
$data = array(
'first' => $this->input->post('first'),
'last' => $this->input->post('last'),
'email' => $this->input->post('email'),
'phone' => $this->input->post('phone'),
'address' => $this->input->post('address'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'zip' => $this->input->post('zip'),
'comments' => $this->input->post('comments'),
'username' => $this->input->post('username'),
'user_id' => $query->row()->id
);
$this->db->insert('contact', $data);
$query->row()->id is correct, yes. Given that the field is called 'id' in your table, and the row exists that you want. You can check $query->num_rows() to see how many rows were returned.
$the_data= $query->row();
$user_id= $the_data->id;
don't think you can do method chaining like in your example.