Rectangle 27 0

<button onclick="location.href='<?php echo site_url('Search_Student_Ctrl/index');?>'">Search Student</button>

For calling controllers from view you have to use site_url() instead of base_url()

php - CodeIgniter button onclick(), page redirect issue - Stack Overfl...

php codeigniter codeigniter-2 codeigniter-url
Rectangle 27 0

<button onclick="location.href='<?php echo site_url('Search_Student_Ctrl/index');?>'">Search Student</button>

For calling controllers from view you have to use site_url() instead of base_url()

php - CodeIgniter button onclick(), page redirect issue - Stack Overfl...

php codeigniter codeigniter-2 codeigniter-url
Rectangle 27 0

$(document).on('click','.unique',function(){
        var id=$(this).val();
        $.ajax({
            type: "POST",
            context: "application/json",
            data: {id:id},
            url: "http://localhost/index.php/fetch_country/index",
            success: function(msg){
                alert(msg);
            }
        });
    });

public function fetch() {
    $id=$this->input->post('id');
    echo $id;
}

php - Not able to pass value to controller onclick checkbox codeignite...

php jquery ajax codeigniter codeigniter-2
Rectangle 27 0

<a data-toggle="modal" data-target="#Add_Money_to_campaign" ><input type="submit" value="Add" onclick="addId(<?php echo $id;?>);" /></a>
function addId(id){
   var id = id
   alert(id);
   $.ajax({
    type: "post",
    url: "<?php echo base_url('controller/function');?>",
    data: {id:id},
    cache: false,
    async: false,
    success: function(result){
            console.log(result); 
        }
    });

}
$id= $this->input->post('id');
 echo $id; 
 $this->model->function($id);// you might have error over here you need to specify your model_name as my_model

Whats the error 500 internal error then check your parameters name instead. From where you are getting value of $id is it an array or you are passing it within foreach loop and are you getting id value within ajax @pawan

i am getting the value on alert, i want to use this value in my where clause to update my database, so i need it as an int value.

So it means atleast we are correct within halfway now try to echo value within controller and check are you getting value over there or not and within PHP you can check with is_numeric function as if(is_numeric($id)){// your code}

php - pass value from view to controller in codeigniter using onclick ...

php jquery ajax codeigniter
Rectangle 27 0

you are calling a javascript function on click event... but you don't have any function in the posted question..

anyways i don't think you need javascript function you can just pass id as parameter in url

<td><?php echo anchor('dbcont/deleteinput/'.$row->member_id, 'Delete'); ?></td>
function deleteinput($id)
{
        $this->load->helper('form');
        $this->load->helper('html');
        $this->load->model('user');
        $this->user->deletedata($id);
        redirect('home');
}

you don't need to get() and select anything in you controler..this is models code...and you are already doing that in your deletedata function..

$this->db->delete() => The first parameter is the table name, the second is the where clause. You can also use the where() or or_where() functions instead of passing the data to the second parameter of the function.

it shows the member_id in url but not delete any row . .

not give any error but still not delete any row @bipen

ok.. echo $id;exit; in first line of deleteinput($id) function .. and check if you are gettin the id or not..

yeah i am getting the id . .

php - get row id of mysql database into onclick function and pass to f...

php mysql codeigniter phpmyadmin
Rectangle 27 0

There could be a few reasons for it:

  • it might be because you are working on a local environment and didn't set a host in the hosts file so the base_url cannot be found by Codeigniter (see 3. or set a local host)
$this->load->helper('url');
  • if all of the above still don't work you should configure the base_url in your config.php: $config['base_url'] = '';

Codeigniter should be able to detect your BASE_URL, in case you are working on a local enviornment and accessing the enviroment using IP/localhost for example. it might not return any url. you can add "virtualhost" to your local enviornment. for example to access your local enviorment using url like: local.example.com you could read more about how to set virtualhost here (its for Ubuntu and Apache but the concept is the same): digitalocean.com/community/tutorials/

about the 3rd point if you don't want to create a virtualhost you could just explictly define your base url in the Config.php file for example: $config['base_url'] = 'http://localhost';

php - CodeIgniter button onclick(), page redirect issue - Stack Overfl...

php codeigniter codeigniter-2 codeigniter-url
Rectangle 27 0

function addId(id) {
            var dataString = id
            var dataSend = {
                dataString: dataString
            };
            $.ajax({
                type: "post",
                url: "<?php echo base_url(); ?>/index.php/controller/function",
                method: "POST",
                data: dataSend,
                cache: false,
                success: function(data) { 
                    alert(data);    
                }
            });
        }
$data = $this->input->post("dataString");

thank you for your reply but stilll no luck...

php - pass value from view to controller in codeigniter using onclick ...

php jquery ajax codeigniter
Rectangle 27 0

onClick isn't necessary, nor really advised with jQuery, just set the two paths as separate classes in the link, then retrieve the classes in the links on click function and pass them to your ajax calls.

<a href="#" id=\"mnu_btn_user_accounts\" class="link '.$arLeftMenuList[$key]['FormCIPath'].' '.$otherPath">Click Me</a>


<script type='text/javascript' language='javascript'>
    $(".link").on("click", function(){
        var url1 = <?=base_url()."index.php";> + $(this).attr('class').split(' ')[1];
        var url2 = <?=base_url()."index.php";> + $(this).attr('class').split(' ')[2];
        loadmenu(url1, url2)
    {
    function loadmenu(url1, url2){
        $.ajax({
            type: "POST",
            url: url1,    
            success: function(output_string){    
                $('.second_column_content_container').html(output_string);    
            }    
        });
        $.ajax({
            type: "POST",
            url: url2,    
            success: function(output_string){    
                $('.other_content_div').html(output_string);    
            }    
        });
}
</script>

php - CodeIgniter Load Two views on a single onclick function - Stack ...

php codeigniter jquery
Rectangle 27 0

<td><a href="javascript:delete_member(<?php echo $row->member_id  ?>) > Delete</a></td>

And in the same view file write JavaScript function like this.......

function delete_membet(member_id){
       window.location.href = "<?php echo ROOT_FOLDER ?>/controller_name/delete/" +member_id ;
 }

Then in the controller file write a function like this below....

public function delete($member_id)

 {

        $this->model_file->delete($member_id);

        redirect('home');

  }

In the model file write a function like this.........

public function delete($member_id)

     {
         $query = "delete from members where member_id = $member_id";

            $res = $this->db->query($query);
      }

sorry its not working . .

what is the error you are getting?

what is there in line number66

php - get row id of mysql database into onclick function and pass to f...

php mysql codeigniter phpmyadmin
Rectangle 27 0

<a href="javascript:void(0);" onclick="deleteinput(<?php echo $row->member_id;?>);">delete</a>

Use this in your javascript

<script type="text/javascript">
var url="<?php echo base_url();?>";

    function delete(id){ 
        if (confirm("Do you want to delete?"))
          window.location = url+"dbcont/deleteinput/"+id;
        else
          return false;
}
</script>
public function deleteinput($id){
     $this->load->model('user');
     $this->user->deletedata($id);
     redirect('home');

}
function deletedata($id){
        $this->db->where('id', $id);
        if($this->db->delete('tbl_members'))
           return true;
        else
           return false;
    }

not work @Rahul Chipad

php - get row id of mysql database into onclick function and pass to f...

php mysql codeigniter phpmyadmin
Rectangle 27 0

Try this dirty code and change as per your requirements:

<div id="notification_counter"><?php echo $note; ?></div>
<div id="notification_container">
         <ul>
                <li class= "notification_heading" onClick="read_notification_url">one</li>
                <li class= "notification_heading" onClick="read_notification_url">two</li>
                <li class= "notification_heading" onClick="read_notification_url">three</li>                
         </ul>
</div>

<script>
$(function() {
        $(".notification_heading").click( function(){
                 var rquest = $.ajax({
                            type: "POST",
                            url: "url_to_modify_counter",
                          });
                          rquest.done(function( msg ) {                              
                                $('#notification_counter').val($('#notification_counter').val()-1);
                              }
              });
          });
</script>

be sure to make it safe and data type conversion and all security checks

php - Codeigniter query (Update) database onclick - Stack Overflow

php jquery ajax codeigniter
Rectangle 27 0

onClick="changeDiv(<?php echo $id; ?>)">
onClick="changeDiv(\''. $id .'\')">

passing a php variable to an onclick function in codeigniter - Stack O...

php codeigniter
Rectangle 27 0

There could be a few reasons for it:

  • it might be because you are working on a local environment and didn't set a host in the hosts file so the base_url cannot be found by Codeigniter (see 3. or set a local host)
$this->load->helper('url');
  • if all of the above still don't work you should configure the base_url in your config.php: $config['base_url'] = '';

Codeigniter should be able to detect your BASE_URL, in case you are working on a local enviornment and accessing the enviroment using IP/localhost for example. it might not return any url. you can add "virtualhost" to your local enviornment. for example to access your local enviorment using url like: local.example.com you could read more about how to set virtualhost here (its for Ubuntu and Apache but the concept is the same): digitalocean.com/community/tutorials/

about the 3rd point if you don't want to create a virtualhost you could just explictly define your base url in the Config.php file for example: $config['base_url'] = 'http://localhost';

php - CodeIgniter button onclick(), page redirect issue - Stack Overfl...

php codeigniter codeigniter-2 codeigniter-url