I have a mysql data which I call to display to my PHP table and then for example I clicked the username01, I wanted to call the other columns of that username01 (e.g. password01, id01) to display to my modal fields.
Here's my code:
PHP
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" ?> <?php echo "<font color='blue'>" . $row['ipaddress'] . "</font></td>";
echo "<td>" . $row['name'] . "</td>";
Modal
<?php
include 'includes\dbconn.php';
$query = mysqli_query($conn,"SELECT * from devopstbl where id=$id");
$ipaddress = $row['ipaddress'];
$name = $row['name'];
$department = $row['department'];
?>
<div id="id01" class="modal">
<form class="modal-content animate" method="GET" action="ipaddress.php">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Exit">×</span>
<img src="images/avatar.png" alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="ipaddress"><b>Username <?php echo $username; ?></b></label>
<input type="text" pattern="[a-zA-Z0-9\s]+" name="username" value="<?php echo $ipaddress; ?>" required>
Apparently.. the $id only gets the id01 even i clicked the other data like id02 etc. and does not get its other columns like username01 password01..
Am i missing something?
Put yout Modal-part to while loop.
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$username = $row['username'];
$ipaddress = $row['ipaddress'];
$name = $row['name'];
echo '<tr>
<td>
<font color="blue">'.$ipaddress.'</font>
<div id="id'.$id.'" class="modal">
<form class="modal-content animate" method="GET" action="ipaddress.php">
<div class="imgcontainer">
<span onclick="document.getElementById(\'id'.$id.'\').style.display=\'none\'" class="close" title="Exit">×</span>
<img src="images/avatar.png" alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="ipaddress"><b>Username '.$username.'</b></label>
<input type="text" pattern="[a-zA-Z0-9\s]+" name="username" value="'.$ipaddress.'" required>
</div>
</form>
</div>
</td>
<td>'.$name.'</td>
';
}
Related
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">
I've read a ton of different ideas out there for this but can't seem to get any of them to work for my piece of code. Currently my products are displaying in a singular column but I'd like them to display in either a 3 or 4 column grid. Here's the code I have so far, hopefully someone can see where I'm going wrong.
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) { ?>
<div class="container">
<div class="col-sm-4">
<?php echo $row["ID"] . " - " . $row["item"] . "<br>";?>
<img src="img/<?php echo $row["image"] ?>" style="width:150px;height:150px;"><br>
<?php echo $row["description"] . " - $" . $row["price"]; ?>
<form method="post" action="viewcart.php">
<input type="hidden" name="item" value="<?php echo $row["item"]?>" />
<input type="hidden" name="price" value="<?php echo $row["price"]?>" />
<button type="submit">Add To Cart</button>
</form>
</div>
</div>
You have the .container being looped inside the while loop as well, which is the problem. The correct format is:
.container
.row
.col-XX-X
Put the container and the row outside and you are good to go.
<?php
if ($result->num_rows > 0) {
echo '<div class="container"><div class="row">'; // You left a row. Change here.
while($row = $result->fetch_assoc()) { ?>
<div class="col-sm-4">
<?php echo $row["ID"] . " - " . $row["item"] . "<br>";?>
<img src="img/<?php echo $row["image"] ?>" style="width:150px;height:150px;"><br>
<?php echo $row["description"] . " - $" . $row["price"]; ?>
<form method="post" action="viewcart.php">
<input type="hidden" name="item" value="<?php echo $row["item"]?>" />
<input type="hidden" name="price" value="<?php echo $row["price"]?>" />
<button type="submit">Add To Cart</button>
</form>
</div>
<?php } ?>
</div>
</div>
Put your container outside of while loop:
if ($result->num_rows > 0) {
echo '<div class="container">';
while($row = $result->fetch_assoc()) { ?>
<div class="col-sm-4">
<?php echo $row["ID"] . " - " . $row["item"] . "<br>";?>
<img src="img/<?php echo $row["image"] ?>" style="width:150px;height:150px;"><br>
<?php echo $row["description"] . " - $" . $row["price"]; ?>
<form method="post" action="viewcart.php">
<input type="hidden" name="item" value="<?php echo $row["item"]?>" />
<input type="hidden" name="price" value="<?php echo $row["price"]?>" />
<button type="submit">Add To Cart</button>
</form>
</div>
<?php } // end while loop
?>
</div>
<?php } //end if statement
?>
If you want more columns, make it like below:
<div class="container">
<div class="row">
<div class="col-sm-4">
</div>
<div class="col-sm-6">
</div>
<div class="col-sm-2">
</div>
</div>
</div>
The total number of columns when you add up, must be 12
I've fetched rows from MySQL and looped it with Bootstrap modal and I've made a form in modal from which the data is being sent to PHP script (update.php) with the help of ajax. But in return I am getting the output of last row only.
I need to get the record of specific student with its unique ID.
HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table class="table table-responsive">
<thead>
<tr>
<th>NAME</th>
<th>ROLL NUMBER</th>
<th>CONTACT NO</th>
<th>ADDRESS</th>
<th>EDIT</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM students ORDER BY id DESC";
$query_run = mysqli_query($connection, $query);
if($query_run){
while($row = mysqli_fetch_assoc($query_run)){
$id = $row['id'];
$name = $row['name'];
$rollno = $row['rollno'];
$contact = $row['contact'];
$address = $row['address'];
echo "<tr>";
echo '<td>' . $name . '</td>';
echo '<td>' . $rollno . '</td>';
echo '<td>' . $contact . '</td>';
echo '<td>' . $address . '</td>';
echo "<td><button class='btn btn-link btn-custom dis' data-toggle='modal' data-target='#myModal$id'>
EDIT</button> </td>";
echo '</tr>';
?>
<div class="modal fade" id="myModal<?php echo $id; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">EDIT RECORD</h4>
</div>
<div class="modal-body">
<form id="updateValues" action="update.php" method="POST" class="form">
<div class="form-group">
<label for="name">NAME</label>
<input type="text" class="form-control" name="name" id="name" value="<?php echo $name; ?>">
</div>
<div class="form-group">
<label for="rollno">ROLL NO</label>
<input type="text" class="form-control" name="rollno" id="rollno" value="<?php echo $rollno; ?>">
</div>
<div class="form-group">
<label for="contact">CONTACT</label>
<input type="text" class="form-control" name="contact" id="contact" value="<?php echo $contact; ?>">
</div>
<div class="form-group">
<label for="address">ADDRESS</label>
<textarea class="form-control" rows="3" name="address" id="address"><?php echo $address; ?></textarea>
</div>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" class="btn btn-primary btn-custom" value="Save changes">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<div id="results"></div>
</div>
</div>
</div>
</div>
<?php }
}?>
</tbody>
</table>
</body>
</html>
JS:
$(document).ready(function(){
var values, url;
$('#updateValues').submit(function(e){
e.preventDefault();
values = $(this).serialize();
url = $(this).attr('action');
$.post(url, values, function(data){
$('#results').html(data);
});
});
});
Update.php:
<?php
if(isset($_POST['name'])&&isset($_POST['rollno'])&&isset($_POST['contact'])&&isset($_POST['address'])){
$id = $_POST['id'];
$name = $_POST['name'];
$rollno = $_POST['rollno'];
$contact = $_POST['contact'];
$address = $_POST['address'];
echo "$id $name $rollno $contact $address";
}else{
echo 'ERROR!';
}
?>
This is not tested/debugged but refactor your code similar to this:
<?php
$query = "SELECT * FROM students ORDER BY id DESC";
$query_run = mysqli_query($connection, $query);
if($query_run){
$out = '
<table class="table table-responsive">
<thead>
<tr>
<th>NAME</th>
<th>ROLL NUMBER</th>
<th>CONTACT NO</th>
<th>ADDRESS</th>
<th>EDIT</th>
</tr>
</thead>
<tbody>
';
while($row = mysqli_fetch_assoc($query_run)){
$out .= '<tr class="trID_' .$row['id']. '">';
$out .= '<td class="td_name">' . $row['name'] . '</td>';
$out .= '<td class="td_rollno">' . $row['rollno'] . '</td>';
$out .= '<td class="td_contact">' . $row['contact'] . '</td>';
$out .= '<td class="td_address">' . $row['address'] . '</td>';
$out .= "<td><button class='td_btn btn btn-link btn-custom dis'>EDIT</button> </td>";
$out .= '</tr>';
}
$out .= '</tbody></table>
echo $out;
?>
<script>
$(document).ready(){
$('.td_btn').click(function(){
var $row = $(this).closest('tr');
var rowID = $row.attr('class').split('_')[1];
var name = $row.find('.td_name').val();
var rollno = $row.find('.td_rollno').val();
var contact = $row.find('.td_contact').val();
var address = $row.find('.td_address').val();
$('#frm_id').val(rowID);
$('#frm_name').text(name);
$('#frm_rollno').text(rollno);
$('#frm_contact').text(contact);
$('#frm_address').text(address);
$('#myModal').modal('show');
});
});//END document.ready
</script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">EDIT RECORD</h4>
</div>
<div class="modal-body">
<form id="updateValues" action="update.php" method="POST" class="form">
<div class="form-group">
<label for="name">NAME</label>
<input type="text" class="form-control" name="name" id="frm_name">
</div>
<div class="form-group">
<label for="rollno">ROLL NO</label>
<input type="text" class="form-control" name="rollno" id="frm_rollno">
</div>
<div class="form-group">
<label for="contact">CONTACT</label>
<input type="text" class="form-control" name="contact" id="frm_contact">
</div>
<div class="form-group">
<label for="address">ADDRESS</label>
<textarea class="form-control" rows="3" name="address" id="frm_address"></textarea>
</div>
<input type="hidden" name="frm_id">
<input type="submit" class="btn btn-primary btn-custom" value="Save changes">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<div id="results"></div>
</div>
</div>
</div>
</div>
<?php
}
}
?>
Notes:
(1) Create the entire table in a variable, then output the variable all at once.
(2) You only need one modal, not one modal for each table row. Therefore, remove modal creation from inside while loop.
(3) Use jQuery to:
(a) detect button click in row
(b) get table data for that row
(c) populate fields in modal
(d) display modal
You are using Bootstrap, which uses jQuery, so it makes sense to use jQuery to do this.
(4) Using jQuery to get values from table cells vs. input fields:
(a) .text() - from table cells
(b) .val() - from <input> or <textarea>
Here is a jsFiddle Demo you can play with that demonstrates how you can use jQuery to populate the modal depending on the row that was clicked.
i am newbie in php kindly pardon me if i am silly .
I have a form which on submit updates the changes in the form .
Now i added a image upload field with field type as file . my question is i don't want it to be uploaded by clicking upload button separately, instead i want to use the same old submit button which i use for form update . i tried several ways but failed . also i want to save only in the name admin and it should allow only .jpg extension
My form page code is as follows
<?php
if(isset($_POST['update'])) {
$info = pathinfo($_FILES['imagefile']['name']);
$ext = $info['extension']; // get the extension of the file
$newname = "admin.".$ext;
$target = WEB_URL .'img/'.$newname;
move_uploaded_file( $_FILES['imagefile']['tmp_name'], $target);
$name_a = $_POST['name'];
$email_a = $_POST['email'];
$pass_a = $_POST['password'];
$sql = "UPDATE admin SET a_name = '$name_a', a_email = '$email_a', password = '$pass_a' where aid='$update_id' ";
$retval = mysql_query($sql,$link);
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
// echo "Updated data successfully\n";
}
$result = mysql_query("SELECT * FROM admin where aid='$update_id' ",$link);
while($row = mysql_fetch_array($result)){
$name = $row['a_name'];
$email = $row['a_email'];
$password = $row['password'];
}
mysql_close($link);
?>
<div class="box box-widget widget-user-2">
<div class="widget-user-header bg-yellow">
<div class="widget-user-image">
<?php echo '<img src="' . $img . '" class="img-circle" alt="User Image">'; ?>
</div>
<!-- /.widget-user-image -->
<h3 class="widget-user-username"><?php echo "$name"; ?></h3>
<h5 class="widget-user-desc"><?php echo "$role"; ?></h5>
</div>
<div class="box-footer no-padding">
<form role="form" method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="box-body">
<div class="form-group">
<label for="exampleInputName1">Name</label>
<input type="text" class="form-control" id="exampleInputName1" name="name" value="<?php echo $name; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" name="email" value="<?php echo $email; ?>">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" name="password" value="<?php echo $password; ?>">
</div>
<div class="form-group">
<label for="exampleInputFile">Profile picture</label><br/>
<img id="preview" src="<?php echo $img; ?>" /><br/><br/>
<input type="file" onchange="readURL(this);" id="exampleInputFile" name="imagefile">
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" name="update" id="update" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
<!-- /.widget-user -->
The lines which i tried and failed to achieve my requirement is as follows . which is also there in the above code .
$info = pathinfo($_FILES['imagefile']['name']);
$ext = $info['extension']; // get the extension of the file
$newname = "admin.".$ext;
$target = WEB_URL .'img/'.$newname;
move_uploaded_file( $_FILES['imagefile']['tmp_name'], $target);
You forgot to write enctype="multipart/form-data" into your <form> without this attribute you can not upload any image.
You should change :
<form role="form" method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
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.