write to DB
-
Hi,
with the following part of code:
<?php class wp_calculator{ public $tabName; function __construct(){ global $wpdb; $this->tabName= $wpdb->prefix."calculator"; } public function init($hvId,$khId,$total){ $this->hvId = mysql_real_escape_string($hvId); $this->khId = mysql_real_escape_string($khId); $this->sotienDk = mysql_real_escape_string($total); } public function getInformation($idOrEmail){ $id = mysql_real_escape_string($idOrEmail); global $wpdb; $row = $wpdb->get_row("SELECT * FROM $this->tabName where user_email = '$id'"); //echo "SELECT * FROM $this->tabName where user_email = '$id'"; return $row; } public function updateInformation($idOrEmail){ $id = mysql_real_escape_string($idOrEmail); global $wpdb; $row = $wpdb->get_row("SELECT * FROM $this->tabName where id = $id or user_email = '$id'"); } public function createNew(){ global $wpdb; $username = mysql_real_escape_string($_REQUEST["username"]); $user_email = $_REQUEST["email"]; $user_email = mysql_real_escape_string($user_email); $height = mysql_real_escape_string($_REQUEST["height"]); $weight = mysql_real_escape_string($_REQUEST["weight"]); $desire_weight = mysql_real_escape_string($_REQUEST["desire_weight"]); $gender = mysql_real_escape_string($_REQUEST["gender"]); $age = mysql_real_escape_string($_REQUEST["age"]); $active_level_work = mysql_real_escape_string($_REQUEST["active_level_work"]); $active_level_free = mysql_real_escape_string($_REQUEST["active_level_free"]); $arr = array('user_name' => $username, 'user_email' => $user_email , 'height' => intval($height) ,'weight' => $weight , 'desire_weight' => $desire_weight ,'gender' => $gender , 'age' => intval($age) ,'active_level_work' => $active_level_work , 'active_level_free' => $active_level_free ,'status' => 'active' ); $arrType = array('%s','%s','%d','%s','%s','%s','%d','%s','%s','%s'); $row = $this->getInformation($user_email); if(isset($row) && !empty($row)){ $wpdb->query(" update $this->tabName set user_name='$username',height=$height,weight='$weight' ,desire_weight='$desire_weight',gender='$gender',age=$age,active_level_work='$active_level_work' ,active_level_free='$active_level_free' where user_email='$user_email'"); }else{ $result = $wpdb->insert($this->tabName,$arr,$arrType); } } public function delete($dkid){ global $wpdb; $$dkid= mysql_real_escape_string($dkid); $wpdb->query(" update $this->tabName set hv_status='delete' where dk_id=$dkid"); } } ?>
I write the values to a table in the WP Database, now I want to extend that and want to write in the same moment,
$username to field name
$user_email to field email
actual date (timestamp) to field date
‘1’ as number to field nid
‘1’ as number to field active
‘1’ as number to field confirmedas new entry in the table ‘wpr_subscribers’ of the same database
Table Structure is:
wp_3_wpr_subscribers` (
nid
int(11) NOT NULL,
id
int(11) NOT NULL AUTO_INCREMENT,
name
varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
email
varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
date
varchar(12) NOT NULL,
active
tinyint(1) NOT NULL DEFAULT ‘0’,
confirmed
tinyint(1) NOT NULL DEFAULT ‘0’,
fid
tinyint(1) NOT NULL DEFAULT ‘1’,
hash
varchar(50) NOT NULL,
PRIMARY KEY (id
),
UNIQUE KEYunique_email_for_newsletter
(nid
,email
)`Anyone can give me an hint how to do that.
Thanks a lot
- The topic ‘write to DB’ is closed to new replies.