karthika pommudu

karthika pommudu

  • NA
  • 321
  • 35k

Fatal error: Call to a member function bind_param() on boolean

Jul 22 2020 1:09 AM
Have a good day:)
 
I tried to insert the value via ajax to php but I receive the error (as mentioned yellow highlighting part),kinldy help me to clear this.
  1. <html>      
  2.     <head>      
  3.             
  4.         <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">    
  5.         <link rel="stylesheet" href="bootstrap.min.css" />    
  6.         <script src="https://code.jquery.com/jquery-1.12.4.js"></script>    
  7.         <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>    
  8.     </head>      
  9.     <body>      
  10.         <div class="container">    
  11.             <br />    
  12.                 
  13.                 
  14.             <br />    
  15.             <br />    
  16.             <div align="right" style="margin-bottom:5px;">    
  17.                 <button type="button" name="add" id="add" class="btn btn-success btn-xs">Add</button>    
  18.             </div>    
  19.             <br />    
  20.             <form method="post" id="user_form">    
  21.                 <div class="table-responsive">    
  22.                     <table class="table table-striped table-bordered" id="user_data">    
  23.                         <tr>    
  24.                             <th>First Name</th>    
  25.                             <th>Last Name</th>    
  26.                             <th>Details</th>    
  27.                             <th>Remove</th>    
  28.                         </tr>    
  29.                     </table>    
  30.                 </div>    
  31.                 <div align="center">    
  32.                     <input type="submit" name="insert" id="insert" class="btn btn-primary" value="Insert" />    
  33.                 </div>    
  34.             </form>    
  35.     
  36.             <br />    
  37.         </div>    
  38.         <div id="user_dialog" title="Add Data">    
  39.             <div class="form-group">    
  40.                 <label>Enter First Name</label>    
  41.                 <input type="text" name="first_name" id="first_name" class="form-control" />    
  42.                 <span id="error_first_name" class="text-danger"></span>    
  43.             </div>    
  44.             <div class="form-group">    
  45.                 <label>Enter Last Name</label>    
  46.                 <input type="text" name="last_name" id="last_name" class="form-control" />    
  47.                 <span id="error_last_name" class="text-danger"></span>    
  48.             </div>    
  49.             <div class="form-group" align="center">    
  50.                 <input type="hidden" name="row_id" id="hidden_row_id" />    
  51.                 <button type="button" name="save" id="save" class="btn btn-info">Save</button>    
  52.             </div>    
  53.         </div>    
  54.         <div id="action_alert" title="Action">    
  55.     
  56.         </div>    
  57.     </body>      
  58. </html>  
  1. <script>      
  2. $(document).ready(function(){     
  3.         
  4.     var count = 0;    
  5.     
  6.     $('#user_dialog').dialog({    
  7.         autoOpen:false,    
  8.         width:800    
  9.     });    
  10.     
  11.     $('#add').click(function(){    
  12.         $('#user_dialog').dialog('option''title''Add Data');    
  13.         $('#first_name').val('');    
  14.         $('#last_name').val('');    
  15.         $('#error_first_name').text('');    
  16.         $('#error_last_name').text('');    
  17.         $('#first_name').css('border-color''');    
  18.         $('#last_name').css('border-color''');    
  19.         $('#save').text('Save');    
  20.         $('#user_dialog').dialog('open');    
  21.     });    
  22.     
  23.     $('#save').click(function(){    
  24.         var error_first_name = '';    
  25.         var error_last_name = '';    
  26.         var first_name = '';    
  27.         var last_name = '';    
  28.         if($('#first_name').val() == '')    
  29.         {    
  30.             error_first_name = 'First Name is required';    
  31.             $('#error_first_name').text(error_first_name);    
  32.             $('#first_name').css('border-color''#cc0000');    
  33.             first_name = '';    
  34.         }    
  35.         else    
  36.         {    
  37.             error_first_name = '';    
  38.             $('#error_first_name').text(error_first_name);    
  39.             $('#first_name').css('border-color''');    
  40.             first_name = $('#first_name').val();    
  41.         }       
  42.         if($('#last_name').val() == '')    
  43.         {    
  44.             error_last_name = 'Last Name is required';    
  45.             $('#error_last_name').text(error_last_name);    
  46.             $('#last_name').css('border-color''#cc0000');    
  47.             last_name = '';    
  48.         }    
  49.         else    
  50.         {    
  51.             error_last_name = '';    
  52.             $('#error_last_name').text(error_last_name);    
  53.             $('#last_name').css('border-color''');    
  54.             last_name = $('#last_name').val();    
  55.         }    
  56.         if(error_first_name != '' || error_last_name != '')    
  57.         {    
  58.             return false;    
  59.         }    
  60.         else    
  61.         {    
  62.             if($('#save').text() == 'Save')    
  63.             {    
  64.                 count = count + 1;    
  65.                 output = '<tr id="row_'+count+'">';    
  66.                 output += '<td>'+first_name+' <input type="hidden" name="hidden_first_name[]" id="first_name'+count+'" class="first_name" value="'+first_name+'" /></td>';    
  67.                 output += '<td>'+last_name+' <input type="hidden" name="hidden_last_name[]" id="last_name'+count+'" value="'+last_name+'" /></td>';    
  68.                 output += '<td><button type="button" name="view_details" class="btn btn-warning btn-xs view_details" id="'+count+'">View</button></td>';    
  69.                 output += '<td><button type="button" name="remove_details" class="btn btn-danger btn-xs remove_details" id="'+count+'">Remove</button></td>';    
  70.                 output += '</tr>';    
  71.                 $('#user_data').append(output);    
  72.             }    
  73.             else    
  74.             {    
  75.                 var row_id = $('#hidden_row_id').val();    
  76.                 output = '<td>'+first_name+' <input type="hidden" name="hidden_first_name[]" id="first_name'+row_id+'" class="first_name" value="'+first_name+'" /></td>';    
  77.                 output += '<td>'+last_name+' <input type="hidden" name="hidden_last_name[]" id="last_name'+row_id+'" value="'+last_name+'" /></td>';    
  78.                 output += '<td><button type="button" name="view_details" class="btn btn-warning btn-xs view_details" id="'+row_id+'">View</button></td>';    
  79.                 output += '<td><button type="button" name="remove_details" class="btn btn-danger btn-xs remove_details" id="'+row_id+'">Remove</button></td>';    
  80.                 $('#row_'+row_id+'').html(output);    
  81.             }    
  82.     
  83.             $('#user_dialog').dialog('close');    
  84.         }    
  85.     });    
  86.     
  87.     $(document).on('click''.view_details'function(){    
  88.         var row_id = $(this).attr("id");    
  89.         var first_name = $('#first_name'+row_id+'').val();    
  90.         var last_name = $('#last_name'+row_id+'').val();    
  91.         $('#first_name').val(first_name);    
  92.         $('#last_name').val(last_name);    
  93.         $('#save').text('Edit');    
  94.         $('#hidden_row_id').val(row_id);    
  95.         $('#user_dialog').dialog('option''title''Edit Data');    
  96.         $('#user_dialog').dialog('open');    
  97.     });    
  98.     
  99.     $(document).on('click''.remove_details'function(){    
  100.         var row_id = $(this).attr("id");    
  101.         if(confirm("Are you sure you want to remove this row data?"))    
  102.         {    
  103.             $('#row_'+row_id+'').remove();    
  104.         }    
  105.         else    
  106.         {    
  107.             return false;    
  108.         }    
  109.     });    
  110.     
  111.     $('#action_alert').dialog({    
  112.         autoOpen:false    
  113.     });    
  114.     
  115.     $('#user_form').on('submit'function(event){    
  116.         event.preventDefault();    
  117.         var count_data = 0;    
  118.         $('.first_name').each(function(){    
  119.             count_data = count_data + 1;    
  120.         });    
  121.         if(count_data > 0)    
  122.         {    
  123.             var form_data = $(this).serialize();    
  124.             $.ajax({    
  125.                 url:"insert.php",    
  126.                 method:"POST",    
  127.                 data:form_data,    
  128.                 success:function(data)    
  129.                 {    
  130.                     $('#user_data').find("tr:gt(0)").remove();    
  131.                     $('#action_alert').html('<p>Data Inserted Successfully</p>');    
  132.                     $('#action_alert').dialog('open');    
  133.                 }    
  134.             })    
  135.         }    
  136.         else    
  137.         {    
  138.             $('#action_alert').html('<p>Please Add atleast one data</p>');    
  139.             $('#action_alert').dialog('open');    
  140.         }    
  141.     });    
  142.         
  143. });      
  144. </script>   
  1. require_once "dbconnect.php";    
  2.     
  3. //$query = "INSERT INTO internship (first_name, last_name) VALUES (:first_name, :last_name)";    
  4.     
  5.     
  6. for($count = 0; $count<count($_POST['hidden_first_name']); $count++)    
  7. {    
  8.  $data = array    
  9.  (    
  10.  $first_name=$_POST['hidden_first_name'][$count],    
  11.  $last_name=$_POST['hidden_last_name'][$count]    
  12.  );     
  13.      
  14. if($first_name!='')    
  15. {    
  16.   echo "HI".$first_name;      
  17.   echo $last_name;      
  18.         
  19. $result1=$link->query("INSERT INTO internship(`first_name`, `last_name`) VALUES (`$first_name`, `$last_name`)");    
  20. $result1->bind_param('i'$first_name); // error here   
  21. $result1->execute();    
  22.     
  23. if ($result1)     
  24.    {    
  25.     echo "Successfully";    
  26.     }    
  27.     else    
  28.     {    
  29.     echo "Failed";    
  30.     }       
  31. /* $statement = $link->prepare("INSERT INTO internship (`id`,`first_name`, `last_name`) VALUES (``,`$first_name`, `$last_name`)");  
  32. //$statement->bind_param("s", $hidden_first_name);  
  33. $result = $statement->execute(); */    
  34.         
  35. }    
  36. else    
  37. {    
  38.     echo "I dont know you.";        
  39. }    
  40. }

Answers (4)