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

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

{

#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;
}
please enter user_id:
$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 "
";
}
echo "
firstname lastname
". $row["firstname"] ." ". $row["lastname"] ."
";
}
else {
echo "

please ensure that invoice id or mobile number is correct

";
}
mysqli_close($conn);
}
?>
}

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

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.

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 .

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.

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

{$smarty.post.id|fn_my_function_name}

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

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

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:

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.com/4.8.x/developer_guide/addons/index.html

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

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.

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

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.

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?

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.com/4.5.x/developer_guide/addons/directories.html

Example of add-on creation - https://docs.cs-cart.com/4.5.x/developer_guide/addons/tutorials/advanced.html

General add-on development topic - https://docs.cs-cart.com/4.5.x/developer_guide/addons/index.html

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.

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

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

Deleted - wrong thread