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
Nikita
NA
56
10.1k
inserting multiple values to database
Jan 2 2020 5:00 AM
Warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in D:\xampp\htdocs\punegurukulfinal\registration.php on line 16
HTML CODE
<!DOCTYPE html>
<html>
<head>
<meta name=
"viewport"
content=
"width=device-width, initial-scale=1"
/>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: black;
}
* {
box-sizing: border-box;
}
/* Add padding to containers */
.container {
padding: 16px;
background-color: white;
}
/* Full-width input fields */
input[type=
"text"
],
input[type=
"text"
] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
input[type=
"text"
]:focus,
input[type=
"text"
]:focus {
background-color: #ddd;
outline: none;
}
/* Overwrite default styles of hr */
hr {
border: 1px solid #f1f1f1;
margin-bottom: 25px;
}
/* Set a style for the submit button */
.registerbtn {
background-color: #4caf50;
color: white;
padding: 16px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
}
.registerbtn:hover {
opacity: 1;
}
/* Add a blue text color to links */
a {
color: dodgerblue;
}
/* Set a grey background color and center the text of the "sign in" section */
.signin {
background-color: #f1f1f1;
text-align: center;
}
</style>
</head>
<body>
<form action=
"registration.php"
>
<div
class
=
"container"
>
<div
class
=
"row"
>
<h1>Register</h1>
<p>Please fill
in
this
form to create an account.</p>
<hr />
<label
for
=
"fname"
><b>First Name</b></label>
<input
type=
"text"
placeholder=
"Enter First Name"
name=
"First_Name"
required/>
<label
for
=
"lname"
><b>Last Name</b></label>
<input
type=
"text"
placeholder=
"Enter Password"
name=
"Last_Name"
required/>
<label
for
=
"Mobile"
><b>Mobile</b></label>
<input
type=
"text"
placeholder=
"Enter Mobile"
name=
"mobile"
required/>
<label
for
=
"email"
><b>Email</b></label>
<input type=
"text"
placeholder=
"Enter Email"
name=
"email"
required/>
<label
for
=
"training"
><b>Training</b></label><br />
<input type=
"checkbox"
name=
"Training[]"
value=
"it"
/> IT and Yoga
Training<br />
<input
type=
"checkbox"
name=
"Training[]"
value=
"technology"
/>Technology Training<br />
<input
type=
"checkbox"
name=
"Training[]"
value=
"Meditation"
checked/>Meditation
<p>
By creating an account you agree to our
<a href=
"#"
>Terms & Privacy</a>.
</p>
<button type=
"submit"
class
=
"registerbtn"
name=
"submit1"
>
Register
</button>
</div>
<div
class
=
"container signin"
>
<p>Already have an account? <a href=
"#"
>Sign
in
</a>.</p>
</div>
</div>
</form>
</body>
</html>
PHP CODE
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link
= mysqli_connect(
"localhost"
,
"root"
,
""
,
"punegurukul"
);
// Check connection
if
(
$link
=== false){
die
(
"ERROR: Could not connect. "
. mysqli_connect_error());
}
// Escape user inputs for security
$First_Name
= mysqli_real_escape_string(
$link
,
$_REQUEST
[
'First_Name'
]);
$Last_Name
= mysqli_real_escape_string(
$link
,
$_REQUEST
[
'Last_Name'
]);
$mobile
= mysqli_real_escape_string(
$link
,
$_REQUEST
[
'mobile'
]);
$email
= mysqli_real_escape_string(
$link
,
$_REQUEST
[
'email'
]);
$Training
= mysqli_real_escape_string(
$link
,
$_REQUEST
[
'Training'
]);
//code for checkbox values
if
(isset(
$_POST
[
"submit1"
]))
{
if
(!
empty
empty
(
$_POST
[
"Training"
]))
{
echo
'<h3>Please select atlest one training'
;
foreach
(
$_POST
[
"Training"
]
as
$Training
)
{
echo
'<p>'
.
$Training
.
'</p>'
;
}
}
else
{
echo
"please select atleast one training"
;
}
}
// Attempt insert query execution
$sql
=
"INSERT INTO studentreg (First_Name, Last_Name, Mobile, Email, Training) VALUES ('$First_Name', '$Last_Name', '$mobile','$email','$Training')"
;
if
(mysqli_query(
$link
,
$sql
)){
echo
"Records added successfully."
;
}
else
{
echo
"ERROR: Could not able to execute $sql. "
. mysqli_error(
$link
);
}
// Close connection
mysqli_close(
$link
);
?>
PLEASE solve my problem.
I want to insert checkbox multiple values in database.
Reply
Answers (
1
)
Doent insert into DB. Why?
ical to google calendar sync api in php codeigniter