here I am going to delete the database record, when i delete the record, the record deletes successfully but it dosen't reload the insert_search page it displays the result and deleted result will not go, so i need to type every time insert_search in url to get the updated result, please can u tell me where i need to reload the page and how to implement it, thank you in advance...
<?php
$user = "root";
$server = "localhost";
$password = "";
$db = "coedsproddb1";
$dbconn = mysql_connect($server, $user, $password);
mysql_select_db($db, $dbconn);
?>
<html>
<head>
<title>Insert</title>
<link rel="stylesheet" href="css/jquery-ui.css">
<script src="js/jquery-1.12.4.js"></script>
<script src="js/jquery-ui.js"></script>
<style>
#display {
color: red;
font-size: 12px;
text-align: center;
}
.logo {
padding: 5px;
float: left;
}
header {
background-color: #074e7c;
height: 60px;
width: 100%;
text-align: center;
color: white;
font-size: 40px;
}
#wrap {
text-align: center;
}
</style>
</head>
<body>
<header><img src="images/ipoint.png" class="logo" /> USER REGISTRATION</header>
<div class="container">
<h1 style="text-align:center">ADDING THE USER DETAILS</h1>
<form name="useradd" id="useradd" action="#" method="post">
<table align='center' border='1'>
<tr>
<td>
<label for="userName">UserName</label>
</td>
<td>
<input id="userName" name="userName" type="text" />
</td>
</tr>
<tr>
<td>
<label for="userEmail">Email</label>
</td>
<td>
<input id="userEmail" name="userEmail" type="text" />
</td>
</tr>
<tr>
<td>
<label for="userPassword">password</label>
</td>
<td>
<input id="userPassword" name="userPassword" type="password" />
</td>
</tr>
</table>
<br>
<div id="wrap">
<input type="submit" name="add" value="add" id="add">
<input type="submit" name="update" value="update" id="update">
</div>
</form>
<div id="display">
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#add").click(function(e) {
var userName = $("#userName").val();
var userEmail = $("#userEmail").val();
var userPassword = $("#userPassword").val();
var dataString = 'userName=' + userName + '&userEmail=' + userEmail + '&userPassword=' + userPassword;
alert(dataString);
if (userName == "" || userEmail == "" || userPassword == "") {
document.getElementById("display").innerHTML = "Please Enter The Fields";
} else if (!validate1($.trim(userName))) {
document.getElementById("display").innerHTML = "Please Enter The Valid UserName";
document.getElementById("display").focus();
} else if (!ValidateEmail($.trim(userEmail))) {
document.getElementById("display").innerHTML = "Please Enter The Valid Emailid";
document.getElementById("display").focus();
} else {
$.ajax({
type: "POST",
url: "insert.php",
data: dataString,
cache: false,
success: function(result) {
//alert("submitted"+result);
$('#display').html(result);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
e.preventDefault();
});
function validate1(userName) {
var u = userName;
var filter = /^[a-zA-Z0-9]+$/;
if (filter.test(u)) {
return true;
} else {
return false;
}
}
function ValidateEmail(userEmail) {
var e = userEmail;
var filter = /^\w+([\.-]?\w+)*#\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (filter.test(e)) {
return true;
} else {
return false;
}
}
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#update").click(function(e) {
alert("hi");
var userName = $("#userName").val();
var userEmail = $("#userEmail").val();
var userPassword = $("#userPassword").val();
var dataString = 'userName=' + userName + '&userEmail=' + userEmail + '&userPassword=' + userPassword;
alert(dataString);
if (userEmail == "" || userPassword == "") {
document.getElementById("display").innerHTML = "Please Enter The Fields";
} else {
$.ajax({
type: "POST",
url: "user_update.php",
data: dataString,
cache: false,
success: function(result) {
//alert("submitted"+result);
$('#display').html(result);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
e.preventDefault();
});
});
</script>
</body>
</html>
insert.php
<html>
<head>
<title>Insertion</title>
</head>
<body>
<div id="display">
<?php
include('db.php');
$userName = mysql_real_escape_string($_POST['userName']);
$userEmail = mysql_real_escape_string($_POST['userEmail']);
$userPassword = mysql_real_escape_string($_POST['userPassword']);
$regDate = date("Y-m-d");
function generateCode($characters)
{
$possible = '23456789abcdefghjkmnpqrstuvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible) - 1), 1);
$i++;
}
return $code;
}
$registration_key = generateCode(10);
$str = "insert into coeds_user(userName,userEmail,userPassword,regDate,registration_key) values('$userName','$userEmail','$userPassword','$regDate','$registration_key')";
echo $str;
$query = mysql_query($str);
if ($query) {
$display = "Success";
} else {
$display = "Failed";
}
$string = "select * from coeds_user";
$query2 = mysql_query($string);
$display .= "<table border='1'>";
$display .= "<tr><th>UserId</th><th>UserName</th><th>UserEmail</th><th>UserPassword</th><th>RegDate</th><th>RegistrationKey</th></tr>";
while ($result = mysql_fetch_array($query2)) {
$display .= "<tr>";
$display .= "<td>" . $result['userId'] . "</td>";
$display .= "<td>" . $result['userName'] . "</td>";
$display .= "<td>" . $result['userEmail'] . "</td>";
$display .= "<td>" . $result['userPassword'] . "</td>";
$display .= "<td>" . $result['regDate'] . "</td>";
$display .= "<td>" . $result['registration_key'] . "</td>";
$display .= "<td><a href='user_update.php?user_Id=" . $result['userId'] . "'>Edit</a></td>";
$display .= "<td><a href='user_delete.php?user_Id=" . $result['userId'] . "'>Delete</a></td>";
$display .= "</tr>";
}
$display .= "</table>";
location . reload();
echo $display;
?>
</div>
</body>
</html>
user_delete.php
<html>
<head>
<title>Deletion</title>
<link rel="stylesheet" href="css/jquery-ui.css">
<script src="js/jquery-1.12.4.js"></script>
<script src="js/jquery-ui.js"></script>
<style>
#display {
color: red;
font-size: 12px;
text-align: center;
}
.logo {
padding: 5px;
float: left;
}
header {
background-color: #074e7c;
height: 60px;
width: 100%;
text-align: center;
color: white;
font-size: 40px;
}
#wrap {
text-align: center;
}
</style>
</head>
<body>
<header> <img src="images/ipoint.png" class="logo" /> USER REGISTRATION</header>
<div class="container">
<h1 style="text-align:center">DELETE WINDOW</h1>
<div id="display">
<?php
include('db.php');
if (isset($_GET['user_Id'])) {
$userid = $_GET['user_Id'];
}
?>
<form action="user_delete.php" name="user_delete" method="post">
<input type="hidden" name="user_Id" id="user_Id" value="<?php
if (isset($userid))
echo $userid;
?>">
<?php
include('db.php');
$s = "delete from coeds_user where userId=$userid";
$query3 = mysql_query($s);
if ($query3) {
$display = "Delete Is Successful";
} else {
$display = "Delete Is Unsuccessful";
}
$string = "select * from coeds_user";
$query5 = mysql_query($string);
$display .= "<table border='1'>";
$display .= "<tr><th>UserId</th><th>UserName</th><th>UserEmail</th><th>UserPassword</th><th>RegistrationDate</th><th>RegistrationKey</th></tr>";
while ($res1 = mysql_fetch_array($query5)) {
$display .= "<tr>";
$display .= "<td>" . $res1['userId'] . "</td>";
$display .= "<td>" . $res1['userName'] . "</td>";
$display .= "<td>" . $res1['userEmail'] . "</td>";
$display .= "<td>" . $res1['userPassword'] . "</td>";
$display .= "<td>" . $res1['regDate'] . "</td>";
$display .= "<td>" . $res1['registration_key'] . "</td>";
}
echo $display;
?>
</div>
</form>
</div>
</body>
</html>
user_update.php
<html>
<head>
<title>Updation</title>
</head>
<body>
<div id="display">
<?php
include('db.php');
if (isset($_GET['user_Id'])) {
$userid = $_GET['user_Id'];
echo $userid;
$s = "select * from coeds_user where userId=$userid";
echo $s;
$query1 = mysql_query($s);
$res = mysql_fetch_array($query1);
?>
<input type="hidden" name="userPassword" id="userPassword">
<input type="hidden" name="userEmail" id="userEmail">
<form action="user_update.php" name="user_update" method="post">
<input type="hidden" name="user_Id" id="userId" value="<?php
if (isset($userid))
echo $userid;
?>">
<table align='center' border='1'>
<tr>
<td>
<label for="userName">UserName</label>
</td>
<td>
<input id="userName" name="userName" type="text" value="<?php
echo $res['userName'];
?> " />
</td>
</tr>
<tr>
<td>
<label for="userEmail">Email</label>
</td>
<td>
<input id="userEmail" name="userEmail" type="text" value="<?php
echo $res['userEmail'];
?> " />
</td>
</tr>
<tr>
<td>
<label for="userPassword">password</label>
</td>
<td>
<input id="userPassword" name="userPassword" type="password" value="<?php
echo $res['userPassword'];
?> " />
</td>
</tr>
</table>
<input type="submit" name="modify" id="modify" value="modify">
<?php
}
include('db.php');
if (isset($_POST['user_Id'])) {
$userid = $_POST['user_Id'];
echo $userid;
}
if (isset($_POST['modify'])) {
echo $userid;
$userName = mysql_real_escape_string($_POST['userName']);
$userEmail = mysql_real_escape_string($_POST['userEmail']);
$userPassword = mysql_real_escape_string($_POST['userPassword']);
$string = "update coeds_user set userName='$userName',userEmail='$userEmail', userPassword='$userPassword' where userId=$userid";
echo $string;
$query = mysql_query($string);
if ($query) {
$display = "Update Successful";
} else {
$display = "Update Failed";
}
$s = "select * from coeds_user";
$query = mysql_query($s);
$display .= "<table border='1'>";
$display .= "<tr><th>UserId</th><th>UserName</th><th>UserEmail</th><th>UserPassword</th><th>RegDate</th><th>RegistrationKey</th></tr>";
while ($res = mysql_fetch_array($query)) {
$display .= "<tr>";
$display .= "<td>" . $res['userId'] . "</td>";
$display .= "<td>" . $res['userName'] . "</td>";
$display .= "<td>" . $res['userEmail'] . "</td>";
$display .= "<td>" . $res['userPassword'] . "</td>";
$display .= "<td>" . $res['regDate'] . "</td>";
$display .= "<td>" . $res['registration_key'] . "</td>";
$display .= "</tr>";
}
$display .= "</table>";
echo $display;
}
?>
</div>
</body>
</form>
</html>
Use
echo "<script>location.replace('user_delete.php');</script>";
instead of header location.
Hope this helps.
Related
My PHP code:
<?php
include 'function.php';
$db = mysqli_connect("localhost","root","","messmanagementsys");
session_start();
if(mysqli_connect_error())
{
echo "ERROR CONNECTING TO THE DATABASE";
}
else{
$vali=$_POST['noie'];
echo $vali;
for($i=1;$i<=$vali;$i++)
{
$iname=$_POST['ingname'.$i];
$icode=$_POST['ingcode'.$i];
$icur=$_POST['ingcur'.$i];
$ireq=$_POST['ingreq'.$i];
$icost=$_POST['ingcost'.$i];
$idate=$_POST['ingdate'.$i];
$check="SELECT `ingcode` FROM `ing` WHERE ingcode='$icode'";
$s=mysqli_query($db,$check);
$coderepeat=mysqli_fetch_array($s);
$e=mysqli_num_rows($s);
echo $e;
if($e>0)
{
echo "<script>$(function(){
$('#my-dialog-id').dialog();
});
</script>";
if(isset($_POST['ingyes']))
{
$update="UPDATE `ing` SET `ingname`='$iname',`ingcode`='$icode',`current`='$icur',`required`='$ireq',`ingcost`='$icost',`date`='$idate' WHERE 1";
}
if(isset($_POST['ingno'])){
header("Refresh:0:url=ingredient.php");
}
}
else{
$query="INSERT INTO `ing`(`ingname`, `ingcode`, `current`, `required`, `ingcost`, `date`) VALUES ('$iname','$icode','$icur','$ireq','$icost','$idate')";
$res=mysqli_query($db,$query);
if($res)
header("Refresh:0;url=ingredient.php");
else
echo "SOMETHING WENT WRONG";
}
}
}
?>
<!DOCTYPE html>
<head></head>
<body>
<form action="ingupdate.php" method="POST">
<div id='my-dialog-id' title='my dialog title'>
<p>The item <?php $string=implode(",",$coderepeat);echo $string;?> already exists do u wish to update??</p>
<button name="ingyes" >YES</button>
<button name="ingno">NO</button>
</div>
</form>
<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>
</body>
I need to print the code which is being repeated.
I have put the entries in an array in php but if i have 2 codes which are repetitive then the array has he same value stored twice.
I'm getting the values of the variable from a html page and the user selects the no of entries he wants to make.
I'm creating the input field dynamically and setting names dynamically so I'm retrieving them in PHP by concatenating ingname with $i which is a variable which is set to the no of input fields user has requested.
I'm using loops and retrieving the values of those input fields.
What can i do to enter into array the 2 values?
Here is my html code:
<!DOCTYPE html>
`<html>
<head>
<link rel="stylesheet" href="main.css">
<link href='https://fonts.googleapis.com/css?family=Bungee Shade' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Eater' rel='stylesheet'>
<title>Ingredients Details</title>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<center> <h1 id="labelb">Ingredients Details</h1></center>
<form action="ingupdate.php" method="POST" >
<input type="text" name="noie" placeholder="Enter the no of ingredients to add" style="width:200px;" id="noie">
<button id="noieb">Enter</button>
<table id="ingredients">
<thead><tr>
<th>Ingredient name:</th>
<th>Ingredient code:</th>
<th>Current<sub>(in stock in kgs)</sub></th>
<th>Required<sub>(excluding stocks in kgs)</sub></th>
<th>Cost<sub>(in Rupees including transportation)</sub></th>
<th>Date:</th>
</tr>
</thead>
<tbody id="ing">
<?php
$db = mysqli_connect("localhost","root","","messmanagementsys");
session_start();
if(mysqli_connect_error())
{
echo "ERROR CONNECTING TO THE DATABASE";
}
else{
//$query1="SELECT * FROM login ";
$usr=$_SESSION['adminuser'];
$query1="SELECT * FROM `ing` WHERE 1";
$result1=mysqli_query($db,$query1);
while($row = mysqli_fetch_array($result1))
{
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "<td>" . $row[5] . "</td>";
echo "</tr>";
}
}
//echo "<td><form action='fineedit.php' method='POST'><select name='sfstat'><option value='paid' >Paid</option><option value='unpaid' selected>No</option></select><button type='submit' name='submit'>submit</button></form></td>";
?>
</tbody>
</table>
<button type="submit" name="submit" >SUBMIT</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
document.getElementById("noieb").onclick=function()
{
var i=document.getElementById("noie").value;
for(var j=1;j<=i;j++)
{
var table = document.getElementById("ing");
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
var name='ingname'+j;
var code='ingcode'+j;
var cur='ingcur'+j;
var req='ingreq'+j;
var cost='ingcost'+j;
var date='ingdate'+j;
var iname = document.createElement('input');
iname.setAttribute("type", "text");
iname.name = "ingname" + j;
iname.setAttribute("required", "true");
cell1.appendChild(iname);
var icode = document.createElement('input');
icode.setAttribute("type", "text");
icode.name = "ingcode" + j;
icode.setAttribute("required", "true");
cell2.appendChild(icode);
var icur = document.createElement('input');
icur.setAttribute("type", "number");
icur.name = "ingcur" + j;
icur.setAttribute("required", "true");
cell3.appendChild(icur);
var ireq = document.createElement('input');
ireq.setAttribute("type", "number");
ireq.name = "ingreq" + j;
ireq.setAttribute("required", "true");
cell4.appendChild(ireq);
var icost = document.createElement('input');
icost.setAttribute("type", "number");
icost.name = "ingcost" + j;
icost.setAttribute("required", "true");
cell5.appendChild(icost);
var idate = document.createElement('input');
idate.setAttribute("type", "date");
idate.name = "ingdate" + j;
idate.setAttribute("required", "true");
cell6.appendChild(idate);
}
}
function delrow(){
var table = document.getElementById("ing");
table.deleteRow(-1);
}
$(document).ready(function(){
$("input[name=edit]").on("click",function(){
$(".en").css("display","block");
})
$("input[name=save]").on("click",function(){
$(".en").css("display","none");
})
})
</script>
</body>\
Second html file
</html>
<!DOCTYPE html>
<head></head>
<body>
<form action="ingupdate.php" method="POST" >
<input type="text" name="noie" placeholder="Enter the no of ingredients to add" style="width:200px;" id="noie">
<button id="noieb">Enter</button>`
<div id='my-dialog-id' title='my dialog title'>
<p>The item <?php print_r($coderepeat);?> already exists do u wish to update??</p>
<button name="ingyes" >YES</button>
<button name="ingno">NO</button>
</div>
<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>
</body>
Here I have HTML, PHP and Jquery code with where I can edit all my record using the modal, the problem is that it keeps disappearing after I click on my update button, the modal only shows for about half a second. Can you help me? I'm actually new and just learning Jquery
this is the front view
<?php
include 'php/header.php';
require_once 'php/connect.php';
?>
<script>
$(document).ready(function(){
$("#input").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#body tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
<style>
table, th, td {
border: 1px solid black;
color: black;
width: auto;
margin: auto;
}
td {
text-align: center;
}
.edit {
background-color: blue;
font-family: algerian;
color: lime;
border-radius: 30px;
}
.edit:hover {
cursor: pointer;
background-color: yellow;
color: black;
}
.delete {
color: white;
background: black;
font-family: algerian;
}
.delete:hover {
color: black;
background: yellow;
}
</style>
<h1 style=" font-family: algerian; color: lime" align="center">Assets</h1>
<div class="filter">
<input style="height: 23px; float: right;" id="input" type="text" placeholder="Search.." autocomplete="off"></div>
<br>
<br>
<table align="center">
<tr>
<a onclick="" href=""></a>
<thead>
<th>Asset Num</th>
<th>FA num</th>
<th>Employee</th>
<th>Team</th>
<th>Contractor</th>
<th>Status</th>
<th>Category</th>
<th>Disposed</th>
<th colspan="2">Actions</th>
</thead>
<tbody id="body">
<?php
$sql = " SELECT * FROM assets
LEFT JOIN team
ON assets.team_id = team.team_id
LEFT JOIN contractor
ON assets.contractor_id = contractor.contractor_id
LEFT JOIN employee
ON assets.employee_id = employee.employee_id
LEFT JOIN item_status
ON assets.status_id = item_status.status_id
LEFT JOIN category
ON assets.category_id = category.category_id
ORDER BY category ";
$result = mysqli_query($conn, $sql);
if ($result->num_rows> 0) {
while($row = $result->fetch_assoc())
{
if (empty($row["disposal_status_id"])) {
$row["disposal_status_id"] = "NO"; }
else {
$row["disposal_status_id"] = "YES";
}
echo "<tr>";
echo "<td>". $row["asset_num"] ."</td>" ;
echo "<td>". $row["fa_num"]."</td>";
echo "<td>". $row["first_name"]. " " .$row["last_name"]. "</td>";
echo "<td>". $row["team"]."</td>";
echo "<td>". $row["F_name"]."</td>";
echo "<td>". $row["item_status"]."</td>";
echo "<td>". $row["category"]."</td>";
echo "<td>". $row["disposal_status_id"] ."</td>";
echo "<td><form method='POST' id='form'><button name='edit' class='edit' value=". $row['assets_id'] . " >Update</button></form>";
echo "<td><a class='delete' onclick=\"return confirm('Are you sure you want to delete this record?')\"
href='php/delete_asset.php?id=".$row['assets_id']."'>Delete</a>";
echo "</tr>";
}
}
else {
echo "<p style='font-family: algerian; font-size: 30px; margin-left: 45%; color: yellow ' >No Record</p>";
}
?>
</tbody>
</table>
and this is the modal view
<script>
$(document).ready(function() {
$(".edit").click(function(){
$("#modal").css('display', 'block');
});
});
</script>
<script>
$(document).ready(function() {
$("#cancel").click(function(){
$("#modal").css("display", "none");
});
});
</script>
<script>
$(document).ready(function(){
$("#form").submit(function() {
var edit = $(this).val();
$.ajax({
type: "POST",
data: {edit:edit},
});
});
});
</script>
<?php
include 'php/connect.php';
$id = $_POST['edit'];
$d = mysqli_query($conn, " SELECT * FROM assets
LEFT JOIN employee
ON assets.employee_id = employee.employee_id
LEFT JOIN team
ON assets.team_id = team.team_id
LEFT JOIN contractor
ON assets.contractor_id = contractor.contractor_id
LEFT JOIN item_status
ON assets.status_id = item_status.status_id
LEFT JOIN category
ON assets.category_id = category.category_id
LEFT JOIN disposal_status
ON assets.disposal_status_id = disposal_status.disposal_status_id
WHERE assets_id = '$id'");
$check = mysqli_fetch_array($d);
function load_employee()
{
include 'php/connect.php';
$output = '';
$sql = "SELECT * FROM employee ORDER BY first_name";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)) {
$output .= "<option value='" . $row['employee_id'] ."'>"
. $row['first_name'] . " "
. $row['last_name'] . " </option>";
}
return $output;
}
?>
<div id="modal">
<script>
$(document).ready(function(){
$('#employee').change(function(){
var employee_id = $(this).val();
$.ajax({
url:"php/get_employee_team.php",
method: "POST",
data: {employee_id:employee_id},
dataType:"text",
success:function(data)
{
$('#team').html(data);
}
});
});
});
</script>
<link rel="stylesheet" type="text/css" href="../mystyle.css">
<style>
#modal {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0%;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5);
z-index: 2;
cursor: pointer;
background-color: rgba(0,0,0,0.8); /* Black w/ opacity */
}
</style>
<form method="POST" action="php/update_assets.php" >
<table align="center">
<th colspan="4" >Update Asset # <?php echo $check['assets_id']; ?></th>
<tr></tr>
<input style="display: none" type="text" name="assets_id" value="<?php echo $check['assets_id'] ?>">
<td>Asset Num:</td>
<td><input type="text" name="asset_num" value="<?php echo $check['asset_num'] ?>" autocomplete="off" required></td>
<td>Unit Condition:</td>
<td><input type="text" name="condition" value="<?php echo $check['condition'] ?>" autocomplete="off" ></td>
<tr></tr>
<td>FA Num:</td>
<td><input type="text" name="fa_num" value="<?php echo $check['fa_num'] ?>" autocomplete="off" required></td>
<td>Audit Date:</td>
<td><input type="date" name="audit" value="<?php echo $check['audit_date'] ?>" autocomplete="off"></td>
<tr></tr>
<tr>
<td>Employee:</td>
<td>
<select id="employee" name="employee" >
<?php
echo "<option value='" . $check['employee_id'] ."'>"
. $check['first_name'] . " "
. $check['last_name'] . " </option>";
?>
<option><?php echo load_employee(); ?></option>
</select>
</select></td>
<td>Location:</td>
<td><input type="text" name="location" value="<?php echo $check['location'] ?>" autocomplete="off"></td>
</tr>
<tr>
<td>Team:</td>
<td>
<select style="color: black" id="team" name="team" readonly>
<option value= "<?php echo $check['team_id'] ?>" ><?php echo $check['team'] ?></option>
</select>
</td>
<td>Insurance Date:</td>
<td><input type="date" name="insurance" value="<?php echo $check['audit_date'] ?>"></td>
</tr>
<td>Contractor:</td>
<td><select name="contractor">
<?php
echo "<option value='" . $check['contractor_id'] ."'>"
. $check['F_name'] . " "
. $check['L_name'] . " </option>";
?>
<option>
<?php
$sql = "SELECT * FROM contractor" ;
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['contractor_id'] ."'>"
. $row['F_name'] . " "
. $row['L_name'] . " </option>";
}
?>
</option>
</select> </td>
<td>Comments:</td>
<td><input style="overflow: scroll;" type="text" name="comments" value="<?php echo $check['comments'] ?>" autocomplete="off"></td>
<tr></tr>
<td>Status:</td>
<td><select name="status">
<?php
echo "<option value='" . $check['status_id'] ."'>"
. $check['item_status'] . " </option>";
?>
<option>
<?php
$sql = "SELECT * FROM item_status " ;
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['status_id'] ."'>"
. $row['item_status'] . " </option>";
}
?>
</option>
</select>
</td>
<td colspan="2"> <br></td>
<tr></tr>
<td>Asset Category:</td>
<td>
<select name="category">
<?php
echo "<option value='" . $check['category_id'] ."'>"
. $check['category'] . " </option>";
?>
<option>
<?php
$sql = "SELECT * FROM category" ;
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['category_id'] ."'>"
. $row['category'] . " </option>";
}
?>
</option>
</select>
</td>
<td colspan="2"> <br></td>
<tr></tr>
<td>Description:</td>
<td><input type="text" name="description" value="<?php echo $check['description'] ?>" autocomplete="off">
<td colspan="2" style="text-align: center; color: blue; font-family: algerian" >DISPOSAL DETAILS</td>
<tr></tr>
<td>Serial Number:</td>
<td><input type="text" name="serial" value="<?php echo $check['serial_num'] ?>" autocomplete="off"></td>
<td>Disposal Location</td>
<td><input type="text" name="disposal_loc" value="<?php echo $check['disposal_location'] ?>" autocomplete="off"></td>
<tr></tr>
<td>Date Aquired:</td>
<td><input type="date" name="acquired" value="<?php echo $check['date_get'] ?>" autocomplete="off"></td>
<td>Date Disposed</td>
<td><input type="date" name="disposal_date" value="<?php echo $check['disposal_date'] ?>" autocomplete="off"></td>
<tr></tr>
<td>Purchase Price:</td>
<td><input type="text" name="price" value="<?php echo $check['purchase_price'] ?>" autocomplete="off"></td>
<td>Disposed Status</td>
<td>
<select id="dept" name="disposal_status">
<?php
if ($check['disposal_status_id'] == 0) {
echo "<option value='". $checl['disposal_status_id'] ."' >";
echo "NOT YET";
echo "</option>";
}
?>
<?php
$sql = "SELECT * FROM disposal_status " ;
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['disposal_status_id'] ."'>"
. $row['status'] . " </option>";
}
?>
</select>
</td>
<tr></tr>
<br>
<td style="text-align: center;" colspan="4"><button type="submit" name="btn" class="submit" >Submit</button>
<p class="submit" id="cancel">Cancel</p></form>
</td>
</table>
</div>
I try to send the data in the same page and try to change the CSS code when I click on the Update button, sending the id and fetching the data required using ajax Jquery, Hope someone can help me, thanks in advance
I think you need to use preventDefault() function because the nature of submiting form is to refresh the page that's also the reason why the modal is appearing just a couple of seconds only or sometimes it is not appearing.
Please try these line of code.
$("#form").on("submit",function(event) {
event.preventDefault();
var edit = $(this).val();
$.ajax({
type: "POST",
data: {edit:edit},
});
});
});
I'm pretty new to html, php, mysql and i have to like learn the basics # my new workplace.
I'm having an annoying problem with my Form Validation. I'm using ubuntu server in combination with PuTTY
My problem is: that my 'Validation' and 'empty Field' check is not working propperly.
So when i go into my browser, my Form (Table) shows up as it should. When I hit the Submit button WITHOUT writing any stuff into the fields, the Form stays on the page and my Errors appear: ("Name is required, email, Nachname") That's right so far.
But when i fill in anything into the field(s), and then hit the Submit button, the form just disappears and i get like a blank page (but still having my CSS background n stuff).
No matter if comes up to the requirements, or not.
I'm trying to find out whats wrong since 3 whole days 9hrs/day # my workplace.
So hopefully anyone of you can help me finally get this thing work.
everything i post now is in the same order as i have it in my PuTTy
(nano)
My script starts like this:
CSS:
<html>
<head>
<title> Formular FINAL </title>
<style>
body {
background-image: url("http://fewpict.com/images/background-pictures/background-pictures-01.jpg");
}
.db_table {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
overflow: hidden;
overflow-y: auto;
position: fixed;
top: 80%;
left: 50%;
transform: translate(-50%, -50%);
width: 50%;
height: 100px;
}
.db_table td, tr {
color: white;
text-align: center;
}
.center_div {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.center_div td {
font-family: "Comic Sans", Comic Sans MS, cursive;
color: white;
text-align: left;
}
.error {color: #FF0000;}
</style>
</head>
<body>
PHP-Form Validation:
<?php
$VornameErr = "";
$emailErr = "";
$NachnameErr = "";
$Vorname = $_POST['Vorname'];
$email = $_POST['email'];
$Nachname = $_POST['Nachname'];
$allesok = "";
//input type hidden
if(isset($_POST['action'])){
//ÜBERPRÜFUNGSVARIABLE
$allesok = 1;
$errors = array();
if (empty($_POST) === false) {
$required_fields = array('Vorname', 'Nachname', 'email');
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true ){
$errors[] = 'Fields marked with an asterisk are required';
break 1;
}
}
}
//Vorname Überprüfen
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Vorname"])) {
$allesok = 0;$VornameErr = "Name is required";
} else {
$Vorname = test_input($_POST["Vorname"]);
if (!preg_match("/[a-zA-Z]{3,}/",$Vorname)) {
$allesok = 0;$VornameErr = "Only letters and atleast 3 alpha characters Allowed";
}
}
}
if (empty($_POST["email"])) {
$allesok = 0;$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$allesok = 0;$emailErr = "Invalid email format";
}
}
//Nachname Überprüfen
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Nachname"])) {
$allesok = 0; $NachnameErr = "Nachname is required";
} else {
$Nachname = test_input($_POST["Nachname"]);
if (!preg_match("/[a-zA-Z]{3,}/",$Nachname)) {
$allesok = 0;$NachameErr = "Only letters and atleast 3 alpha characters Allowed";
}
}
}
function check_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
}
MySQL:
if ($allesok) {
define('DB_NAME', 'formular');
define('DB_USER', 'David');
define('DB_PASSWORD', '****');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
if(isset($_POST['sent'])) {
$value1 = $_POST['Vorname'];
$value2 = $_POST['Nachname'];
$value3 = $_POST['email'];
$sql = "INSERT INTO formular (Vorname, Nachname, email) VALUES ('$value1', '$value2', '$value3')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
} else {
$msg1='<p> Your information was submitted successfully.</p>';
}
}
Echo Form:
if(isset($_POST['sent'])) {
?>
<div class="center_div">
<table>
<tr>
<td style="width: 200px;">Vorname: </td>
<td style="border-bottom: 1px solid black;"><?php echo $_POST['Vorname']; ?> </br></td>
</tr>
<tr>
<td style="width: 200px;">Nachname: </td>
<td style="border-bottom: 1px solid black;"><?php echo $_POST['Nachname']; ?> </br></td>
</tr>
<tr>
<td style="width: 200px;">E-Mail: </td>
<td style="border-bottom: 1px solid black;"><?php echo $_POST['email']; ?> </br> </td>
</tr>
</table>
<input type="button" value="Zurück" onClick="history.back();">
</div>
<?php
echo $msg1."<br /><br /><br />";
//Liste anzeigen
} elseif(isset($_POST['show_table'])) {
//fake formular <-----was made for still having the possibility to fill out stuff when i view the LIST
echo "<div class='center_div'>";
echo "<form action='toto2.php' method='POST'/>";
echo"<table>";
echo "<tr>";
echo "<th></th>";
echo "<th></th>";
echo "<th>span class='error'>* required field.</span></th>";
echo "<tr>";
echo "<td style= 'width: 200px;' > Vorname:* </td>";
echo "<td> <input type='text' name='Vorname' placeholder='Your Vorname...' /></td>";
echo "<td><span class='error'>*$VornameErr </span></td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 200px;'> Nachname:* </td>";
echo "<td> <input type='text' name='Nachname' placeholder='Your Nachname...' /></td>";
echo "<td><span class='error'>*$NachnameErr</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 200px;'> E-Mail:* </td>";
echo "<td><input type='email' name='email' placeholder='Your E-Mail address...' /></td>";
echo "<td><span class='error'>*$emailErr</span></td>";
echo "</tr>";
echo "</table>";
echo "<input type='submit' value='SEND' name='sent' />";
echo "<input type='submit' value='Einträge anzeigen' name='show_table' />";
echo "<input type='button' value='Einträge ausblenden' onClick='history.back();'>";
echo "</div>";
echo "</form>";
//DB Tabelle
$query = "SELECT * FROM formular;";
$result = mysql_query($query);
echo '<div class="db_table">';
echo '<table>';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>Vorname</th>';
echo '<th>Nachname</th>';
echo '<th>email</th>';
echo '</tr>';
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td>";
echo "</tr>";
}
echo '<tr>';
echo '<td>';
echo '<input type="button" value="Zurück" onClick="history.back();">';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
}
} else {
?>
HTML Form:
<div class="center_div">
<span class="error"></span>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table>
<tr>
<th></th>
<th></th>
<th><span class="error">* required field.</span></th>
<tr>
<td style= "width: 200px;" > Vorname:* </td>
<td> <input type="text" name="Vorname" placeholder="Your Vorname..." /></td>
<td><span class="error">* <?php echo $VornameErr;?></span></td>
</tr>
<tr>
<td style="width: 200px;"> Nachname:* </td>
<td> <input type="text" name="Nachname" placeholder="Your Nachname..." /></td>
<td><span class="error">* <?php echo $NachnameErr;?></span></td>
</tr>
<tr>
<td style="width: 200px;"> E-Mail:* </td>
<td><input type="text" name="email" placeholder="Your E-Mail address..." /></td>
<td><span class="error">* <?php echo $emailErr;?></span></td>
</tr>
</table>
<input type="hidden" name="action" value="1">
<input type="submit" value="SEND" name="sent" />
<input type="submit" value="Einträge anzeigen" name="show_table" />
<input type="button" value="Einträge ausblenden" onClick="history.back();">
</form>
</div>
<?php
}
mysql_close();
?>
</body>
</html>
Hey everyone I have been trying to figure this out for a while and just cant get around while its not showing the second fetch where weaponF is,
<?php
session_start();
if(!$_SESSION['logged']){
header("Location: login_page.php");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<style type="text/css">
div {
position: relative;
left: 5px;
top: 25px;
width: 280px;
padding: 10px;
color: black;
display: none;
}
</style>
<script language="JavaScript">
function setVisibility(id1,id2,id3) {
if(document.getElementById('bt1').value=='H'){
document.getElementById('bt1').value = 'S';
document.getElementById(id1).style.display = 'none';
document.getElementById(id2).style.display = 'none';
document.getElementById(id3).style.display = 'none';
}else{
document.getElementById('bt1').value = 'H';
document.getElementById(id1).style.display = 'inline';
document.getElementById(id2).style.display = 'inline';
document.getElementById(id3).style.display = 'inline';
}
}
function setvisibility(id4){
if(document.getElementById('bt2').value=='HP'){
document.getElementById('bt2').value = 'SP';
document.getElementById('id4').style.display = 'none';
}else{
document.getElementById('bt2').value = 'HP';
document.getElementById('id4').style.display = 'inline';
}
}
function setvisibility(id5){
if(document.getElementById('bt3').value=='HC'){
document.getElementById('bt3').value = 'SC';
document.getElementById('id5').style.display = 'none';
}else{
document.getElementById('bt3').value = 'HC';
document.getElementById('id5').style.display = 'inline';
}
}
function setvisibility(id6){
if(document.getElementById('bt4').value=='HM'){
document.getElementById('bt4').value = 'SM';
document.getElementById('id6').style.display = 'none';
}else{
document.getElementById('bt4').value = 'HM';
document.getElementById('id6').style.display = 'inline';
}
}
function setvisibility(id7){
if(document.getElementById('bt5').value=='HI'){
document.getElementById('bt5').value = 'SI';
document.getElementById('id7').style.display = 'none';
}else{
document.getElementById('bt5').value = 'HI';
document.getElementById('id7').style.display = 'inline';
}
}
</script>
<body>
<center>
<?php
$con=mysqli_connect(secret);
$validUser = mysqli_real_escape_string($con, $_SESSION['username']);
$result = mysqli_query($con, "SELECT level, exp, maxexp, str, dex, inte, sta, crit, hp, atk, def, dfire, dwater, dposion, atkfire, atkwater, atkposion, weapon FROM users WHERE username = '$validUser'");
$data = mysqli_fetch_array($result,MYSQLI_ASSOC);
$weapon = $data['weapon'];
$weaponQ = mysqli_query($con, "SELECT * FROM equipment WHERE wname= '$weapon'") or die(mysqli_error($con));
$weaponF = mysqli_fetch_array($weaponQ,MYSQLI_ASSOC);
mysqli_close($con);
?>
<body><center>
<table border="1">
<td>Level:<?php echo $data['level']; ?></td>
<td
<?php if ($data['exp'] == $data['maxexp']) {
echo "bgcolor = white";
}
else
{
echo "bgcolor = white";
}
?>
>Exp:<?php echo $data['exp']; ?>/<?php echo $data['maxexp']; ?></td>
<td>Str:<?php echo $data['str']; ?></td>
<td>Dex:<?php echo $data['dex']; ?></td>
<td>Int:<?php echo $data['inte']; ?></td>
<td>Stam:<?php echo $data['sta']; ?></td>
<td>Crit:<?php echo $data['crit']; ?>%</td>
</table>
<?php
if ($data['exp'] == $data['maxexp']) {
echo "<a href='levelup.php'>Level up </a>";
}
else
{
echo "";
}
?>
</center>
<table border="1" align="left">
<tr>
<td>
<a onclick="setVisibility('sub3','sub4','sub5');" id="bt1" href="#">Explore</a><br /><br />
<a onclick="setVisibility('sub6');" id="bt4" href="#">Market</a><br /><br />
<a onclick="setVisibility('sub1');" id="bt2" href="#">Profile</a><br /><br />
<a onclick="setVisibility('sub2');" id="bt3" href="#">Casino</a><br /><br />
<a onclick="setVisibility('sub7');" id="bt5" href="#">Inventory</a><br /><br />
Logout
</td>
</tr>
</table>
<br />
<div id="sub3" align="center">Map</div>
<br><br><br><br><br>
<div id="sub4" align="center">Arrows</div>
<div id="sub5" align="center">Mobs</div>
<div id="sub1" align="center">
<table border="1" align="center">
<td>
<?php
echo "<font size='+2'>Base Stats</font>";
echo "<br><br>";
echo "Str: ";
echo $data['str'];
echo "<br>";
echo "Dex: ";
echo $data['dex'];
echo "<br>";
echo "Int: ";
echo $data['inte'];
echo "<br>";
echo "Stam: ";
echo $data['sta'];
echo "<br>";
echo "Crit: ";
echo $data['crit'];
echo "%";
echo "<br>";
echo "Atk: ";
echo $data['atk'];
echo "<br>";
echo "Def: ";
echo $data['def'];
echo "<br><br>";
echo "<font size='+2'>Bonus Atk</font>";
echo "<br><br>";
echo "Atk Fire: ";
echo $data['atkfire'];
echo "%";
echo "<br>";
echo "Atk Water: ";
echo $data['atkwater'];
echo "%";
echo "<br>";
echo "Atk Posion: ";
echo $data['atkposion'];
echo "%";
echo "<br><br>";
echo "<font size='+2'>Bonus Res</font>";
echo "<br><br>";
echo "Def Fire: ";
echo $data['dfire'];
echo "%";
echo "<br>";
echo "Def Water: ";
echo $data['dwater'];
echo "%";
echo "<br>";
echo "Def Posion: ";
echo $data['dposion'];
echo "%";
?>
</td>
</table>
</div>
<div id="sub2" align="center">Casino</div>
<div id="sub6" align="center">Market</div>
<div id="sub7" align="center">
<table border="1" bordercolor="white">
<tr>
<td bordercolor="white" height="50px" width="50px"></td>
<td width="50px" height="50px" bordercolor="black">
Head
</td>
</tr><br />
<tr>
<td width="50px" height="50px" bordercolor="black">
<img onmouseover="<?php echo $weaponF['name']; ?>" src="equipment/<?php echo $data['weapon']; ?>.png" />
</td>
<td width="50px" height="50px" bordercolor="black">
Chest
</td>
<td width="50px" height="50px" bordercolor="black">
RightArm
</td>
</tr>
<tr>
<td bordercolor="white" height="50px" width="50px">
</td>
<td bordercolor="black" height="50px" width="50px">
Pants
</td>
</tr>
<tr>
<td bordercolor="white" height="50px" width="50px">
</td>
<td bordercolor="black" height="50px" width="50px">
Shoes
</td>
</tr>
</table>
</div>
<?php echo $data['weapon'];
echo $weaponF['wname']; ?>
</body>
It dose not show any errors or faults, Please help haha here is all my code make it easier to view and help I hope lol
i think username and name is your table columns so try
$validUser = mysqli_real_escape_string($con, $_SESSION['username']);
mysqli_query("SELECT * FROM users WHERE username ='$validUser' LIMIT 1");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT level, exp, maxexp, str, dex, inte, sta, crit, hp, atk, def, dfire, dwater, dposion, atkfire, atkwater, atkposion, weapon FROM users WHERE username = '$validUser'");
$data = mysqli_fetch_array($result,MYSQLI_ASSOC);
$weapon = $data['weapon'];
$weaponQ = mysqli_query($con, "SELECT * FROM equipment WHERE wname= '$weapon'") or die(mysqli_error($con));
if(mysqli_num_rows($weaponQ) > 0) {
$weaponF = mysqli_fetch_array($weaponQ,MYSQLI_ASSOC);
}
else {
echo 'No rows found';
}
mysqli_close($con);
and also there is no work of below query so you can remove this:-
mysqli_query("SELECT * FROM users WHERE username ='$validUser' LIMIT 1");
I have tried a few things but cant seem to implement pagination properly, can someone point me in the right direction and give me a few code examples of how i can properly implement pagination in my code
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<link href="/lightbox/css/lightbox.css" rel="stylesheet" />
<link rel="stylesheet" href="img/reveal.css">
<script src="/lightbox/js/jquery-1.7.2.min.js"></script>
<script src="/lightbox/js/lightbox.js"></script>
<script src="img/jquery.min.js" type="text/javascript"></script>
<script src="img/jquery.reveal.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
#divspace {
position: relative;
width: 100%;
height: 50px;
z-index: -9999;
vertical-align bottom;
}
#divspace1 {
position: relative;
width: 100%;
height: 50px;
z-index: -9999;
vertical-align: bottom;
padding-left: 400px;
}
#search1 {
position: absolute;
width: 203px;
height: 30px;
z-index: -9999;
vertical-align: bottom;
left: 832px;
top: 1px;
z-index: 9999;
}
#text1 {
position: absolute;
width: 203px;
height: 30px;
z-index: -9999;
vertical-align: bottom;
top: 13px;
z-index: 9999;
left: 268px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
color: #FFF;
font-style: italic;
font-size: 22px;
}
#apDiv1 {
position:absolute;
width:560px;
height:27px;
z-index:1;
left: 93px;
top: 247px;
}
#cat {
position:absolute;
width:227px;
height:500px;
z-index:1;
left: 3px;
top: 48px;
background-color: #FFF;
font-family:"Lucida Console", Monaco, monospace;
}
.container1 {
position:relative;
padding: 0 20px 0 20px;
margin: auto;
width: 1000px;
background-image: url(images/skyblue.png);
margin-top: 20px;
margin-bottom: 20px;
padding-bottom: 300px;
-moz-border-radius: 8px;
border-radius: 8px;
}
.label{
text-align:right;
}
#submit{
text-align:center;
}
</style>
<script type = "text/javascript">
function myfunction(url)
{
window.location.href = url;
}
</script>
<script type="text/javascript">
$(document).ready(function(){
$(".expanderHead").click(function(){
var $exsign = $("#expanderSign");
$(this).find("#expanderContent").slideToggle();
$exsign.html($exsign.text() == '+' ? '-': '+');
// simplify your if/else into one line using ternary operator
// if $exsign.text() == "+" then use "-" else "+"
});
});
</script>
</head>
<body>
<div id="header">
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=439699742746900";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div id="search">
<center>
<form method="GET" action="search.php" style= "padding: 1px;">
<input name="search" id="s" type="text" value="<?php echo $_GET['search']; ?>" size="20" />
<select name="category" id="category" >
<?php if(isset($_GET['submit'])) { ?>
<option value="<?php echo $_GET['category']; ?>" selected="selected"><?php echo $_GET['category']; ?></option>
<?php }else{ ?>
<option value=""> -- select -- </option>
<?php } ?>
<option value="">All</option>
<option value="Books">Books</option>
<option value="Textbooks">TextBooks</option>
<option value="Tickets">Tickets</option>
<option value="Electronics">Electronics</option>
<option value="Clothing">Clothing</option>
<option value="Accessories">Accessories</option>
<option value="Furniture">Furniture</option>
<option value="Imagery">Imagery</option>
<option value="Business">Business</option>
<option value="Clothing">Clothing</option>
<option value="Multi">Multimedia</option>
</select>
<select name="university" id="university" >
<option value="">Aston University</option>
</select>
<input id="searchSubmit" type="submit" value="" name="submit"/>
</form>
</center>
</div>
<div id="imagelogo" onclick = "window.location.href = 'index.php'" >
<p> Buy and sell stuff around University</p>
</div>
<ul id="navigation" name="navigation">
<li id="nav-home">Home | Search | Selling | Buying | FAQ | Contact </li>
</ul>
<div id="account">
<?php
if( isset( $_SESSION['username'] ) ){
echo "<a href='securedpage1.php'>My Account</a><img src='images/uni-icon.png' width='30' height='18' style='vertical-align: middle;'/>";
}else{
echo "<a href='login.php' >Login</a><img src='images/uni-icon.png' width='30' height='18' style='vertical-align: middle;'/>";
}
?>
</div>
<div id="registerlogout">
<?php
if( isset( $_SESSION['username'] ) ){
echo "<a href='logout.php'>Logout</a>";
}else{
echo "<a href='register.php'> Register</a>";
}
?>
</div>
<center>
<center>
</div>
<div class="container1">
<div id="cat">
<table width="225" border="1" cellspacing="10" cellpadding="10">
<tr>
<td>Accessories</td>
</tr>
<tr>
<td>Accommodation</td>
</tr>
<tr>
<td>Books</td>
</tr>
<tr>
<td>Business</td>
</tr>
<tr>
<td>Clothing</td>
</tr>
<tr>
<td>Electronics</td>
</tr>
<tr>
<td>Furniture</td>
</tr>
<tr>
<td>Imagery</td>
</tr>
<tr>
<td>Multimedia</td>
</tr>
<tr>
<td>Services</td>
</tr>
<tr>
<td>Tickets</td>
</tr>
</table>
</div>
<div id="text1">Items For Sale:
</div>
<div id="search1">
<form method="GET" action="search.php" style= "padding: 1px;">
<select name="price" id="price" >
<?php if(isset($_GET['submit'])) { ?>
<option value="<?php echo $_GET['price']; ?>" selected="selected"><?php echo $_GET['price']; ?></option>
<?php }else{ ?>
<option value=""> -- select -- </option>
<?php } ?>
<option value=""></option>
<option value="DESC">Highest to Lowest</option>
<option value="ASC">Lowest to Highest</option>
</select>
<input id="searchSubmit" type="submit" value="" name="submit"/>
</form>
</div>
<div id="divspace"></div>
<div style=" padding-left: 240px" ">
<?php
// Include database connection settings
include('config.php');
include('config.inc');
// Check and set username
$username = (isset($_SESSION['username']) ? $_SESSION['username'] : 'guest');
// Check and set category
$category = (!empty($_GET['category']) ? $_GET['category'] : null);
// Check and set search
if(!empty($_GET['search'])){
$search = $_GET['search'];
}else{
$search = null;
}
// Check that $_GET['price'] is ASC if not set to DESC
// as static values its ok to directly put in the query
if(isset($_GET['price']) && $_GET['price'] == 'ASC'){
$price = 'ASC';
}else{
$price = 'DESC';
}
if ($search !== null){
$sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)";
$q = $conn->prepare($sql) or die("failed!");
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->execute();
}
if ($search !== null && $category !== null){
$sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE) AND category = :category";
$q = $conn->prepare($sql) or die("failed!");
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->bindParam(':category', $category, PDO::PARAM_STR);
$q->execute();
}
if ($category !== null && $search !== null && isset($price)){
$sql = "SELECT *
FROM people
WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)
AND category = :category
ORDER BY price ".$price;
$q = $conn->prepare($sql);
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->bindParam(':category', $category, PDO::PARAM_STR);
$q->execute();
}
if ($category == null && $search !== null && isset($price)){
$sql = "SELECT *
FROM people
WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)
ORDER BY price ".$price;
$q = $conn->prepare($sql);
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->execute();
}
if ($q){
//declaring counter
$count=0;
while($r = $q->fetch(PDO::FETCH_ASSOC)){
$row = $r;
$fname = $row['fname'];
$lname = $row['lname'];
$firstname = $row['firstname'];
$surname = $row['surname'];
$expire = $row['expire'];
$oDate = strtotime($row['expire']);
$sDate = date("d/m/y",$oDate);
//counter equals
$count++;
//insert an image every 5 rows
if($count==5){
$count=0;
echo "<table width='50%' style='border-bottom:1px solid #000000;'>";
echo "<tr>";
echo "<td>";
echo "<div id='page-wrap'>";
echo "<div class='discounted-item freeshipping'>";
echo "<a href='images/box1.png' rel='lightbox'><img src='images/box1.png' width='160px' height='200px' /></a>";
echo "<div class='reasonbar'><div class='prod-title' style='width: 70%;'>AN AD CAN GO HERE</div><div class='reason' style='width: 29%;'><b>Ad Company</b></div></div>";
echo "<div class='reasonbar'><div class='prod-title1' style='width: 70%;'>Description about the advert from a company</div><div class='reason1' style='width: 29%;'>Category: Advert</div></div>";
echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'>HELLO, User</div><div class='reason2' style='width: 29%;'></div></div>";
echo "</td>";
echo "</tr>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
echo "<table width='50%' style='border-bottom:1px solid #FFFFFF'>";
echo "<tr>";
echo "<td>";
echo "<div id='page-wrap'>";
echo "<div class='discounted-item freeshipping'>";
echo "<a href='./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "' rel='lightbox'><img src=\"./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "\" alt=\"\" width='80px' height='100px' /></a>";
echo "<div class='expanderHead'>";
echo "<div class='reasonbar'><div class='prod-title'>" .$row['fname'] . "</div><div class='reason' style='width: 29%;'><b>". $row['firstname'] . " " . $row['surname'] ."</b></div></div>";
echo "<div id='expanderContent' style='display:none'><div class='reasonbar'><div class='prod-title1'>" . $row['lname'] . "</div><div class='reason1' style='width: 29%;'>Category:<br /> ". $row['category'] . "</div></div>";
echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'><form action='adclick.php' method='post'><input type='hidden' name='username' value='" . $row['username'] . "'/><input type='submit' name='submit' value='Reply To this ad'></form></div><div class='reason2' style='width: 29%;'></div></div></div>";
echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'>Expires: $sDate</div><div class='reason2' style='width: 29%;'>Price: £". $row['price'] . "</div></div>";
echo "</td>";
echo "</tr>";
echo "</td>";
echo "</tr>";
echo "</div>";
echo "</table>";
}
}
else
echo "No results found for \"<b>$search</b>\"";
//disconnect
mysql_close();
?>
</div>
</div>
<div class="footer">
<p> Private Policy | Terms and Conditions | FAQ </p>
</div>
</body>
</html>
Sample Code:
$start is the starting number,$limit is the ending number (for one page).. $count is total number of records
echo "<h5>Showing ".$start." to ".($start+$limit)." Records of ".$count." Records</h5>";
if($start<=($count-$limit))
{
echo '<a style="float:right" href="'.$_SERVER['PHP_SELF'].'?start='.($start+$limit).'&limit='.$limit"><t1>Next</t1></a>';
}
$prev = $start-$limit;
if ($prev >= 0)
{
echo '<a style="float:left" href="'.$_SERVER['PHP_SELF'].'?start='.$prev.'&limit='.$limit"><t2>Previous</t2></a>';
}
$i=0;
$l=1;
echo "<p align='center'>";
for($i=0;$i < $count;$i=$i+$limit)
{
if($i <> $start)
{
echo "<a href='listing_test.php?start=$i&limit=$limit'><font face='Verdana' size='2'><b> $l </b></font></a> ";
}
else
{
echo "<font face='Verdana' size='4' color=#2E9AFE ><b> $l </b></font>";
}
$l=$l+1;
}
echo "</p>";
EDIT:
$result = mysql_query("SELECT * FROM table_name LIMIT ".$start.",".$limit);
$total=mysql_query("SELECT * FROM table_name");
$count=mysql_num_rows($total);