TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
karthika pommudu
NA
321
34.5k
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.
<html>
<head>
<link rel=
"stylesheet"
href=
"//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"
>
<link rel=
"stylesheet"
href=
"bootstrap.min.css"
/>
<script src=
"https://code.jquery.com/jquery-1.12.4.js"
></script>
<script src=
"https://code.jquery.com/ui/1.12.1/jquery-ui.js"
></script>
</head>
<body>
<div
class
=
"container"
>
<br />
<br />
<br />
<div align=
"right"
style=
"margin-bottom:5px;"
>
<button type=
"button"
name=
"add"
id=
"add"
class
=
"btn btn-success btn-xs"
>Add</button>
</div>
<br />
<form method=
"post"
id=
"user_form"
>
<div
class
=
"table-responsive"
>
<table
class
=
"table table-striped table-bordered"
id=
"user_data"
>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Details</th>
<th>Remove</th>
</tr>
</table>
</div>
<div align=
"center"
>
<input type=
"submit"
name=
"insert"
id=
"insert"
class
=
"btn btn-primary"
value=
"Insert"
/>
</div>
</form>
<br />
</div>
<div id=
"user_dialog"
title=
"Add Data"
>
<div
class
=
"form-group"
>
<label>Enter First Name</label>
<input type=
"text"
name=
"first_name"
id=
"first_name"
class
=
"form-control"
/>
<span id=
"error_first_name"
class
=
"text-danger"
></span>
</div>
<div
class
=
"form-group"
>
<label>Enter Last Name</label>
<input type=
"text"
name=
"last_name"
id=
"last_name"
class
=
"form-control"
/>
<span id=
"error_last_name"
class
=
"text-danger"
></span>
</div>
<div
class
=
"form-group"
align=
"center"
>
<input type=
"hidden"
name=
"row_id"
id=
"hidden_row_id"
/>
<button type=
"button"
name=
"save"
id=
"save"
class
=
"btn btn-info"
>Save</button>
</div>
</div>
<div id=
"action_alert"
title=
"Action"
>
</div>
</body>
</html>
<script>
$(document).ready(
function
(){
var
count = 0;
$(
'#user_dialog'
).dialog({
autoOpen:
false
,
width:800
});
$(
'#add'
).click(
function
(){
$(
'#user_dialog'
).dialog(
'option'
,
'title'
,
'Add Data'
);
$(
'#first_name'
).val(
''
);
$(
'#last_name'
).val(
''
);
$(
'#error_first_name'
).text(
''
);
$(
'#error_last_name'
).text(
''
);
$(
'#first_name'
).css(
'border-color'
,
''
);
$(
'#last_name'
).css(
'border-color'
,
''
);
$(
'#save'
).text(
'Save'
);
$(
'#user_dialog'
).dialog(
'open'
);
});
$(
'#save'
).click(
function
(){
var
error_first_name =
''
;
var
error_last_name =
''
;
var
first_name =
''
;
var
last_name =
''
;
if
($(
'#first_name'
).val() ==
''
)
{
error_first_name =
'First Name is required'
;
$(
'#error_first_name'
).text(error_first_name);
$(
'#first_name'
).css(
'border-color'
,
'#cc0000'
);
first_name =
''
;
}
else
{
error_first_name =
''
;
$(
'#error_first_name'
).text(error_first_name);
$(
'#first_name'
).css(
'border-color'
,
''
);
first_name = $(
'#first_name'
).val();
}
if
($(
'#last_name'
).val() ==
''
)
{
error_last_name =
'Last Name is required'
;
$(
'#error_last_name'
).text(error_last_name);
$(
'#last_name'
).css(
'border-color'
,
'#cc0000'
);
last_name =
''
;
}
else
{
error_last_name =
''
;
$(
'#error_last_name'
).text(error_last_name);
$(
'#last_name'
).css(
'border-color'
,
''
);
last_name = $(
'#last_name'
).val();
}
if
(error_first_name !=
''
|| error_last_name !=
''
)
{
return
false
;
}
else
{
if
($(
'#save'
).text() ==
'Save'
)
{
count = count + 1;
output =
'<tr id="row_'
+count+
'">'
;
output +=
'<td>'
+first_name+
' <input type="hidden" name="hidden_first_name[]" id="first_name'
+count+
'" class="first_name" value="'
+first_name+
'" /></td>'
;
output +=
'<td>'
+last_name+
' <input type="hidden" name="hidden_last_name[]" id="last_name'
+count+
'" value="'
+last_name+
'" /></td>'
;
output +=
'<td><button type="button" name="view_details" class="btn btn-warning btn-xs view_details" id="'
+count+
'">View</button></td>'
;
output +=
'<td><button type="button" name="remove_details" class="btn btn-danger btn-xs remove_details" id="'
+count+
'">Remove</button></td>'
;
output +=
'</tr>'
;
$(
'#user_data'
).append(output);
}
else
{
var
row_id = $(
'#hidden_row_id'
).val();
output =
'<td>'
+first_name+
' <input type="hidden" name="hidden_first_name[]" id="first_name'
+row_id+
'" class="first_name" value="'
+first_name+
'" /></td>'
;
output +=
'<td>'
+last_name+
' <input type="hidden" name="hidden_last_name[]" id="last_name'
+row_id+
'" value="'
+last_name+
'" /></td>'
;
output +=
'<td><button type="button" name="view_details" class="btn btn-warning btn-xs view_details" id="'
+row_id+
'">View</button></td>'
;
output +=
'<td><button type="button" name="remove_details" class="btn btn-danger btn-xs remove_details" id="'
+row_id+
'">Remove</button></td>'
;
$(
'#row_'
+row_id+
''
).html(output);
}
$(
'#user_dialog'
).dialog(
'close'
);
}
});
$(document).on(
'click'
,
'.view_details'
,
function
(){
var
row_id = $(
this
).attr(
"id"
);
var
first_name = $(
'#first_name'
+row_id+
''
).val();
var
last_name = $(
'#last_name'
+row_id+
''
).val();
$(
'#first_name'
).val(first_name);
$(
'#last_name'
).val(last_name);
$(
'#save'
).text(
'Edit'
);
$(
'#hidden_row_id'
).val(row_id);
$(
'#user_dialog'
).dialog(
'option'
,
'title'
,
'Edit Data'
);
$(
'#user_dialog'
).dialog(
'open'
);
});
$(document).on(
'click'
,
'.remove_details'
,
function
(){
var
row_id = $(
this
).attr(
"id"
);
if
(confirm(
"Are you sure you want to remove this row data?"
))
{
$(
'#row_'
+row_id+
''
).remove();
}
else
{
return
false
;
}
});
$(
'#action_alert'
).dialog({
autoOpen:
false
});
$(
'#user_form'
).on(
'submit'
,
function
(event){
event.preventDefault();
var
count_data = 0;
$(
'.first_name'
).each(
function
(){
count_data = count_data + 1;
});
if
(count_data > 0)
{
var
form_data = $(
this
).serialize();
$.ajax({
url:
"insert.php"
,
method:
"POST"
,
data:form_data,
success:
function
(data)
{
$(
'#user_data'
).find(
"tr:gt(0)"
).remove();
$(
'#action_alert'
).html(
'<p>Data Inserted Successfully</p>'
);
$(
'#action_alert'
).dialog(
'open'
);
}
})
}
else
{
$(
'#action_alert'
).html(
'<p>Please Add atleast one data</p>'
);
$(
'#action_alert'
).dialog(
'open'
);
}
});
});
</script>
require_once
"dbconnect.php"
;
//$query = "INSERT INTO internship (first_name, last_name) VALUES (:first_name, :last_name)";
for
(
$count
= 0;
$count
<
count
(
$_POST
[
'hidden_first_name'
]);
$count
++)
{
$data
=
array
(
$first_name
=
$_POST
[
'hidden_first_name'
][
$count
],
$last_name
=
$_POST
[
'hidden_last_name'
][
$count
]
);
if
(
$first_name
!=
''
)
{
echo
"HI"
.
$first_name
;
echo
$last_name
;
$result1
=
$link
->query(
"INSERT INTO internship(`first_name`, `last_name`) VALUES (`$first_name`, `$last_name`)"
);
$result1
->bind_param(
'i'
,
$first_name
);
// error here
$result1
->execute();
if
(
$result1
)
{
echo
"Successfully"
;
}
else
{
echo
"Failed"
;
}
/* $statement = $link->prepare("INSERT INTO internship (`id`,`first_name`, `last_name`) VALUES (``,`$first_name`, `$last_name`)");
//$statement->bind_param("s", $hidden_first_name);
$result = $statement->execute(); */
}
else
{
echo
"I dont know you."
;
}
}
Reply
Answers (
4
)
How i can fetch vimeo videos in my website using vimeo API?
While loop values pass to php update query by submit button