How to Navigate to Another View in PHP Codeigniter

I have a register view and a register controller and a header. in the header there is a drop down menu.

Now when I click on the login button from the header nav drop down menu, it doesn’t do anything it only refreshes the page and doesn’t take me to the login or registration page. (this is true for all my other views and controllers.)

even when I navigate to the URL hardcoded like /register/login it gives me 404 PAGE NOT FOUND error

How can I load my views correctly in the controllers and then navigate to them from my views.

What am I doing wrong?

Here is my code:

Controller for the register.
Register.php:

class Register extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        $this->load->library(array(
            'session',
            'email',
            'form_validation',
        ));
        $this->load->database();
        $this->load->helper(array(
            'url',
            'string',
        ));
        $this->load->model(array(
            'auth_model',
            'user_model',
            'price_ranges_model',
            'category_model',
            'quote_model',
        ));
    }

    public function index()
    {
        $this->load->view('footer', array(
            'page_title' => 'Register',
        ));
        $this->load->view('register', array(
            'price_ranges' => $this->price_ranges_model->get(),
            'categories' => $this->category_model->get(),
            'delivery_timings' => $this->user_model->_delivery_timings,
        ));
        $this->load->view('footer');
    }

public function login()
    {
        $this->form_validation->set_rules('c_username', 'Username', 'required');
        $this->form_validation->set_rules('c_password', 'Password', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('header', array(
                'page_title' => 'Register',
            ));
            $this->load->view('register', array(
                'price_ranges' => $this->price_ranges_model->get(),
                'categories' => $this->category_model->get(),
                'delivery_timings' => $this->user_model->_delivery_timings,
            ));
            $this->load->view('footer');
        }

the register.php view:

<div class="col_two_third col_last nobottommargin">


                <h3>Don't have an Account? Register Now.</h3>

                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Unde, vel odio non dicta provident sint ex autem mollitia dolorem illum repellat ipsum aliquid illo similique sapiente fugiat minus ratione.</p>

                <form class="nobottommargin" method="post" action="<?=site_url('register/post')?>">

                    <div class="col_half">
                        <label for="register-form-name">Customer Name:</label>
                        <input type="text" id="qname" name="name" value="<?=set_value('name')?>" class="form-control" />
                        <?php echo form_error('name'); ?>
                    </div>
                    
                

                    <div class="col_half">
                        <label for="register-form-email">Email Address (Username):</label>
                        <input type="email" id="qemail" name="email" value="<?=set_value('email')?>" class="form-control" />
                        <?php echo form_error('email'); ?>
                    </div>

                    <

                    <div class="col_half">
                        <label for="register-form-password">Password:</label>
                        <input type="password" id="qpassword" name="password" value="" class="form-control" />
                        <?php echo form_error('password'); ?>
                    </div>

                    <div class="col_half col_last">
                        <label for="register-form-cpassword">Confirm Password:</label>
                        <input type="password" id="qcpassword" name="password_confirm" value="" class="form-control" />
                        <?php echo form_error('password_confirm'); ?>
                    </div>

                        <?php echo form_error('est_amount'); ?>
                    </div>

the header.php view:

<div class="top-links on-click">
                            <form class="form-inline m-0" method="post" action="<?=base_url('register/login')?>">
                              <div class="form-group m-2">
                                <input type="email" class="form-control form-control-sm" placeholder="Username" name="c_username" required>
                              </div>
                              <div class="form-group m-2">
                                <input type="password" class="form-control form-control-sm" placeholder="Password" name="c_password" required>
                              </div>
                              <button type="submit" class="btn btn-sm btn-primary m-2">GO</button>
                            </form>
                        </div><!-- .top-links end -->

How to echo one value from JSON response from the code below [duplicate]

The following piece of code displays data from an API.
How do i echo only one value from the displayed data, For example only echo FIRSTNAME
I have tried many solutions from Stackoverflow and other websites but non of them works for me!

Here is the code:

<?php


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://example.com/data/XXX');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Length: 0';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

var_dump($result);

?>

Output:

string(531)"{"obj":{"result":{"FIRSTNAME":"JOHN","SECONDNAME":"DOE"}}"

Wont proceed if enter the correct uname and pass. After I uploaded the code online. It shows no error at all. The code works smoothly in offline [duplicate]

<?php
class DBConnection{

    private $host = 'localhost';
    private $username = 'id17280929';
    private $password = 'EpidemicResearch12345*';
    private $database = 'id17280929';
    
    public $conn;
    
    public function __construct(){

        if (!isset($this->conn)) {
            
            $this->conn = new mysqli($this->host, $this->username, $this->password, $this->database);
            
            if (!$this->conn) {
                echo 'Cannot connect to database server';
                exit;
            }            
        }    
        
    }
    public function __destruct(){
        $this->conn->close();
    }
}
?>

This is the Db connection File

    <?php
    session_start();
    $dev_data = array('id'=>'-1','firstname'=>'Developer','lastname'=>'','username'=>'admin','password'=>'5da283a2d990e8d8512cf967df5bc0d0','last_login'=>'','date_updated'=>'','date_added'=>'');
    if(!defined('base_url')) define('base_url','https://mywebsitelink.000webhostapp.com/');
    if(!defined('base_app')) define('base_app', str_replace('\','/',__DIR__).'/' );
    if(!defined('dev_data')) define('dev_data',$dev_data);
    require_once('classes/DBConnection.php');
    require_once('classes/SystemSettings.php');
    $db = new DBConnection;
    $conn = $db->conn;
    
    function redirect($url=''){
        if(!empty($url))
        echo '<script>location.href="'.base_url .$url.'"</script>';
    }
    function validate_image($file){
        if(!empty($file)){
            if(@getimagesize(base_url.$file)){
                return base_url.$file;
            }else{
                return base_url.'dist/img/no-image-available.png';
            }
        }else{
            return base_url.'dist/img/no-image-available.png';
        }
    }

This the config.php File

My Problem is if enter the correct info nothing happens to the login form. If i enter the incorrect info, the says incorrect, which is correct. I can’t explain any further. I hope you understand what I am pointing about. Thanks for your help.

WordPress Multilanguage with variable and get request

i tried almost all plugins and not giving me what im looking for

im looking to click on a _GET link and convert site / content to another dir / lang and have 2 variable for each Lang as example :

  $is_lang = htmlspecialchars($_SESSION['WPLANG'], ENT_QUOTES);
  $is_en = htmlspecialchars('en_US', ENT_QUOTES);
  $is_ar = htmlspecialchars('ar', ENT_QUOTES);
    
    if(isset($is_lang) = $is_en):
--    
-- show something
--
    elseif(isset($is_lang) = $is_ar):
--    
-- show something
--
    endif;

so i end up with this wp-config :

$language = isset( $_GET['lang'] ) ? htmlspecialchars($_GET['lang'], ENT_QUOTES) : 'en';
switch ( $language ) {
    case 'ar':
        define( 'WPLANG', 'ar' );
        $_SESSION['WPLANG'] = 'ar';
    break;

    case 'en':
    default:
    define( 'WPLANG', 'en_US' );
    $_SESSION['WPLANG'] = 'en_US';
}

change /view-order/2877/ to /orders/2877/

i want change view-order to orders

before : /my-account/view-order/2877/

after : /my-account/orders/2877/

path : /plugins/woocommerce/includes/class-wc-order.php | line 1675

/**
 * Generates a URL to view an order from the my account page.
 *
 * @return string
 */
public function get_view_order_url() {
    return apply_filters( 'woocommerce_get_view_order_url', wc_get_endpoint_url( 'view-order', $this->get_id(), wc_get_page_permalink( 'myaccount' ) ), $this );
}

If / Else in HTML within a return of PHP function

I am trying to use an if/else statement within an HTML structure of a return in a PHP function:

function price_vat() {
    global $product;
    $condition = $product->get_attribute( 'pa_condition' );
    
    return'
    <div class="condition-container">
        <div class="condition-wrapper">
        <?php if($condition = "New"){ ?>
            <div id="content-banned">New</div>
        <?php } else { ?>
            <div id="content-not-banned">Used</div>
        <?php } ?>
        </div>
    </div>
    ';
}

I am sure it is just a syntax issue here, does anyone have any ideas? Also tried with a tertiary operator but couldn’t get it to work. Any input is appreciated.

How can I set variable php and mysql code

I want to set a variable “name”,
I tried: if(isset($_POST[‘name’])), But not result.

I was also looking for other options but could not get results.

I have a PHP code:

  <?php
  $servername = "localhost";
  $username = "..";
  $password = "..";
  $dbname = "..";

  $conn = new mysqli($servername, $username, $password, $dbname);
  $response = array();
  $posts = array();

  $sql = "SELECT name, addres, status, date  FROM silknet WHERE name='test'";

  $result=mysqli_query($conn,$sql);


  while($row=mysqli_fetch_array($result)) { 
     $name=$row['name']; 
     $addres=$row['addres']; 
     $status=$row['status'];
     $date=$row['date'];

  $response[] = array('name'=> $name, 'addres'=> $addres, 'status'=>$status, 
  'date'=>$date);
  } 

  echo json_encode($response);
  ?> 

sorry – old question again: imagecropauto() not working

I have some simple code:

$original_image = imagecreatefromjpeg($image_path);
$cropped_image =imagecropauto($original_image , IMG_CROP_THRESHOLD, .5, 16777215);
magejpeg($cropped_image, "$destination.cropped.jpg",90);

but this code does not give the desired result. I actually expect that from my $original_image (jpg) the white border will be removed automatically.

This is the Input Image.
enter image description here

Whatever parameters I choose, imagecropauto() always returns the original image and not a cropped image.

Where else can the cause be?

PHP Version 7.3.7 + GD 2.1.0 compatible

LARAVEL: How to fetch id dynamically in a query builder?

I want to join multiple tables in laravel with query builder. My problem is that my code only works if I specify the id myself that I want like this:

 $datauser = DB::table('users')
    ->join('activitates','users.id','=','activitates.user_id')
    ->join('taga_cars','taga_cars.id','=','activitates.tagacar_id')
    ->join('clients','users.id','=','clients.user_id')
    ->where('users.id','=','1')
    ->select('users.*','activitates.*','taga_cars.model','taga_cars.id','clients.name')
    ->get();
    return response()->json($datauser);

But I would want something like this(which I just can’t seem to figure out)

public function showuser($id)
{
$userid = User::findOrFail($id);
    $datauser = DB::table('users')
    ->join('activitates','users.id','=','activitates.user_id')
    ->join('taga_cars','taga_cars.id','=','activitates.tagacar_id')
    ->join('clients','users.id','=','clients.user_id')
    ->where('users.id','=',$userid)
    ->select('users.*','activitates.*','taga_cars.model','taga_cars.id','clients.name')
    ->get();
   
    return response()->json($datauser);
}

Am I making a syntax mistake? When I check the page for my json response in second page it just returns empty brackets, but when I specify the id it fetches me the right data

display WooCommerce “Add to cart” button with short-code [add_to_cart ] dynamically

I use WooCommerce short-code [add_to_cart ] inside a widget sidebar On WordPress website to display “Add to cart” button on product pages (wanted to put the short-code to Custom Field). I understand how to display the button on a specific page using a product “Id” (for example: [add_to_cart id=”1874″ ]), but I wanted to make it that way when it gets Id of a current product page automatically (dynamically) and display “Add to cart” button related to a specific product for each product page. Can someone advise how to do it, please?

Thank you

website as saas in php for different users with different databases

Client demanded a lms system where different users (think it of as an admin of a school branch) has to register and each school will have its own subdomain like (user1.lms.com, user2.lms.com) and each school will have its own database.

like the code will be the same but the user1 will have subdomain like user1.lms.com and will have its own data different than the data of the user2.lms.com

the project is developed in php framework similar to laravel because it has .env file for the environment variables.

XAMPP/SQLSRV: Unable to find Sqlsrv in PHPINFO(); – errors coming from connection

I’ve been killing my brain over this for a few hours while I was running into another issue, I feel the answer is so simple but I’ve been unable to solve it.

I’m attempting to connect into a SQL Server DB I have hosted on my Linux VM. I’m running xampp on my development windows machine and the connection is coming from a php site I’m building. I figured I’d need to use sqlsrv to connect in. I downloaded the dll’s from https://docs.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15&viewFallbackFrom=sql-server-2019

I’ve moved the necessary dll files to my xamppphpetc directory. I’ve also verified the extension directory in the php.ini file is extension_dir="C:xamppphpext"

The following have been added to the Dynamic Extensions section of the php.ini:

extension=php_sqlsrv_81_ts_x86.dll
extension=php_pdo_sqlsrv_81_ts_x86.dll
extension=php8ts.dll

I’ve found info online about removing the php_ prefix, removing the .dll suffix, using ts or non ts, moving all files into the extensions directory, moving only the couple listed above into the directory, not including php8ts.dll, etc. I’ve tried every configuration of the above, both logical and illogical.

Here’s a sample connection code for my site:

$conn = new PDO('sqlsrv:Server=my_server_ip\MSSQLSERVER;Database=dbname', 'username', 'password');
if ($conn === false) {
    echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
    exit;
} else {
    echo "success";
}

I’ve tried multiple different connection examples. With the one above, I receive this error:

Fatal error: Uncaught PDOException: could not find driver in C:xampphtdocssiteindex.php:123 Stack trace: #0 C:xampphtdocssiteindex.php(123): PDO->__construct('sqlsrv:Server=my_server_ip', 'username', 'password') #1 {main} thrown in C:xampphtdocssiteindex.php on line 123

From here I logically thought okay, let’s check phpinfo(); by echoing it. There is nothing at all listed for sqlsrv or the PDO variant anywhere on the list. Even ctrl+f on the page for sqlsrv, the only thing that is found is the error above.

I have verified I have the ODBC drivers installed.

enter image description here

The other things I’ve tried was to use sqlsrv_connect instead of PDO. I found conflicting information on this working for my php version (8.1), but figured what the hell, let’s try it anyways. However when I run into that variant, I get:

Fatal error: Call to undefined function sqlsrv_connect()

It seems obvious to me my .dlls are not being recognized or something of the sort. However I cannot for the life of me understand why. I’ve verified everything is ran as admin, restarted xampp multiple times, removed/redownloaded the dlls, etc.

Can anyone point out any glaring problems I may not be thinking of?

SQL that works in MySQL that doesn’t work in PHP

I have done an SQL query that works when I query the database directly:

SELECT COUNT(*) FROM tickets where created = “2022-05-11 13:10:03”

This returns 1 as it should.

In my PHP code that date is stored in a variable so it’s:

SELECT COUNT(*) FROM tickets where created = “$finaldate”

This just returns 0 all the time.

I have checked and when I echo $finaldate it shows 2022-05-11 13:10:03 so I know that is right.

Any ideas?

Thanks.

javascript function inside another function isn’t working

Currenty i’m working on php dynamic row but i need to change satuanbahan value based on id_bahan dropdown but it isn’t working inside the addrow function. The satuanbahan wont show it’s value. Is there any ways to make it work

$(document).ready(function () {

var counter = 0;

$("#addrow").on("click", function () {

    var newRow = $("<tr> id='row"+ counter +"'");
    var cols = "";

    cols += '<td><select name="id_bahan[]" id="id_bahan" class="form-control"><option value="-" selected="selected">-</option><?php
                        $q=mysqli_query($conn,"SELECT id_bahan, nama,satuan FROM tblbahan group by id_bahan ORDER BY id_bahan asc");
                        while($data2=mysqli_fetch_array($q)) {
                      
                      echo '<option value="'.$data2[0].'" data-satuan="'.$data2[2] .'">'. $data2[1]. '</option>';
                      
                      }
                      ?>
                  </select></td>';
    cols += '<td><input type="number" name="takaran[]" value="" id="takaran" class="form-control"/></td>';
    cols += '<td><input type="text" name="satuanbahan" value="" id="satuanbahan" class="form-control" readonly="true"/></td>';

    cols += '<td><a type="button" class="ibtnDel btn btn-md btn-danger "><i class="fas fa-fw fa-trash"></i></a></td>';
    newRow.append(cols);
    $("table.order-list").append(newRow);
    counter++;

    $('#id_bahan').change(function() {
        selectedOption = $('option:selected', this);
        $("#satuanbahan").val( selectedOption.data('satuan') );
    });


});