Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
Need help using this in php 7 and pdo
// Фиксируем местоположение гостей
$movings = 0;
$session = md5(core::$ip . core::$ip_via_proxy . core::$user_agent);
$req = mysql_query("SELECT * FROM `cms_sessions` WHERE `session_id` = '$session' LIMIT 1");
if (mysql_num_rows($req)) {
// Если есть в базе, то обновляем данные
$res = mysql_fetch_assoc($req);
$movings = ++$res['movings'];
if ($res['sestime'] < (time() - 300)) {
$movings = 1;
$sql .= " `sestime` = '" . time() . "', ";
}
if ($res['place'] != $headmod) {
$sql .= " `place` = '" . mysql_real_escape_string($headmod) . "', ";
}
mysql_query("UPDATE `cms_sessions` SET $sql
`movings` = '$movings',
`lastdate` = '" . time() . "'
WHERE `session_id` = '$session'
");
} else {
// Если еще небыло в базе, то добавляем запись
mysql_query("INSERT INTO `cms_sessions` SET
`session_id` = '" . $session . "',
`ip` = '" . core::$ip . "',
`ip_via_proxy` = '" . core::$ip_via_proxy . "',
`browser` = '" . mysql_real_escape_string($agn) . "',
`lastdate` = '" . time() . "',
`sestime` = '" . time() . "',
`place` = '" . mysql_real_escape_string($headmod) . "'
");
}
I don't know how to do it
Related
Hellos.
Assist me with two queries in the file below intended to upload CSV files
Failing to upload to a MySQL without logging errors (Am I missing folder/file permissions?)
"Undefined offset" error from anything after column 10 in CSV (Is there a limit I declared unknowingly?)
Thank You.
if(isset($_POST['import'])){
$csvMimes = array('text/x-comma-separated-values',
'text/comma-separated-values',
'application/octet-stream',
'application/vnd.ms-excel',
'application/x-csv',
'text/x-csv', 'text/csv',
'application/csv',
'application/excel',
'application/vnd.msexcel',
'text/plain');
if(!empty($_FILES['file']['name'])
&& in_array($_FILES['file']['type'], $csvMimes))
{
if(is_uploaded_file($_FILES['file']['tmp_name'])){
$csvFile = fopen($_FILES['file']['tmp_name'], 'r');
fgetcsv($csvFile);
while(($line = fgetcsv($csvFile)) !== FALSE){
$ColID = $line[0];
$Col02 = $line[1];
$Col03 = $line[2];
$Col04 = $line[3];
$Col05 = $line[4];
$Col06 = $line[5];
$Col07 = $line[6];
$Col08 = $line[7];
$Col09 = $line[8];
$Col010 = $line[9];
$Col0n = $line[10];
$prevQuery = "SELECT id
FROM table_name
WHERE ColID = '".$line[0]."'";
$prevResult = $db->query($prevQuery);
if($prevResult){
if($prevResult->num_rows > 0){
$db->query("UPDATE table_name
SET ColHdg02 = '".$Col02."',
ColHdg03 = '".$Col03."',
ColHdg04 = '".$Col04."',
ColHdg05 = '".$Col05."',
ColHdg06 = '".$Col06."',
ColHdg07 = '".$Col07."',
ColHdg08 = '".$Col08."',
ColHdg09 = '".$Col09."',
ColHdg010 = '".$Col010."',
ColHdg0n = '".$Col0n."'
WHERE ColIDHdg = '".$ColID."'");
} else{
$db->query("INSERT INTO table_name
(ColIDHdg, ColHdg02, ColHdg03, ColHdg04,
ColHdg05, ColHdg06, ColHdg07, ColHdg08,
ColHdg09, ColHdg010, ColHdg0n)
VALUES ('".$ColID."', '".$Col02."', '".$Col03."',
'".$Col04."', '".$Col05."', '".$Col06."',
'".$Col07."', '".$Col08."', '".$Col09."',
'".$Col010."', '".$Col0n."')");
}
}
}
fclose($csvFile);
You're trying to get an Undefined offset, for your example please check if the number of items on $line is 11 or more.
if (count($line) > 10) {
$ColID = $line[0];
$Col02 = $line[1];
$Col03 = $line[2];
$Col04 = $line[3];
$Col05 = $line[4];
$Col06 = $line[5];
$Col07 = $line[6];
$Col08 = $line[7];
$Col09 = $line[8];
$Col010 = $line[9];
$Col0n = $line[10];
$prevQuery = "SELECT id FROM table_name WHERE ColID = '" . $line[0] . "'";
$prevResult = $db->query($prevQuery);
if ($prevResult) {
if ($prevResult->num_rows > 0) {
$db->query("UPDATE table_name SET ColHdg02 = '" . $Col02 . "', ColHdg03 = '" . $Col03 . "', ColHdg04 = '" . $Col04 . "', ColHdg05 = '" . $Col05 . "', ColHdg06 = '" . $Col06 . "', ColHdg07 = '" . $Col07 . "', ColHdg08 = '" . $Col08 . "', ColHdg09 = '" . $Col09 . "', ColHdg010 = '" . $Col010 . "', ColHdg0n = '" . $Col0n . "' WHERE ColIDHdg = '" . $ColID . "'");
} else {
$db->query("INSERT INTO table_name (ColIDHdg, ColHdg02, ColHdg03, ColHdg04, ColHdg05, ColHdg06, ColHdg07, ColHdg08, ColHdg09, ColHdg010, ColHdg0n) VALUES ('" . $ColID . "', '" . $Col02 . "', '" . $Col03 . "', '" . $Col04 . "', '" . $Col05 . "', '" . $Col06 . "', '" . $Col07 . "', '" . $Col08 . "', '" . $Col09 . "', '" . $Col010 . "', '" . $Col0n . "')");
}
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I am assuming I would need to JOIN the two queries before the for loop but what would be the best to optimise the following code:
$LocationArray0 = array();
$LocationArray1 = array();
$LocationArray2 = array();
$LocationArray3 = array();
$LocationArray4 = array();
foreach($Bodyshops as $Bodyshop) {
$Query = "SELECT BodyshopID, BodyshopName, BodyshopLongitude, BodyshopLatitude FROM FusionBodyshops WHERE BodyshopID = '$Bodyshop'";
$result = mysqli_query($db, $Query);
$rows = mysqli_num_rows($result);
if ( $rows != 0 ) {
for ( $i = 0; $i < $rows; $i ++ ) {
$row = mysqli_fetch_array($result, MYSQL_ASSOC);
$BodyshopID = $row['BodyshopID'];
$BodyshopName = $row['BodyshopName'];
$BodyshopLatitude = $row['BodyshopLatitude'];
$BodyshopLongitude = $row['BodyshopLongitude'];
$query2 = "SELECT Tier FROM FusionBodyshopSettings WHERE BodyshopID = '$Bodyshop' AND BusinessID = '$UserCompany'";
$result2 = mysqli_query($db, $query2);
$row2 = mysqli_fetch_array($result2, MYSQL_ASSOC);
if ( $row2['Tier'] == "0") {
array_push($LocationArray0, "'" . str_replace("'", "",$BodyshopName) . "', '" . $BodyshopLatitude . "', '" . $BodyshopLongitude . "'"); //$row['BodyshopID'] . ", " .
}elseif ( $row2['Tier'] == "1") {
array_push($LocationArray1, "'" . str_replace("'", "",$BodyshopName) . "', '" . $BodyshopLatitude . "', '" . $BodyshopLongitude . "'"); //$row['BodyshopID'] . ", " .
}elseif ( $row2['Tier'] == "2") {
array_push($LocationArray2, "'" . str_replace("'", "",$BodyshopName) . "', '" . $BodyshopLatitude . "', '" . $BodyshopLongitude . "'"); //$row['BodyshopID'] . ", " .
}elseif ( $row2['Tier'] == "3") {
array_push($LocationArray3, "'" . str_replace("'", "",$BodyshopName) . "', '" . $BodyshopLatitude . "', '" . $BodyshopLongitude . "'"); //$row['BodyshopID'] . ", " .
}elseif ( $row2['Tier'] == "4") {
array_push($LocationArray4, "'" . str_replace("'", "",$BodyshopName) . "', '" . $BodyshopLatitude . "', '" . $BodyshopLongitude . "'"); //$row['BodyshopID'] . ", " .
}
}
}
}
Any help would be greatly appreciated!
You can replace ALL of your code with something like this:
SELECT a.BodyshopID
, a.BodyshopName
, a.BodyshopLongitude
, a.BodyshopLatitude
, b.Tier
FROM FusionBodyshops a
JOIN FusionBodyshopSettings b
ON b.BodyshopID = a.BodyshopID
WHERE a.BodyshopID IN ($Bodyshops) -- a list of bodyshops
AND b.BusinessID = $UserCompany;
Now see prepared statements.
$queryb = "SELECT product, imei, country, warranty, config from PRODUCT WHERE product_slno = '$mnserialno' ";
$resultb = mysql_query($queryb, $gndbconn) ;
if(mysql_num_rows($resultb) > 0)
{
$queryc = "UPDATE PRODUCT SET product='$desc', product_slno='$mnserialno',imei='$imei',country='$country',warranty='$warranty',config='$config' WHERE product_slno = '.$mnserialno.' ";
$resutc = mysql_query($queryc, $gndbconn) ;
}
else{
$querya = "INSERT INTO PRODUCT SET product='$desc', product_slno='$mnserialno',imei='$imei',country='$country',warranty='$warranty',config='$config'";
$resulta = mysql_query($querya, $gndbconn) ;
}
I want to check the serial number if that serial number already exist in database so records get update, otherwise it get insert into the database.
but the code inserting the records only, no updation, what is the fault i am not getting,
how to prevent the duplicate entry?
INSERT INTO PRODUCT SET
(`product`, `product_slno`, `imei`, `country`, `warranty`, `config`)
VALUES
('" . $desc . "', '" . $mnserialno . "', '" . $imei . "', '" . $country . "', '" . $warranty . "', '" . $config . "')
ON DUPLICATE KEY UPDATE
product='" . $desc . "',
product_slno='" . $mnserialno . "',
imei='" . $imei . "',
country='" . $country . "',
warranty='" . $warranty . "',
config='" . $config . "'";
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Answer always "terjadi kesalahan saat mengirim komen!". Can anyone help me?
$message = mysql_real_escape_string(bbcode_to_html($message));
if (mysql_query('insert into topics (id_parent, id, id_user, title, message, id_author, timestamp, timestamp_user) select "' . $dn1['id_parent'] . '", "' . $id . '", max(id_user)+1, "", "' . $message . '", "' . $_SESSION['userid'] . '", "' . time() . '", "' . time() . '" from topics where id="' . $id . '"') and mysql_query('update topics set timestamp_user="' . time() . '" where id="' . $id . '" and id_user=1')){
?><header class="major">
Komen sukses! Kembali ke Topik!
</header>
<?php
}else{
echo 'Terjadi kesalahan saat mengirim komen!';
}
Edited:
Try just adding this code:
<?php
$message = mysql_real_escape_string(bbcode_to_html($message));
$sqlquery1 = 'insert into topics (id_parent, id, id_user, title, message, id_author, timestamp, timestamp_user) select "' . $dn1['id_parent'] . '", "' . $id . '", max(id_user)+1, "", "' . $message . '", "' . $_SESSION['userid'] . '", "' . time() . '", "' . time() . '" from topics where id="' . $id . '"';
$sqlquery2 = 'update topics set timestamp_user="' . time() . '" where id="' . $id . '" and id_user=1';
$result1 = mysql_query($sqlquery1) or die(mysql_error() . ": Full Query was: " . $sqlquery1);
$result2 = mysql_query($sqlquery2) or die(mysql_error() . ": Full Query was: " . $sqlquery2);
if ( $result1 and $result2){
?><header class="major">
Komen sukses! Kembali ke Topik!
</header>
<?php
}else{
echo 'Terjadi kesalahan saat mengirim komen!';
}
?>
This will now also show you the query you tried to execute. This will help if you want further questions answered well.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I just got my last question answered but now I'm stuck again.. I'm using OpenCart and I want to change the style of my email you'll get when you register on my OpenCart webshop. But when I use add this for example, it just shows it in the email as normal text:
$message .= '<img src="logo.png" />' "\n";
When I searched it on Google, on every site it says that I have to use this:
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
I pasted it on a few places in my code but it never worked, it was still showing the HTML Tags as text in the email.
I will paste my code (from OpenCart) here and can somebody tell me then where I have to paste that code or just another way to use HTML in email via PHP?
<?php
class ModelAccountCustomer extends Model {
public function addCustomer($data) {
if (isset($data['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($data['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $data['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$this->load->model('account/customer_group');
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
$this->db->query("INSERT INTO " . DB_PREFIX . "customer SET store_id = '" . (int)$this->config->get('config_store_id') . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', newsletter = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "', customer_group_id = '" . (int)$customer_group_id . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', status = '1', approved = '" . (int)!$customer_group_info['approval'] . "', date_added = NOW()");
$customer_id = $this->db->getLastId();
$this->db->query("INSERT INTO " . DB_PREFIX . "address SET customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', company = '" . $this->db->escape($data['company']) . "', company_id = '" . $this->db->escape($data['company_id']) . "', tax_id = '" . $this->db->escape($data['tax_id']) . "', address_1 = '" . $this->db->escape($data['address_1']) . "', address_2 = '" . $this->db->escape($data['address_2']) . "', city = '" . $this->db->escape($data['city']) . "', postcode = '" . $this->db->escape($data['postcode']) . "', country_id = '" . (int)$data['country_id'] . "', zone_id = '" . (int)$data['zone_id'] . "'");
$address_id = $this->db->getLastId();
$this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . (int)$address_id . "' WHERE customer_id = '" . (int)$customer_id . "'");
$this->language->load('mail/customer');
Here starts the part of the code what is going to be visible in the email itself.
<--From here-->
**$subject = sprintf($this->language->get('text_subject'), $this->config->get('config_name'));
$message = sprintf($this->language->get('text_welcome'), $this->config->get('config_name')) . "\n\n";
if (!$customer_group_info['approval']) {
$message .= $this->language->get('text_login') . "\n";
} else {
$message .= $this->language->get('text_approval') . "\n";
}
$message .= $this->url->link('account/login', '', 'SSL') . "\n\n";
$message .= $this->language->get('text_services') . "\n\n";
$message .= $this->language->get('text_thanks') . "\n";
$message .= $this->config->get('config_name');**
<--Till here-->
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($data['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($this->config->get('config_name'));
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
$mail->send();
// Send to main admin email if new account email is enabled
if ($this->config->get('config_account_mail')) {
$message = $this->language->get('text_signup') . "\n\n";
$message .= $this->language->get('text_website') . ' ' . $this->config->get('config_name') . "\n";
$message .= $this->language->get('text_firstname') . ' ' . $data['firstname'] . "\n";
$message .= $this->language->get('text_lastname') . ' ' . $data['lastname'] . "\n";
$message .= $this->language->get('text_customer_group') . ' ' . $customer_group_info['name'] . "\n";
if ($data['company']) {
$message .= $this->language->get('text_company') . ' ' . $data['company'] . "\n";
}
$message .= $this->language->get('text_email') . ' ' . $data['email'] . "\n";
$message .= $this->language->get('text_telephone') . ' ' . $data['telephone'] . "\n";
$mail->setTo($this->config->get('config_email'));
$mail->setSubject(html_entity_decode($this->language->get('text_new_customer'), ENT_QUOTES, 'UTF-8'));
$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
$mail->send();
// Send to additional alert emails if new account email is enabled
$emails = explode(',', $this->config->get('config_alert_emails'));
foreach ($emails as $email) {
if (strlen($email) > 0 && preg_match('/^[^\#]+#.*\.[a-z]{2,6}$/i', $email)) {
$mail->setTo($email);
$mail->send();
}
}
}
}
public function editCustomer($data) {
$this->db->query("UPDATE " . DB_PREFIX . "customer SET firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "' WHERE customer_id = '" . (int)$this->customer->getId() . "'");
}
public function editPassword($email, $password) {
$this->db->query("UPDATE " . DB_PREFIX . "customer SET salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($password)))) . "' WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "'");
}
public function editNewsletter($newsletter) {
$this->db->query("UPDATE " . DB_PREFIX . "customer SET newsletter = '" . (int)$newsletter . "' WHERE customer_id = '" . (int)$this->customer->getId() . "'");
}
public function getCustomer($customer_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");
return $query->row;
}
public function getCustomerByEmail($email) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "'");
return $query->row;
}
public function getCustomerByToken($token) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE token = '" . $this->db->escape($token) . "' AND token != ''");
$this->db->query("UPDATE " . DB_PREFIX . "customer SET token = ''");
return $query->row;
}
public function getCustomers($data = array()) {
$sql = "SELECT *, CONCAT(c.firstname, ' ', c.lastname) AS name, cg.name AS customer_group FROM " . DB_PREFIX . "customer c LEFT JOIN " . DB_PREFIX . "customer_group cg ON (c.customer_group_id = cg.customer_group_id) ";
$implode = array();
if (isset($data['filter_name']) && !is_null($data['filter_name'])) {
$implode[] = "LCASE(CONCAT(c.firstname, ' ', c.lastname)) LIKE '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "%'";
}
if (isset($data['filter_email']) && !is_null($data['filter_email'])) {
$implode[] = "LCASE(c.email) = '" . $this->db->escape(utf8_strtolower($data['filter_email'])) . "'";
}
if (isset($data['filter_customer_group_id']) && !is_null($data['filter_customer_group_id'])) {
$implode[] = "cg.customer_group_id = '" . $this->db->escape($data['filter_customer_group_id']) . "'";
}
if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
$implode[] = "c.status = '" . (int)$data['filter_status'] . "'";
}
if (isset($data['filter_approved']) && !is_null($data['filter_approved'])) {
$implode[] = "c.approved = '" . (int)$data['filter_approved'] . "'";
}
if (isset($data['filter_ip']) && !is_null($data['filter_ip'])) {
$implode[] = "c.customer_id IN (SELECT customer_id FROM " . DB_PREFIX . "customer_ip WHERE ip = '" . $this->db->escape($data['filter_ip']) . "')";
}
if (isset($data['filter_date_added']) && !is_null($data['filter_date_added'])) {
$implode[] = "DATE(c.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
}
if ($implode) {
$sql .= " WHERE " . implode(" AND ", $implode);
}
$sort_data = array(
'name',
'c.email',
'customer_group',
'c.status',
'c.ip',
'c.date_added'
);
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY name";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
if ($data['limit'] < 1) {
$data['limit'] = 20;
}
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}
$query = $this->db->query($sql);
return $query->rows;
}
public function getTotalCustomersByEmail($email) {
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "'");
return $query->row['total'];
}
public function getIps($customer_id) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_ip` WHERE customer_id = '" . (int)$customer_id . "'");
return $query->rows;
}
public function isBanIp($ip) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_ban_ip` WHERE ip = '" . $this->db->escape($ip) . "'");
return $query->num_rows;
}
}
?>
The one that reads this, thank you for your time!
$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
Your setting it as text.
Try setting has HTML.
$mail->setHTML($message);