Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Include Php Code The Retrieve Date From Sql Into Cs-Cart Page Rate Topic   - - - - -

 
  • osama moqbal
  • Advanced Member
  • Members
  • Join Date: 10-Jun 18
  • 73 posts

Posted 09 December 2018 - 06:25 AM #1

can you please help me how to include PHP code into the cs-cart page to make tracking system to customer from our service center database.does my code is not secure to the database.

here is my PHP code   

{

<html>
<meta name="viewport" content="width=device-width">
<style>
#customers {
  font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}
 
#customers td, #customers th {
  border: 1px solid #ddd;
  padding: 8px;
}
 
#customers tr:nth-child(even){background-color: #f2f2f2;}
 
#customers tr:hover {background-color: #ddd;}
 
#customers th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  background-color: #4CAF50;
  color: white;
}
input[type=submit] {
  width: 20%;
  background-color: #4CAF50;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  margin-left:10px;
  border-radius: 4px;
  cursor: pointer;
}
input[type=text] {
  width: 20%;
  padding: 12px 20px;
  margin: 8px 0;
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
}
 
</style>
<body>
<form method="post" action="file.php">
      please enter user_id:<input type="text" name="id" value="<?php echo $id;?>">
     <input type="submit" name="submit" value="submit">
     </form>
<table id="customers">
<tr>
<th>firstname</th>
<th>lastname</th>
</tr>
<?php
$id =$_POST["id"];
if (isset($_POST['submit'])){
 
$conn = mysqli_connect($localhost, "dbusername", "password", "dbname");
$id = $_POST["id"];
 
$sql = "SELECT `firstname` , `lastname` FROM `cscart_users` WHERE user_id = $id";
 
$result= mysqli_query($conn , $sql);
if ($result->num_rows > 0)  {
while ($row= mysqli_fetch_array($result)){
     
echo  "</td><td>". $row["firstname"] ."</td><td>". $row["lastname"] ."</td></tr>";
 
    }
    echo "</table>";
    }
    else {
     echo "<p><b>please ensure that invoice id or mobile number is correct </b></p>";
     
     }
 mysqli_close($conn); 
}
 
?>
</body> 
</html>    
   }


 
  • poppedweb
  • Authorized Reseller
  • Members
  • Join Date: 02-Aug 16
  • 543 posts

Posted 09 December 2018 - 03:45 PM #2

You could modify the smarty parameters to allow inline php code using the {php} tag.


PoppedWeb | sales@poppedweb.com | https://poppedweb.com
TurnKey Website Design | Add-Ons | Performance Audits | Dedicated Server Management
24/7 Support | Response within an hour (during working hours).

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11336 posts

Posted 09 December 2018 - 10:19 PM #3

Not clear what you're trying to do here.  It looks like you're retrieving a first/last name from another DB, then echoing the one id you've searched for as a table with a single row.

 

What is the problem you're trying to solve?  My guess is there is a much easier way.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • osama moqbal
  • Advanced Member
  • Members
  • Join Date: 10-Jun 18
  • 73 posts

Posted 10 December 2018 - 05:15 AM #4

thank you poppedweb and tbirnseth for your interest to help me , 

 

i tried to put the code into {php} {/php}, but it dosent work .

 

tbirnseth -> it just test php query code and if its work inseide cs-cart page so i will write my exact query but the problem i can not make php query include cs-cart , so the question is how .

  •  


 
  • galtinbaeva
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 06-Dec 13
  • 3362 posts

Posted 10 December 2018 - 05:21 AM #5

 

thank you poppedweb and tbirnseth for your interest to help me , 

 

i tried to put the code into {php} {/php}, but it dosent work .

 

tbirnseth -> it just test php query code and if its work inseide cs-cart page so i will write my exact query but the problem i can not make php query include cs-cart , so the question is how .

 

 

Hello!

 

Please add queries in function or controller in app directory. If you created a page, then you should have controller for it. It is not correct to write queries in templates.


Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER | LICENSES | DEVELOPMENT | ADD-ONS | DESIGN | UPGRADE

Google Analytics Enhanced Ecommerce - get advanced ecommerce analytics


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19591 posts

Posted 10 December 2018 - 06:34 AM #6

As alternative, you can call php functions in templates in the following way

{$smarty.post.id|fn_my_function_name}

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • osama moqbal
  • Advanced Member
  • Members
  • Join Date: 10-Jun 18
  • 73 posts

Posted 10 December 2018 - 09:42 AM #7

 

As alternative, you can call php functions in templates in the following way

{$smarty.post.id|fn_my_function_name}

 

i really trust about your advice eComlab , but I can't understand what you mean can you please clarify 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19591 posts

Posted 10 December 2018 - 02:04 PM #8

For example, you can create new function in the app/addons/my_changes/func.php

fn_my_function_name($id)
{
    fn_echo('The id is: ' . $id);
    return true;
}

and you can call this function in any template

 

{123|fn_my_function_name}
 
The result will be
 
The id is: 123

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11336 posts

Posted 10 December 2018 - 07:37 PM #9

The "best practices" way of doing it would be to have your controller do the query and then have it put the results in a smarty variable and use it within the templates.

 

I.e.:

app/addons/my_changes/controllers/frontend/get_info.php containing:

<?php
if( !defined('BOOTSTRAP') ) die('Access denied');
use Tygh\Registry;
switch($mode) {
  case 'verify_user':
    $data = my_function_get_remote_data();
    Tygh::$app['view']->assign('u_data', $data);
    return array(CONTROLLER_STATUS_OK);
}
die( "Unknown mode '$mode'");
 
This will call the template in design/themes/[YOUR THEME]/templates/addons/my_changes/verify_user.tpl  You would then reference your data there via:
{$data.my_field}
 
Strongly suggest you read the developer's guide at https://docs.cs-cart...dons/index.html

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • mazter
  • Senior Member
  • Members
  • Join Date: 04-Apr 12
  • 275 posts

Posted 10 December 2018 - 11:17 PM #10

Tony, is get_info.php just a made up example? or would it actually work?

 

Meaning, how would this file be called when CS-Cart is loading? My understanding is that you are limited with what's put under app/controllers/ and you can only do pre, post or override to these files. Am I wrong?

 

categories.php
checkout.php
companies.php
customization.php
index.php
init.php
orders.php
pages.php
product_features.php
products.php
profiles.php
promotions.php
robots.php
search.php
sitemap.php
theme_editor.php
xml_feeds.php


 
  • galtinbaeva
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 06-Dec 13
  • 3362 posts

Posted 11 December 2018 - 05:24 AM #11

 

Tony, is get_info.php just a made up example? or would it actually work?

 

Meaning, how would this file be called when CS-Cart is loading? My understanding is that you are limited with what's put under app/controllers/ and you can only do pre, post or override to these files. Am I wrong?

 

categories.php
checkout.php
companies.php
customization.php
index.php
init.php
orders.php
pages.php
product_features.php
products.php
profiles.php
promotions.php
robots.php
search.php
sitemap.php
theme_editor.php
xml_feeds.php

 

 

Hello!

 

You can create your own pages by adding new controller in your add-on and template for this new controller.


Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER | LICENSES | DEVELOPMENT | ADD-ONS | DESIGN | UPGRADE

Google Analytics Enhanced Ecommerce - get advanced ecommerce analytics


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19591 posts

Posted 11 December 2018 - 05:34 AM #12

 

Tony, is get_info.php just a made up example? or would it actually work?

 

Meaning, how would this file be called when CS-Cart is loading? My understanding is that you are limited with what's put under app/controllers/ and you can only do pre, post or override to these files. Am I wrong?

 

If you want to call this code on all pages, use the init.post.php file which is called for all available controllers

 

app/addons/my_changes/controllers/frontend/init.post.php


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • mazter
  • Senior Member
  • Members
  • Join Date: 04-Apr 12
  • 275 posts

Posted 11 December 2018 - 05:11 PM #13

Oleg and eComlabs, thanks for very useful comments. Is there a documentation on this in development guide? I looked it up but I couldn't find it. I'm very confused and left out with the way CS-Cart can be extended.

 

There are:

blocks, layouts, addons, hooks, controllers, schemas, banners

 

All these can be extended one way or another but how? To what extend?

 

The documentation seems very subtle and limited when it comes to extending CS-Cart.

 

I would appreciate if you have seen exchanges on this forum or on knowledge base and share them here so people like me can better understand it.

 

Thank you for your service and keeping this forum alive and useful.



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11336 posts

Posted 11 December 2018 - 11:54 PM #14

Read about addons.  You are asking questions about the architecture that is pretty clearly spelled out in the documentation.  I never mentioned anything about app/controllers.  I mentioned using an addon (app/addons/my_changes/controllers/frontend).  Once you understand how addons and other controllers (addons are just a controller) work, this will all make sense.

 

'get_info' is the "mode" for the my_changes controller you would be creating.  Using this 'mode' would mean that it would utilize a get_info.tpl template located in the directory design/themes/[YOUR THEME]/templates/addons/my_changes/ which I referenced above.

 

 

Tony, is get_info.php just a made up example? or would it actually work?

 

Meaning, how would this file be called when CS-Cart is loading? My understanding is that you are limited with what's put under app/controllers/ and you can only do pre, post or override to these files. Am I wrong?

 


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • galtinbaeva
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 06-Dec 13
  • 3362 posts

Posted 12 December 2018 - 05:03 AM #15

Oleg and eComlabs, thanks for very useful comments. Is there a documentation on this in development guide? I looked it up but I couldn't find it. I'm very confused and left out with the way CS-Cart can be extended.

 

There are:

blocks, layouts, addons, hooks, controllers, schemas, banners

 

All these can be extended one way or another but how? To what extend?

 

The documentation seems very subtle and limited when it comes to extending CS-Cart.

 

I would appreciate if you have seen exchanges on this forum or on knowledge base and share them here so people like me can better understand it.

 

Thank you for your service and keeping this forum alive and useful.

 

Here are some links from documentation:

 

Add-on directories - https://docs.cs-cart...irectories.html

Example of add-on creation - https://docs.cs-cart...s/advanced.html

General add-on development topic - https://docs.cs-cart...dons/index.html


Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER | LICENSES | DEVELOPMENT | ADD-ONS | DESIGN | UPGRADE

Google Analytics Enhanced Ecommerce - get advanced ecommerce analytics


 
  • osama moqbal
  • Advanced Member
  • Members
  • Join Date: 10-Jun 18
  • 73 posts

Posted 12 December 2018 - 01:38 PM #16

I tried to it but it also did not work with me, the database i will retrieve from it not cs-cart but other database. 



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11336 posts

Posted 12 December 2018 - 05:42 PM #17

Your function determines what DB to use.  You don't have to use a cs-cart DB to use mySQL.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19591 posts

Posted 13 December 2018 - 05:24 AM #18

I tried to it but it also did not work with me, the database i will retrieve from it not cs-cart but other database.


Hire someone from this this forum to make this small modification for you. It will not cost too much

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11336 posts

Posted 13 December 2018 - 10:58 PM #19

Deleted - wrong thread


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.