Save Bootstrap Form Helpers Country picker to my database - php

I have used Bootstrap-Form-Helpers to display the countries and the flags through a drop down box. I have used the following Html,
<div class="bfh-selectbox bfh-countries" data-country="US" data-flags="true">
<input type="hidden" value="">
<a class="bfh-selectbox-toggle" role="button" data-toggle="bfh-selectbox" href="#">
<span class="bfh-selectbox-option input-medium" data-option=""></span>
<b class="caret"></b>
</a>
<div class="bfh-selectbox-options">
<input type="text" class="bfh-selectbox-filter" name="country">
<div role="listbox">
<ul role="option">
</ul>
</div>
</div>
</div>
The PHP code to save to the database is
if (isset($_POST['btn_signup'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$username = $_POST['username'];
$pass = $_POST['password'];
$cpass = $_POST['conf_pass'];
$country = $_POST['country'];
$dropdown = $_POST['dropdown'];
$query3 = "SELECT * from tbl_users WHERE email = '" . $email . "'";
$result3 = mysql_query($query3, $con) or die(mysql_error());
$query = "SELECT * from tbl_users WHERE username = '" . $username . "'";
$result = mysql_query($query, $con) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
echo '<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">';
echo '<div class="alert alert-danger alert-dismissable">';
echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
echo 'Username is not available! Please Try another username!!.' . mysql_error();
echo '</div>';
echo '</div>';
}
elseif ($pass != $cpass) {
echo '<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">';
echo '<div class="alert alert-danger alert-dismissable">';
echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
echo 'Password typed doesnt match please retype the password correctly!!.' . mysql_error();
echo '</div>';
echo '</div>';
}
elseif (mysql_num_rows($result3) > 0) {
echo '<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">';
echo '<div class="alert alert-danger alert-dismissable">';
echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
echo 'Email Already exist please try another email!!.' . mysql_error();
echo '</div>';
echo '</div>';
}
else {
$query2 = "INSERT INTO tbl_users (first_name,last_name,username,password,confPass,email,country,user_type)VALUES('{$fname}','{$lname}','{$username}','{$pass}','{$cpass}','{$email}','{$country}','{$dropdown}')";
$result2 = mysql_query($query2);
echo '<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">';
echo '<div class="alert alert-success alert-dismissable">';
echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
echo 'Success! Well done its submitted.';
echo '</div>';
echo '</div>';
}
}
All my other data is entered to my database. But not the country.
Please help!!

You can use data-name="country" in below div tag. Then you can get in selected country in the $_POST.
<div class="bfh-selectbox bfh-countries" data-country="US" data-name="country" data-flags="true"> ..............remaining code here.............. </div>
$country = $_POST['country'];
Let me know if this help.
Thanks

The input field your getting is overwriting by the form helper function
Try the below code
<?php
session_start();
require_once ("includes/db.php");
print_r($_POST);
if (isset($_POST['btn_signup'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$username = $_POST['username'];
$pass = $_POST['password'];
$cpass = $_POST['conf_pass'];
$country = $_POST['country'];
$dropdown = $_POST['dropdown'];
$query3 = "SELECT * from tbl_users WHERE email = '" . $email . "'";
$result3 = mysql_query($query3, $con) or die(mysql_error());
$query = "SELECT * from tbl_users WHERE username = '" . $username . "'";
$result = mysql_query($query, $con) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
echo '<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">';
echo '<div class="alert alert-danger alert-dismissable">';
echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
echo 'Username is not available! Please Try another username!!.' . mysql_error();
echo '</div>';
echo '</div>';
}
elseif ($pass != $cpass) {
echo '<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">';
echo '<div class="alert alert-danger alert-dismissable">';
echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
echo 'Password typed doesnt match please retype the password correctly!!.' . mysql_error();
echo '</div>';
echo '</div>';
}
elseif (mysql_num_rows($result3) > 0) {
echo '<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">';
echo '<div class="alert alert-danger alert-dismissable">';
echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
echo 'Email Already exist please try another email!!.' . mysql_error();
echo '</div>';
echo '</div>';
}
else {
$query2 = "INSERT INTO tbl_users (first_name,last_name,username,password,confPass,email,country,user_type)VALUES('{$fname}','{$lname}','{$username}','{$pass}','{$cpass}','{$email}','{$country}','{$dropdown}')";
$result2 = mysql_query($query2);
echo '<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">';
echo '<div class="alert alert-success alert-dismissable">';
echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
echo 'Success! Well done its submitted.';
echo '</div>';
echo '</div>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Mycricprofle</title>
<link rel="shortcut icon" href="http://faviconist.com/icons/be7b568b1a766b3888e5326879e1a9b8/favicon.ico" />
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<link rel="stylesheet" href="css/bootstrap-theme.min.css"/>
<link rel="stylesheet" href="css/bootstrap-formhelpers-countries.flags.css"/>
<link rel="stylesheet" href="css/bootstrap-formhelpers.min.css"/>
<script src="js/vendor/jquery-1.11.2.min.js"></script>
<script src="js/vendor/bootstrap.min.js"></script>
<script src="js/bootstrap-formhelpers.min.js"></script>
<script src="js/bootstrap-formhelpers-countries.js"></script>
<style>
.style {
color: #761c19;
text-decoration: none;
}
.style a {
text-decoration: none;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<div class="col-md-6 col-sm-6 col-xs-12">
<h2>Signup to Create a New Account</h2>
<br/>
<form action="signup.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="text">First Name:</label>
<input type="text" class="form-control" placeholder="Firstname" name="fname" required/>
</div>
<br/>
<div class="form-group">
<label for="text">Last Name:</label>
<input type="text" class="form-control" placeholder="Last name" name="lname" required/>
</div>
<br/>
<div class="bfh-selectbox bfh-countries" data-country="US" data-flags="true">
<input type="hidden" id="country" name="country" value="">
<a class="bfh-selectbox-toggle" role="button" data-toggle="bfh-selectbox" href="#"> <span class="bfh-selectbox-option input-medium" data-option=""></span> <b class="caret"></b> </a>
<div class="bfh-selectbox-options">
<input type="text" class="bfh-selectbox-filter">
<div role="listbox">
<ul role="option">
</ul>
</div>
</div>
</div>
<br/>
<div class="form-group">
<label for="text">Email:</label>
<input type="email" class="form-control" placeholder="Email" name="email" required/>
</div>
<br/>
<div class="form-group">
<label for="text">Username:</label>
<input type="text" class="form-control" placeholder="Username" name="username" required/>
</div>
<br/>
<div class="form-group">
<label for="text">Password:</label>
<input type="password" class="form-control" placeholder="Password" name="password" required/>
</div>
<br/>
<div class="form-group">
<label for="text">Confirm Password:</label>
<input type="password" class="form-control" placeholder="Confirm Password" name="conf_pass" required/>
</div>
<br/>
<select class="form-control selectpicker" name="dropdown" id="type_user" required/>
<option value="player">Player</option>
<option value="recruiter">Recruiter</option>
</select>
<br/>
<br/>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--accent" id="btn_signup" name="btn_signup">Submit</button>
</form>
<br/>
<p class="style">Back to <a href='index.php'>Home</a></p>
<p class="style">Signin to Get in <a href='signin.php'>Sigin in</a></p>
</div>
</div>
<script>
$(document).ready(function(e) {
$(document).find(".bfh-countries input[type=hidden]").attr("name","country");
});
</script>
<?php
// include('includes/footer.php');
?>
</body>
</html>
About DOM reffer this
About DOM manupilation reffer this

Assuming you're using at least version 2.3 of the formhelpers library, You should be able to replace this:
<div class="bfh-selectbox bfh-countries" data-country="US" data-flags="true">
<input type="hidden" id="country" name="country" value="">
<a class="bfh-selectbox-toggle" role="button" data-toggle="bfh-selectbox" href="#"> <span class="bfh-selectbox-option input-medium" data-option=""></span> <b class="caret"></b> </a>
<div class="bfh-selectbox-options">
<input type="text" class="bfh-selectbox-filter">
<div role="listbox">
<ul role="option">
</ul>
</div>
</div>
</div>
With this:
<div class="country bfh-selectbox bfh-countries" data-flags="true" data-filter="true" data-name="country"></div>
The data-name attribute specifies the name of the hidden field that's used to store the two character country code. You can also specify the value of data-country which will either supply a default value or maintain the value after the postback but that depends on how you're handling it.

Related

How to fix 'If(isset($_POST['Id'])) error' while editing the form in a PHP based CRUD application?

The "if(isset($_POST["titleId"]) && !empty($_POST["titleId"])" in my code is returning false value.
I'm working on a CRUD application, the insert modal is working fine, now I'm stuck at the update part of it. So when you click on the update icon it does fetch the right titleId in the URL but the first 'if' condition returns false and hence the update isn't working.
Here's what I've tried so far.
admin.php
<?php
$typeId = filter_input(INPUT_GET, "type");
$titleId = filter_input(INPUT_GET, "titleId");
$active = "admin" . $typeId;
require_once './pages/header.php';
require_once './functions/queries.php';
$getAll = Queries::getAllTitle($typeId);
?>
<div class="container">
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header clearfix">
<h2 class="pull-left"></h2>
<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#facultyAddModal">Add Title</button>
</div>
<!--<div class="container">
<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#facultyAddModal">Add Title</button>
<br><br>-->
<div class="panel-group" id="titleAccordion">
<?php
for ($i = 0; $i < count($getAll); $i++) {
echo <<<HTML
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">
<a data-toggle="collapse" data-parent="#titleAccordion" href="#collapseF{$i}">{$getAll[$i]['title']}</a></h4>
</div>
<div id="collapseF{$i}" class="panel-collapse collapse" >
<div class="panel-body">
<div class="table-responsive">
<table class="table table-condensed"><tbody>
<tr><td>Title:</td><td>{$getAll[$i]['title']}</td></tr>
<tr><td>Units:</td><td>{$getAll[$i]['units']}</td></tr>
<tr><td>Category:</td><td>{$getAll[$i]['category']}</td></tr>
<tr><td>
<tr><td><input type="hidden" id="titleId" name="titleId" value="{$getAll[$i]['titleId']}"> </tr><td>
<a href='edit.php?titleId={$getAll[$i]['titleId']}' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>
<a href='delete.php?titleId={$getAll[$i]['titleId']}' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>
</tr></td>
</tbody></table>
</div>
</div>
</div>
</div>
HTML;
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Title Add Modal-->
<div class="modal fade" id="facultyAddModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add Title</h4>
</div>
<div class="modal-body">
<div id="adminResult" class="hide" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<div id="resultAdminContent"></div>
</div>
<form class="cmxform" id="adminForm" method="post">
<label for="Activity">ActivityAttended (required)</label>
<input class="form-control" id="adminTitle" name="title" type="text" required>
<br>
<label for="units">Units (required)</label>
<input class="form-control" id="adminUnits" type="number" name="units" required>
<br>
<label for="Category">Category (Optional)</label>
<input class="form-control" id="adminCategory" type="text" name="category">
<br>
<?php echo
'<input type="hidden" id="addadminTypeId" value="'.$typeId.'">';
?>
<?php echo
'<input type="hidden" id="titleId" name="titleId" value="'.$titleId.'">';
?>
<button class="btn btn-info btn-primary" type="submit">Submit</button>
<br>
<br>
</form>
</div>
</div>
</div>
</div>
update.php
<?php
require_once 'functions/db_connection.php';
$conn = DB::databaseConnection();
$title = $units = $category = "";
if(isset($_POST["titleId"]) && !empty($_POST["titleId"])){
$titleId = $_POST['titleId'];
$sql = "UPDATE title SET title = :title, units = :units, category = :category WHERE titleId = :titleId";
if($stmt = $conn->prepare($sql))
{
// Bind variables to the prepared statement as parameters
$stmt->bindParam(':titleId', $titleId);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':units', $units);
$stmt->bindParam(':category', $category);
if ($stmt->execute()) {
header("location: index.php");
exit();
} else{
echo "Something went wrong. Please try again later.";
}
unset($stmt);
}
unset($conn);
} else{
if(isset($_GET["titleId"]) && !empty(trim($_GET["titleId"]))){
$titleId = trim($_GET["titleId"]);
$sql = "SELECT * FROM title WHERE titleId = :titleId";
if($stmt = $conn->prepare($sql))
{
$stmt->bindParam(':titleId', $titleId);
if ($stmt->execute()){
if($stmt->rowCount() == 1){
$result = $stmt->fetch(PDO::FETCH_ASSOC);
// Retrieve individual field value
$title = $result["title"];
$units = $result["units"];
$category = $result["category"];
} else{
echo"error1";
exit();
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
unset($stmt);
unset($conn);
} else{
// URL doesn't contain id parameter. Redirect to error page
echo"error2";
exit();
}
}
?>
<!--<!DOCTYPE html>-->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Update Record</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
.wrapper{
width: 500px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h2>Update Record</h2>
</div>
<form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
<label for="Activity">Title</label>
<input class="form-control" id="adminTitle" name="title" type="text" value="<?php echo $title; ?>" required>
<br>
<label for="units">Units (required)</label>
<input class="form-control" id="adminUnits" type="number" name="units" value="<?php echo $units; ?>" required>
<br>
<label for="Category">Category (Optional)</label>
<input class="form-control" id="adminCategory" type="text" value="<?php echo $category; ?>" name="category">
<br>
<input type="hidden" name="titleId" value="<?php echo $titleId; ?>">
<button class="btn btn-info btn-primary" type="submit">Submit</button>
<br>
<br>
</form>
</div>
</<div>
</div>
</div>
</div>
</body>
</html>
The only goal here is to get the update form working, the user should be able to update the records of the respective title being selected.
I don't know crud but I think there is a way to debug a little:
e.g. try this:
if(isset($_POST["titleId"]) && !empty($_POST["titleId"])){
// test if you are here:
echo 'hi, yeah I am here!';
}
or this
echo '<pre>';
var_dump($_POST);
echo '</pre>';
// before:
if(isset($_POST["titleId"]) && !empty($_POST["titleId"])){
// ...
}
also, take a look at
error_get_last()['message']

Modal loads perfectly fine but it won`t respond inside modal

Assigning php
if(isset($_SESSION['email'])) {
$login = $_SESSION['email'];
$conn = mysqli_connect("localhost", "root", "demo1234", "fromayu");
$con = mysqli_connect("localhost", "root", "demo1234", "fromayu");
$i = 0;
$rowsperpage=2;
$get_user = "select * from users where email='$login'";
$run_user = mysqli_query($con, $get_user);
$row=mysqli_fetch_array($run_user);
$user_id = $row['id'];
$user_name = $row['name'];
if (isset($_REQUEST['page'])) {
$page = $_REQUEST['page'];
$page=$page - 1;
$getuserenterpage=$page * $rowsperpage;
$get_posts = "select * from anotice ORDER BY 1 DESC LIMIT $getuserenterpage,$rowsperpage";
$run_posts = mysqli_query($conn, $get_posts);
}else{
$get_post = "select * from anotice ORDER BY 1 DESC LIMIT 0,2";
$run_posts = mysqli_query($conn, $get_post);
}
while ($row_posts=mysqli_fetch_array($run_posts)) {
$edit_id1 = $row_posts['id'];
$title = $row_posts['title'];
$image = $row_posts['image'];
$desc = substr($row_posts['description'],0,150);
$category = $row_posts['category'];
$batchid=$row_posts['batch_id'];
$dbatch=$row_posts['batch'];
$username=$row_posts['notice_by'];
$date = date('Y-m-d', strtotime($row_posts['date']));
?>
Using buttons and loading contents.Modal loads perfectly fine but when I want to click on textarea inside modal, It won`t respond, another modal has been loaded hidden on background.
<div class="row-fluid">
<div class="span12">
<div class="media user">
<div class="media-body">
<h2 class="media-title" data-target="#popup<?php echo $i; ?>_<?php echo $edit_id1; ?>"><strong>Title: <?php echo $title; ?></strong>
</h2>
<i class="icon-trash"></i>
<button data-target="#popup<?php echo $i; ?>_<?php echo $edit_id1; ?>" data-toggle="modal" class='pull-right text-xs m-t-sm btn btn-info'><i class="icon-edit"></i></button>
<p>
<div class="pull-left">
<img src="../../storage/teacher_submitted_notice/images/<?php echo $image; ?>" width="120" height="120"/> </div>
<small class="muted">Description: <?php echo $desc; ?>...<a class="text-info" href="#">Read More</a></small></p>
<em class="pull-right text-xs"> Posted on <span class="text-default"><strong><?php echo $date; ?></strong></span> for <span class="text-default"><strong><?php echo $category; ?></strong></em>
</div>
</div>
</div>
</div>
Starting modal with respective ids. It shows but it wont respond inside modal when i clicked in textarea or title. Only works when i use tab from keyboard
<br />
<div class="modal fade" id="popup<?php echo $i; ?>_<?php echo $edit_id1; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit Notice</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" hidden="hidden">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<form method="POST" enctype="multipart/form-data">
<label for="recipient-name" class="col-form-label">Title</label>
<input style="position:relative;width:485px;" type="text" name="title" id="title" class="form-control" value="<?php echo $title; ?>">
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">Description</label>
<textarea style="position:relative;width:485px;" rows="4" cols="6" name="description" id="description" class="form-control"><?php echo $desc; ?></textarea>
</div>
<select class="form-control" name="selectCategory" id="selectCategory" onclick="javascript:$('#selectCategory').change(function () {
var selected_option = $('#selectCategory').val();
if (selected_option === 'student') {
$('#cmbbatch').show();
}
if (selected_option === 'teacher') {
$('#cmbbatch').hide();
}
});">
<option>Choose Category</option>
<option value="teacher">Teacher</option>
<option value="student">Student</option>
</select>
<select style="position:relative;left:55px;" class="form-control" name="cmbBatch" id="cmbbatch">
<option value="batch">Choose Batch</option>
<?php
$query = "SELECT * FROM batch";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$batch= $row['batch'];
?>
<option value="<?php echo $id; ?>"><?php echo $batch; ?></option>
<?php
}
?>
</select><br>
<input type="file" name="image" id="image" required="required">
<img style="position:relative;left:22px;" src="../../storage/teacher_submitted_notice/images/<?php echo $image; ?>" height="120" width="120" name="image">
<input type="hidden" name="notic_id" id="notic_id" value="<?php echo $edit_id1; ?>"/>
<input type="hidden" name="notice_by" id="notice_by" value="<?php echo $username; ?>"/>
<input type="hidden" name="edited_by" id="edited_by" value="<?php echo $user_name; ?>"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<input type="submit" name="update" id="update" value="Update" onclick="javascript:document.getElementById('update').value='Updating!'"class="btn btn-info" />
</div>
</div>
</div>
<?php
$i++;
?>
</div>
</form>
<?php
}
include 'totalnoticepage.php';
?>
<?php
}else{
header('Location: ../../index.php');
}
?>
Problem solved by adding hide class
<div class="modal hide fade" id="popup<?php echo $i; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">

insert into mysql using php/html - not work

I'm trying to enter data into a mysql database using php / html form but it isn't working and I don't know why. The record is not inserted and the page just refresh
I apologize for some of it being written in Danish
I have 2 files 1 with html and php and 1 with only php
My database: Database image
This is the html form and php:
<div class="row">
<div class="col-sm-12">
<?php
if (isset($_POST['Submit'])) {
// echo "<pre>", print_r($_POST), "</pre>";
$apply_name = mysqli_real_escape_string($db, $_POST ['apply_name']);
$apply_age = mysqli_real_escape_string($db, $_POST ['apply_age']);
$apply_ingame_name = mysqli_real_escape_string($db, $_POST ['apply_ingame_name']);
$apply_email = mysqli_real_escape_string($db, $_POST ['apply_email']);
$apply_steamID = mysqli_real_escape_string($db, $_POST ['apply_steamID']);
$apply_text = mysqli_real_escape_string($db, $_POST ['apply_text']);
$errors = []; // Array
if ($apply_name == "") {
$errors['apply_name'] = "<div class='alert alert-danger'>
<strong>Du har ikke angivet noget navn!</strong>
</div>";
} elseif (strlen($apply_name) < 2) {
$errors['apply_name'] = "<div class='alert alert-info'>
<strong>Dit navn skal minimum være 2 karatere</strong>
</div>";
}
if ($apply_age == "") {
$errors['create_apply_age'] = "<div class='alert alert-danger'>
<strong>Du har ikke angivet din alder!</strong>
</div>";
}
if ($apply_ingame_name == "") {
$errors['create_apply_ingame_name'] = "<div class='alert alert-danger'>
<strong>Du har ikke angivet noget In-Game navn!</strong>
</div>";
} elseif (strlen($apply_ingame_name) < 2) {
$errors['create_apply_ingame_name'] = "<div class='alert alert-info'>
<strong>Dit In-Game navn skal minimum være 2 karatere</strong>
</div>";
}
if ($apply_email == "") {
$errors['create_apply_email'] = "<div class='alert alert-danger'>
<strong>Email skal udfyldes!</strong>
</div>";
} elseif (!filter_var($apply_email, FILTER_VALIDATE_EMAIL)) {
$errors['create_apply_email'] = "<div class='alert alert-info'>
<strong>Email er ugyldig</strong>
</div>";
}
if ($apply_steamID == "") {
$errors['create_apply_steamID'] = "<div class='alert alert-danger'>
<strong>Du har ikke angivet noget SteamID!</strong>
</div>";
} elseif (strlen($apply_steamID) < 18) {
$errors['create_apply_steamID'] = "<div class='alert alert-info'>
<strong>Dit SteamID ser sådan her ud STEAM_0:0:XXXXXXXX</strong>
</div>";
}
if ($apply_text == "") {
$errors['create_apply_text'] = "<div class='alert alert-danger'>
<strong>Du har ikke skrevet noget om dig selv!</strong>
</div>";
}
if (empty($errors)) {
// Send ansøning
$created = create_apply($apply_name, $apply_age, $apply_ingame_name, $apply_email, $apply_steamID, $apply_text);
if ($created) {
echo "
<div class='alert alert-info'>
<strong>Din ansøning er sendt.</strong>
</div>
";
} else {
// Ansøning kunne ikke sendes
$create_error = "Ansøningen kunne ikke sendes, SteamID eksistere i forvejen";
}
} else {
$create_error = "Der opstod en fejl, Prøv igen";
}
}
?>
<section>
<hr>
<form class="form-horizontal" enctype="multipart/form-data" id="signup" method="post" name="signup" action="?p=askforsignup">
<?php
if (isset($errors['apply_name'])) {
echo $errors['apply_name'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Navn <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span><input class="form-control" id="mem_name" name="apply_name" placeholder="Navn" type="text" value="" >
</div>
</div>
</div>
<?php
if (isset($errors['create_apply_age'])) {
echo $errors['create_apply_age'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Alder <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span><input class="form-control" id="age" name="apply_age" placeholder="Alder" type="date" value="" >
</div>
</div>
</div>
<?php
if (isset($errors['create_apply_ingame_name'])) {
echo $errors['create_apply_ingame_name'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">In-Game Name <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span><input class="form-control" id="ingame_game" name="apply_ingame_name" placeholder="In-Game Name" type="text" value="" >
</div>
</div>
</div>
<?php
if (isset($errors['create_apply_email'])) {
echo $errors['create_apply_email'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Email <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span><input class="form-control" id="emailid" name="apply_email" placeholder="Email" type="email" value="" >
</div><small>Your Email is being used for ensuring the security of your account, authorization and access recovery.</small>
</div>
</div>
<?php
if (isset($errors['create_apply_steamID'])) {
echo $errors['create_apply_steamID'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Steam ID <span class="text-danger">*</span></label>
<div class="col-md-5 col-sm-8">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-steam"></i></span><input class="form-control" id="contactnum" name="apply_steamID" placeholder="Steam ID" type="text" value="" >
</div>
</div>
</div>
<?php
if (isset($errors['create_apply_text'])) {
echo $errors['create_apply_text'];
}
?>
<div class="form-group">
<label class="control-label col-sm-3">Beskriv dig selv <span class="text-danger">*</span></label>
<div class="col-md-8 col-sm-9">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-id-card"></i></span>
<textarea class="form-control" rows="5" id="message" name="apply_text" placeholder="Beskriv dig selv." ></textarea>
</div><br>
<div class="col-xs-offset-8 col-xs-10 pull-right">
<input class="btn btn-primary" name="Submit" type="submit" value="Sign Up">
</div>
</div>
</div>
</form>
</section>
</div><!--/.col-sm-8-->
</div>
And this is the php code:
function create_apply($apply_name, $apply_age, $apply_ingame_name, $apply_email, $apply_steamID, $apply_text) {
global $db;
$steamID_exists = steamID_exists($apply_steamID);
if ($steamID_exists == false) {
$apply_name = mysqli_real_escape_string($db, $apply_name);
$apply_age = mysqli_real_escape_string($db, $apply_age);
$apply_ingame_name = mysqli_real_escape_string($db, $apply_ingame_name);
$apply_email = mysqli_real_escape_string($db, $apply_email);
$apply_steamID = mysqli_real_escape_string($db, $apply_steamID);
$apply_text = mysqli_real_escape_string($db, $apply_text);
$query = "INSERT INTO member_applys
(apply_name, apply_age, apply_ingame_name, apply_email, apply_steamID, apply_text, apply_date)
VALUES
('$apply_name', '$apply_age', '$apply_ingame_name', '$apply_email', '$apply_steamID', '$apply_text', NOW())";
$result = $db->query($query);
return true;
} else {
// Brugeren eksistere opret = falsk
return false;
}
}
Solved
the problem was google autocomplete was on not off
Di you be sure that your script call well the form?
I see:
....action="?p=askforsignup">
try:
....action="your_script.php">

Profile page not displaying user profile information or updating [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Hope someone can help. I have a profile page that I want to display the logged in users details. So far I have this on the Profile page.
<?php
/* This script pulls the existing name input and displays it when the user logs in. */
session_start();
include("db.php"); ?>
<?php include("includes/header.php") ?>
<?php include("includes/nav.php") ?>
<?php
if(logged_in()) {
$result = mysqli_query($link,$query);
$row = mysqli_fetch_array($result);
if (!$_POST['name'] && $_POST['name']=="") $error.="<br />Please enter your name";
if (!$_POST['email'] && $_POST['email']=="") $error.="<br />Please enter your email";
if (!$_POST['DOB'] && $_POST['DOB']=="") $error.="<br />Please enter your date of birth";
if (!$_POST['country'] && $_POST['country']=="") $error.="<br />Please enter your country";
if ($error) {
echo '<div class="alert alert-success alert-dismissable">'.addslashes($error).'</div>';
}
if(isset($_POST['form-control'])) {
move_uploaded_file($_FILES['file']['tmp_name'],"img/".$_FILES['file']['name']);
$query = mysqli_query("UPDATE users SET image = '".$_FILES['file']['name']."'");
}
} else {
redirect("login.php");
}
?>
<Style>
.alert{
display:none;
}
#profileimg {
height: 100px;
width: auto;
}
</Style>
<div class="container">
<h1>Edit Profile</h1>
<hr>
<div class="row">
<!-- left column -->
<div class="col-md-3">
<div class="text-center">
<img src="//placehold.it/100" class="avatar img-circle" alt="avatar" id="profileimg">
<h6>Upload a different photo...</h6>
<input class="form-control" type="file" name="name">
</div>
</div>
<!-- edit form column -->
<div class="col-md-9 personal-info">
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Profile updated.</strong>
</div>
<h3>Personal info</h3>
<form class="form-horizontal" role="form" action="edit_profile.php" method="post">
<div class="form-group">
<label class="col-lg-3 control-label name">name:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['name'];?>" type="text" name="name" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['email'];?>" type="text" name="email" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">DOB:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['DOB'];?>" type="date" name="DOB" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Country</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['country'];?>" type="text" name="country" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input class="btn btn-primary" value="Save Changes" type="submit">
<span></span>
<input class="btn btn-default" id="updated" value="Cancel" type="reset">
</div>
</div>
</form>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script>
$("#updated").click(function(){
$(".alert").hide().show('medium');
</script>
</body>
</html>
I then have another php file for the updating which is this:
<?php
session_start();
include("db.php");
$name = $_POST['name'];
$email = $_POST['email'];
$DOB = $_POST['DOB'];
$country = $_POST['country'];
$password = md5($salt.$_POST['password']);
$query = "UPDATE users SET name = '".$name."', email = '".$email."', DOB = '".$DOB."', country = '".$country."', password = '".$password."'";
$result = mysqli_query($link,$query);
header('Location: profile.php');
?>
So the short is it doesn't display or update and I am not sure why. I am new to PHP so go easy on me if this is simple, I have searched but can't seem to find the answer.
Thanks in advance.
Im also new to this but normally when I check if a SESSION id is active I use
if(isset($_SESSION['id'])) {
$query = "UPDATE users SET name = '".$name."', email = '".$email."', DOB = '".$DOB."', country = '".$country."', password = '".$password."' WHERE id='".$_SESSION['id']."'";
}
You also need to echo back the indexed rows that you are trying to query to display results
$name = row['username'];
echo $name;
There are lots of errors in your code: You are trying to upload a file in the same page whereas you send the form data to another page. How you handle form validation is also a little overhead. What I did change in the form is: I add name="save" in your submit button and added new hidden input for storing your user profile id. I am not sure what login() function did in your code, better stick to if($id){}.
Try this:
<?php
/* This script pulls the existing name input
and displays it when the user logs in. */
session_start();
include("db.php");
include("includes/header.php");
include("includes/nav.php");
$id = $_SESSION['id'];
if(loginned()) {//you can do if($id){}
$query="SELECT * FROM users WHERE id='$id' LIMIT 1";
$result = mysqli_query($link,$query);
$row = mysqli_fetch_array($result);
?>
<style>
.alert{
display:none;
}
#profileimg {
height: 100px;
width: auto;
}
</style>
<div class="container">
<h1>Edit Profile</h1>
<hr>
<div class="row">
<!-- left column -->
<!-- edit form column -->
<div class="col-md-9 personal-info">
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert"
aria-hidden="true">×</button>
<strong>Profile updated.</strong>
</div>
<h3>Personal info</h3>
<form class="form-horizontal" role="form"
action="edit_profile.php" method="post">
<div class="form-group">
<label class="col-lg-3 control-label name">name:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['name'];?>"
type="text" name="name" required>
</div>
</div>
<div class="col-md-3">
<div class="text-center">
<img src="//placehold.it/100" class="avatar
img-circle" alt="avatar" id="profileimg">
<h6>Upload a different photo...</h6>
<input class="form-control" type="file" name="name">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['email'];?>"
type="text" name="email" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">DOB:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['DOB'];?>"
type="date" name="DOB" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Country</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['country'];?>"
type="text" name="country" required>
</div>
</div>
<div class="form-group">
<input type="hidden" name="id" value="<?php echo $row['id'];?>">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input class="btn btn-primary" name="save"
value="Save Changes" type="submit">
<span></span>
<input class="btn btn-default" id="updated"
value="Cancel" type="reset">
</div>
</div>
</form>
</div>
<?php }else{ redirect("login.php"); } ?>
edit_profile.php First we check whether any post with a name of save is there, We validate the posted data. if validation is successful, we proceed to upload your file and then run your update query.
<?php
session_start();
include("db.php");
if(isset($_POST['save'])){
$id = isset($_POST['id'])? $_POST['id']:'';
$name = isset($_POST['name'])? $_POST['name']:'';
$email = isset($_POST['email'])? $_POST['email']:'';
$dob = isset($_POST['DOB'])? $_POST['DOB']:'';
$pass = isset($_POST['passwrd'])? md5($salt.$_POST['password']):'';
$country = isset($_POST['country'])? $_POST['country']:'';
if(empty($name)){
$error = 'Please enter your name';
}elseif(empty($email)){
$error = 'Please enter your email';
}elseif(empty($dob)){
$error = 'Please enter your date of birth';
}elseif(empty($country)){
$error = 'Please enter your country';
}elseif(empty($pass)){
$error = 'Please enter your password';
}else{
move_uploaded_file($_FILES['file']['tmp_name'],"img/".$_FILES['file']['name']);
$query = mysqli_query("UPDATE users SET image = '".$_FILES['file']['name']."'
WHERE id='$id'");
$query = "UPDATE users SET name = '$name', email = '$email',
DOB = '$DOB', country = '$country', password = '$password'
WHERE id='$id'";
$result = mysqli_query($link,$query);
header('Location: profile.php');
}
}
?>
<?php if(!empty($error)){
echo '<div class="alert alert-success
alert-dismissable">'.addslashes($error).'</div>';
}else{
echo '<div class="alert alert-success">Success</div>';
}
?>
I have added a demo here. At least this will help:

Delete selected Items with modal confirmation PHP

I have this index.php code:
<form role="form" id="submit_form" class="form-horizontal">
<div class="panel-body">
<div class="form-group has-feedback">
<div class="col-sm-2">
<label class="control-label">País</label>
</div>
<div class="col-sm-9">
<?
$array_pais = array('Selecione...', 'Alemanha', 'Angola', 'Argentina', 'Bolívia', 'Brasil', 'Camarões', 'Canadá', 'Chile', 'China', 'Colombia',
'Costa Rica', 'Cuba', 'Dinamarca', 'Equador', 'Espanha', 'Estados Unidos', 'França', 'Holanda', 'Inglaterra', 'Itália', 'Japão',
'México', 'Nigéria', 'Panamá', 'Paraguai', 'Peru', 'Porto Rico', 'Portugal', 'Rússia', 'Senegal', 'Taiwan', 'Uruguai', 'Venezuela'
);
echo '<select class="form-control" name="pais" id="pais">';
foreach ($array_pais as $valor) {
echo '<option>' . $valor . '</option>';
}
echo '</select>';
?>
</div>
</div>
<div class="form-group has-feedback">
<div class="col-sm-2">
<label class="control-label">Nome:</label>
</div>
<div class="col-sm-10">
<input id="nome" name="nome" class="form-control" type="text" placeholder="Digite o nome">
</div>
</div>
<div class="form-group has-feedback">
<div class="col-sm-2">
<label class="control-label">Empresa</label>
</div>
<div class="col-sm-10">
<input id="empresa" name="empresa" class="form-control" type="text" placeholder="Digite a empresa">
</div>
</div>
<div class="form-group">
<div class="col-sm-12 col-sm-offset">
<div style="float:left; padding-right:30px">
<button type="submit" class="btn btn-lg btn-primary" aria-label="Left Align">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Adicionar
</button>
</div>
<div style="float:right;">
<button class="btn btn-lg btn-warning" onClick="parent.location='exibir.php'">
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="col-md-2"></div>
</div>
</div>
</div>
<div class="section">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="jumbotron">
<table data-toggle="table" data-cache="false" class="table" id="list">
<thead align="center">
<tr bgcolor="#FFFFFF">
<th>PAÍS</th>
<th>NOME</th>
<th>EMPRESA</th>
<th>AÇÕES</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="inserir_modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">
<span class="glyphicon glyphicon-file"></span> Inserir
</h3>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="editar_modal" role="dialog">
<div class="modal-dialog">
<form id="edit_form" class="form">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">
<span class="glyphicon glyphicon-pencil"></span> Editar
</h3>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label">País:</label>
<input id="pais_input" name="nome" class="form-control" type="text" placeholder="Digite o pais">
</div>
<div class="form-group">
<label class="control-label">Nome:</label>
<input id="nome_input" name="nome" class="form-control" type="text" placeholder="Digite a empresa">
</div>
<div class="form-group">
<label class="control-label">Empresa:</label>
<input id="empresa_input" name="empresa" class="form-control" type="text" placeholder="Digite a empresa">
</div>
<input id="id_input" type="hidden" name="id">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success" aria-label="Left Align">
<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> Gravar
</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</form>
</div>
</div>
<div class="modal fade" id="deletar_modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">
<span class="glyphicon glyphicon-trash"></span> Exclusão
</h3>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
<script>
function update_list() {
$.getJSON("get_list.php", function (data) {
if (data.response) {
$("#list").find("tbody").empty();
data.results.forEach(function (i) {
$("#list").find("tbody").append(
"<tr>" +
"<td>" + i.pais + "</td>" +
"<td>" + i.nome + "</td>" +
"<td>" + i.empresa + "</td>" +
"<td align='center'><a class='btn btn-primary glyphicon glyphicon-pencil' title='Editar' id='edit_link' href='" + JSON.stringify(i) + "'></a> | <a class='btn btn-danger glyphicon glyphicon-trash' title='Deletar' id='delete_link' href='" + JSON.stringify(i) + "'></a></td>" +
"</tr>"
);
});
}
});
}
$("#list").delegate('#edit_link', 'click', function (e) {
e.preventDefault();
var info = JSON.parse($(this).attr("href"));
var $modal = $("#editar_modal");
$modal.find("#pais_input").val(info.pais);
$modal.find("#nome_input").val(info.nome);
$modal.find("#empresa_input").val(info.empresa);
$modal.find("#id_input").val(info.id);
$modal.modal('show');
});
update_list();
$('#submit_form').submit(function () {
$.ajax({
url: "inserir.php",
type: "POST",
data: $(this).serialize(),
dataType: "json",
success: function (data) {
if (data.response) {
var $modal = $('#inserir_modal');
$modal.find(".modal-body").html(data.message);
$modal.modal('show');
update_list();
} else {
alert(data.message);
}
}
});
return false;
});
$('#edit_form').submit(function () {
$.ajax({
url: "editar.php",
type: "POST",
data: $(this).serialize(),
dataType: "json",
success: function (data) {
if (data.response) {
var $modal = $('#inserir_modal');
$("#editar_modal").modal('hide');
$modal.find(".modal-body").html(data.message);
$modal.modal('show');
update_list();
} else {
alert(data.message);
}
}
});
return false;
});
</script>
edit.php
<?php
require('conexao.php');
$id = $_POST['id'];
$pais = $_POST['pais'];
$nome = $_POST['nome'];
$empresa = $_POST['empresa'];
$query = "UPDATE tb_visitas SET nome = '$nome', empresa = '$empresa', pais= '$pais' WHERE id = $id ";
$update = mysql_query($query);
if ($update) {
$res['response'] = true;
$res['message'] = "Registro atualizado com sucesso!";
} else {
$res['response'] = false;
$res['message'] = "Erro: " . $query . "<br>" . mysql_error();
}
echo json_encode($res);
?>
get_list.php
<?php
require('conexao.php');
$sql = "SELECT id, pais, nome, empresa FROM tb_visitas";
$table = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($table) > 0) {
$res['response'] = true;
while($row = mysql_fetch_assoc($table)) {
$res['results'][] = $row;
}
} else {
$res['response'] = false;
$res['message'] = "Erro: " . $sql . "<br>" . mysql_error($con);
}
echo json_encode($res);
?>
deletar.php
<?php
require('conexao.php');
$id = $_POST['id'];
$query = "DELETE FROM tb_visitas WHERE id = $id ";
if (mysql_query($query)) {
$res['response'] = true;
$res['message'] = "Registro deletado com sucesso!";
} else {
$res['response'] = false;
$res['message'] = "Erro: " . $query . "<br>" . mysql_error($con);
}
echo json_encode($res);
?>
and conexao.php
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$hostname = 'localhost';
$username = 'root';
$senha = '';
$banco = 'visitas';
$db = mysql_connect($hostname, $username, $senha);
mysql_set_charset('latin1',$db);
mysql_select_db($banco, $db) or die ("Não foi possível conectar ao banco MySQL");
?>
So, now I'd like to put a checkbox in each item for being able to select several records and delete them at once. Another question, when I edit a record if I put a text the field it's filled, but if I put a select it doesn't work. The idea is the select field has all options of countries and letting that item from the record already selected. I hope you understand what I need. Thanks.
From what I understand, you have two questions:
How to put checkboxes on your CRUD list in order to delete all items at once.
It seems that you are using update_list() to load all items on your table. Since thats the case, you need to add an extra <td> in that row to that iteration with the checkbox element.
data.results.forEach(function (i) {
$("#list").find("tbody").append(
"<tr>" +
"<td><input class='item_checkbox' type='checkbox'/></td>" +
"<td>" + i.pais + "</td>" +
"<td>" + i.nome + "</td>" +
"<td>" + i.empresa + "</td>" +
"<td align='center'><a class='btn btn-primary glyphicon glyphicon-pencil' title='Editar' id='edit_link' href='" + JSON.stringify(i) + "'></a> | <a class='btn btn-danger glyphicon glyphicon-trash' title='Deletar' id='delete_link' href='" + JSON.stringify(i) + "'></a></td>" +
"</tr>"
);
});
Once you have that set, you can then use jquery to collect all checkboxes by class .item_checkbox and run a delete function.
How to make sure the SELECT country field is pre-selected when you EDIT an item
Since you are using bootstrap modals, when you edit an item, that modal will popup showing that info. What you need to do is send that item's country ID to that modal's form so that it can be preselected, so do the following change:
first in #editar_modal
<div class="form-group">
<label class="control-label">País:</label>
<select id="pais_input" name="pais">
<?php foreach ($array_pais as $pais) { ?>
<option value="<?php echo $pais ?>"><?php echo $pais ?></option>
<?php } ?>
</div>
then in '#edit_link', 'click', function (e) add:
$modal.find("#pais_input").val(info.pais);

Categories