PHP delete function? - php

PHP beginner here, probably bind to this mistake. Got a crud function going on here, trying to get the delete button to work. Users would currently be on the /crud/view.php. It's currently asking "do you want to delete" followed by the screen refreshing and nothing happening.
<?php
session_start();
if(isset($_SESSION['u_uid'])){
$uid = $_SESSION['u_id'];
require_once('connect.php');
$ReadSql = "SELECT * FROM `contact` WHERE users_id=$uid ORDER BY Name";
$res = mysqli_query($connection, $ReadSql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Motoko</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container">
<div class="row">
<table class="table">
<tr>
<th><strong>Extras</strong></th>
</tr>
<?php
while($r = mysqli_fetch_assoc($res)){
?>
<tr>
<td>Edit
</td>
<td><input type="button" onClick="deleteme(<?php echo
$r['u_uid']; ?>)" name="Delete" value="Delete"></td>
</tr>
<script language="Javascript">
function deleteme(delid)
{
if(confirm("Are you sure you want to Delete?")){
window.location.href='delete.php';
}
}
</script>
<?php } ?>
</table>
</div>
</body>
</html>
<?php
}else{
header("Location: http://motoko.sorainsurance.com.au");
}
?>
With the /delete.php being:
<?php
if(isset($_SESSION['u_uid'])){
require_once('connect.php');
$select = "DELETE from contact where id='".$_GET['del_id']."'";
$query = mysqli_query($connection, $select) or die($select);
}else{
header("Location: http://motoko.sorainsurance.com.au/crud/view.php");
}
?>

Change these lines
<input type="button" onClick="deleteme('<?php echo
$r['u_uid']; ?>')" name="Delete" value="Delete">
function deleteme(delid){
if(confirm("Are you sure you want to Delete?")){
window.location.href='delete.php?del_id='+delid;
}
}
Always preferred to write you php code at top of HTML script
<?php
session_start();
if(!isset($_SESSION['u_uid'])){
header("Location: http://motoko.sorainsurance.com.au");
}
$uid = $_SESSION['u_id'];
require_once('connect.php');
$ReadSql = "SELECT * FROM `contact` WHERE users_id=$uid ORDER BY Name";
$res = mysqli_query($connection, $ReadSql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Motoko</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container">
<div class="row">
<table class="table">
<tr>
<th>
<strong>Extras</strong>
</th>
</tr>
<?php while($r = mysqli_fetch_assoc($res)){ ?>
<tr>
<td>
Edit
</td>
<td>
<input type="button" onClick="deleteme('<?php echo $r['u_uid']; ?>')" name="Delete" value="Delete">
</td>
</tr>
<?php } ?>
</table>
</div>
</body>
</html>
<script language="Javascript">
function deleteme(delid){
if(confirm("Are you sure you want to Delete?")){
window.location.href='delete.php?del_id=delid';
}
}
</script>

<form>
<input type="button" value="Search Contact 1.0" onclick="window.location.href='http://motoko.sorainsurance.com.au/crud/searchone.php'" />
</form>
<form>
<input type="button" value="Search Contact 2.0" onclick="window.location.href='http://motoko.sorainsurance.com.au/crud/search.php'" />
</form>
<html>
<head>
<title>Motoko</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<table class="table">
<tr>
<th><strong>Name</strong></th>
<th><strong>Company</strong></th>
<th><strong>Title</strong></th>
<th><strong>Phone</strong></th>
<th><strong>Email</strong></th>
<th><strong>Address</strong></th>
<th><strong>Extras</strong></th>
</tr>
<?php
while($r = mysqli_fetch_assoc($res)){
?>
<tr>
<td><?php echo $r['Name']; ?></td>
<td><?php echo $r['Company']; ?></td>
<td><?php echo $r['Title']; ?></td>
<td><?php echo $r['Phone']; ?></td>
<td><?php echo $r['Email']; ?></td>
<td><?php echo $r['Address']; ?></td>
<td>Edit</td>
<td> <input type="button" onClick="deleteme(<?php echo $r['u_uid']; ?>)" name="Delete" value="Delete">
</tr>
<script language="Javascript">
function deleteme(delid) {
if(confirm("Are you sure you want to Delete?")){
window.location.href='delete.php?del_id='+delid;
}
}
</script>
<?php } ?>
</table>
</div>
</body>
</html>
<?php
}else{
header("Location: http://motoko.sorainsurance.com.au");
}
?>

Could you try ?
$select = "DELETE from contact where id='".$_GET['u_uid']."'";

Related

Generating a button on php checkbox selection from mysql

I have this project where the user selects items using a checkbox and then a button is generated from that item's name.
<!DOCTYPE html>
<html>
<head>
<title>webs</title>
</head>
<body>
<h2>Select User:</h2>
<div>
<form method="POST">
<table border="1">
<thead>
<th></th>
<th>Subject</th>
</thead>
<tbody>
<?php
include('get.php');
$query=mysqli_query($conn,"select * from `subjects`");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><input type="checkbox" value="<?php echo $row['subject']; ?>" name="id[]"></td>
<td><?php echo $row['subject']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<br>
<input type="submit" name="submit" value="Submit">
</form>
</div>
<div>
<h2>Subjects selected:</h2>
<button class="button"><span><?php
if (isset($_POST['submit'])){
foreach ($_POST['id'] as $id):
$sq=mysqli_query($conn,"select * from `subjects` where subject='$id'");
$srow=mysqli_fetch_array($sq);
echo $srow['subject']."<br>";
endforeach;
}
?></span></button>
</div>
I did make a button but the output was just one big button formed from all selections.
How do I make buttons individually per item? Thanks.
Also, additionally, how can I make this dynamic? no need for a "Submit" button?
You Should try Following code For generate Separate Button.
<!DOCTYPE html>
<html>
<head>
<title>webs</title>
</head>
<body>
<h2>Select User:</h2>
<div>
<form method="POST">
<table border="1">
<thead>
<th></th>
<th>Subject</th>
</thead>
<tbody>
<?php
include('get.php');
$query=mysqli_query($conn,"select * from `subjects`");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><input type="checkbox" value="<?php echo $row['subject']; ?>" name="id[]"></td>
<td><?php echo $row['subject']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<br>
<input type="submit" name="submit" value="Submit">
</form>
</div>
<div>
<h2>Subjects selected:</h2>
<?php
if (isset($_POST['submit'])){
foreach ($_POST['id'] as $id):
$sq=mysqli_query($conn,"select * from `subjects` where subject='$id'");
$srow=mysqli_fetch_array($sq);
?>
<button class="button">
<span>
<?php echo $srow['subject']; ?>
</span>
</button>
<?php
endforeach;
}
?>
</div>
I think you will use JavaScript for this I'm giving you syntax in JavaScript, because JavaScript is the best way to make it dynamic.
First arrange PHP code
include 'get.php';
$query = mysqli_query($conn, "select * from `subjects`");
while ($row = mysqli_fetch_array($query)) {
$subject = $row['subject'];
echo "<tr>
<td><input type='checkbox' onclick='validate()' value='".$subject."' name='id[]' id='myCheck'></td>
<td> ".$subject."</td>
</tr>";
?>
Then JavaScript
function validate() {
var check = document.getElementById("myCheck").checked = true;
var val = document.getElementById("myCheck").value;
document.getElementById("myCheck").style.display = "none";
document.getElementById("myBtn").style.display = "block";
document.getElementById("myBtn").value = val;
}
Button
<button class="button animate" id="myBtn">
Adding animation to button
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
#-webkit-keyframes animatezoom {
from {-webkit-transform: scale(0)}
to {-webkit-transform: scale(1)}
}
#keyframes animatezoom {
from {transform: scale(0)}
to {transform: scale(1)}
}
You need to put <button class="button"> inside foreach, mitkosoft thats right.

execution of isset before click the save button in php

I am having two php files, one contains a form and another to display the content entered and save button. After confirming the details are correct he has to save and the data should be inserted into the table. I have given the code below
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
</head>
<body>
<?php
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
?>
<div class="container container-center">
<!-------------total panel------------------------------------>
<div class="panel-info">
<!------panel heading------>
<div class="panel-heading">
<h2><center><u>STUDENT DETAILS</u></center></h2>
</div> <!-panel heading->
<div class="panel-body">
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo"".strtoupper($roll).""; ?></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo"".strtoupper($sname).""; ?></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo"".strtoupper($fname).""; ?></td>
</tr>
<tr>
<td>4. Gender:</td>
<td><?php
if($gender=='M')
{ echo"Male";}
else
{echo"Female";}
?></td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo"$aadhar"; ?></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo"$caste"; ?></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['submit']))
{
echo"<script>alert('success')</script>";
}
?>
</body>
when i click the save button then only the data must be saved. but even if not click the save the php code in isset is executing.
the data obtained by $_POST is from the form.
Please help me.
NOTE:
Actually Problem is that, you don't get the data on this page.. in your POST request with given variable so that Please Just Check it . Other Code Is Fine. !! ( Here I am Just Pass Dummy Data ) Like Below.
$roll= '1234';
$sname='XYZ';
$fname= 'ABC';
$gender= 'M';
$aadhar= '123456789100';
$caste= 'A12345';
Solution: You Have To Get DATA Here in post request from your first_php_page form where user enter the details regarding given fields: roll,sname,fname,gender,aadhar,caste
After here in secound_php_page check that Submit button is set then store the values in varable Like below Code:
NOTE: At The End YoU Have To Write The Insert Query On Save Button Click. To Store The data in Database.
<?php
if(isset($_POST['Submit'])){
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
</head>
<body>
<?php
/*
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
*/
// SET THE DUMMY DATA FOR Result check
$roll= '1234';
$sname='XYZ';
$fname= 'ABC';
$gender= 'M';
$aadhar= '123456789100';
$caste= 'A12345';
?>
<div class="container container-center">
<!-- total panel -->
<div class="panel-info">
<!-- panel heading -->
<div class="panel-heading">
<h2><center><u>STUDENT DETAILS</u></center></h2>
</div>
<!--panel heading -->
<div class="panel-body">
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo"".strtoupper($roll).""; ?></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo"".strtoupper($sname).""; ?></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo"".strtoupper($fname).""; ?></td>
</tr>
<tr>
<td>4. Gender:</td>
<td><?php
if($gender=='M')
{ echo"Male";}
else
{echo"Female";}
?></td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo"$aadhar"; ?></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo"$caste"; ?></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['submit']))
{
echo"<script>alert('success')</script>";
}
?>
</body>
</HTML>
OUTPUT: DATA Display
AND ONCLICK SAVE
There are few issues with your code, such as:
There's no point having a form and save button(in another page) if you don't have input elements and don't send your data using $_POST superglobal. Create input elements for each of your fields with type="hidden", for example like this:
<td><?php echo strtoupper($roll); ?><input type="hidden" name="roll" value="<?php echo strtoupper($roll); ?>"></td>
Here's the full form code,
// your code
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo strtoupper($roll); ?><input type="hidden" name="roll" value="<?php echo strtoupper($roll); ?>"></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo strtoupper($sname); ?><input type="hidden" name="sname" value="<?php echo strtoupper($sname); ?>"></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo strtoupper($fname); ?><input type="hidden" name="fname" value="<?php echo strtoupper($fname); ?>"></td>
</tr>
<tr>
<td>4. Gender:</td>
<td>
<?php
if($gender=='M'){
echo"Male";
}else{
echo"Female";
}
?>
<input type="hidden" name="gender" value="<?php echo $gender; ?>">
</td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo $aadhar; ?><input type="hidden" name="aadhar" value="<?php echo $aadhar; ?>"></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo $caste; ?><input type="hidden" name="caste" value="<?php echo $caste; ?>"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
// your code
I don't see any code where you're inserting the form data into the table, you should have a code block like this in another page(where you have displayed the form data and has the save button):
if(isset($_POST['submit'])){
$roll = $_POST['roll'];
$sname = $_POST['sname'];
$fname = $_POST['fname'];
$gender = $_POST['gender'];
$aadhar = $_POST['aadhar'];
$caste = $_POST['caste'];
// your INSERT operation
}

Can't seem to add simple user input to my DB via a form

This is very quick.
I have a form that when submitted should add user input into my DB. I have had a similar form working well but for some reason this one is not working.
Please excuse my sloppy code but here is the whole page. For some reason 'observation' will not take the user input and display it on the next page (showOne.php). The next page simply shows a blank space for observation and I checked the DB and there was nothing in the observation field of course.
Is it something simple that I can't see? I've been at this for days since it is identical to another form I have that works well on another page.
Thank you for any insight.
<?php
//including the database connection file
include("config.php");
$activePage = "start.php";
if(isset($_POST['update'])) {
$id = $_POST['id'];
$observation = $_POST['observation'];
$result = mysqli_query($mysqli, "UPDATE tasks SET observation='$observation' WHERE id=$id");
header("Location: showOne.php?id=$id");
}
//getting id from url
$id = $_GET['id'];
//selecting data associated with this particular id
$result2 = mysqli_query($mysqli, "SELECT * FROM users WHERE id=$id ORDER BY id ASC");
$result = mysqli_query($mysqli, "SELECT * FROM tasks ORDER BY taskNumber ASC");
include_once "nav.php";
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Pathfinder - A User Testing Dashboard</title>
<meta name="description" content="Pathfinder - A User Testing Dashboard">
<meta name="author" content="James Stables - Thurs April 13th 2017">
<link rel="stylesheet" href="core.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700" rel="stylesheet">
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"> </script>
<![endif]-->
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<header>
<h1 class="logo"><img src="images/logo.png">Pathfinder</h1>
<h4>User Testing Dashboard</h4>
</header>
<section class="nonav">
<div class="showAllUsers">
<table border='0'>
<tr>
<?php while($res = mysqli_fetch_array($result2))
{ ?>
<td class="widthHundred no-border left"><h2><?php echo $res['nameFirst']; ?></h2></td>
<?php } ?>
</tr>
</table>
<table border='0'>
<thead>
<tr>
<th>Image</th>
<th>Category</th>
<th>Task Number</th>
<th>Task Name</th>
<th>Observation</th>
<td> </td>
<td> </td>
<td> </td>
</tr>
</thead>
<tbody>
<form name="start" method="post" action="start.php" enctype="multipart/form-data">
<tr>
<td><a href="<?php echo $res['$image'];?>" data-lightbox="example-1" data-title="Task Number <?php echo $res['taskNumber'];?>">
<img id="imageResize" src="<?php echo $res['image'];?>" /></a></td>
<td><?php echo $res['category'];?></td>
<td><?php echo $res['taskNumber'];?></td>
<td><?php echo $res['taskName'];?></td>
<td><input type="text" name="observation" value="<?php echo $res['observation'];?>"></td>
<td> </td>
<td> </td>
<td> </td>
<?php } ?>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input type="hidden" name="id" value="<?php echo $_GET['id'];?>"><input type="submit" class="buttonUpdate right" name="update" value="Update"></td>
<td><a class="buttonCancel right" href="tasks.php" onClick="return confirm('Cancel and go back?')">Cancel</a></td>
</tr>
</form>
</tbody>
</table>
</div>
</section>
<script src="js/lightbox-plus-jquery.min.js"></script>
<script>
lightbox.option({
'resizeDuration': 200,
'showImageNumberLabel': false,
'fitImagesInViewport': true
})
</script>
</body>
</html>

I dont want to reload all the php page after dropbox selection

I have a php page to present in a table characteristics after you select a name in a dropbox. But when you make a selection all the page is reloaded and dublicate the upper div that I have.
<?php include("datalogin.php"); ?>
<!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" />
<title>Ιατρείο Πόνου</title>
<!-- Add jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<!-- Add fancyBox -->
<link rel="stylesheet" href="fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
<script type="text/javascript" src="fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
<!-- Optionally add helpers - button, thumbnail and/or media -->
<link rel="stylesheet" href="fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.5" type="text/css" media="screen" />
<script type="text/javascript" src="fancybox/source/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>
<script type="text/javascript" src="fancybox/source/helpers/jquery.fancybox-media.js?v=1.0.6"></script>
<link rel="stylesheet" href="fancybox/source/helpers/jquery.fancybox-thumbs.css?v=1.0.7" type="text/css" media="screen" />
<script type="text/javascript" src="fancybox/source/helpers/jquery.fancybox-thumbs.js?v=1.0.7"></script>
<link href="template.css" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=1.4.2"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/interface.js"></script>
<script>
function showDetails(id)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("details").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","patients.php?q="+id,true);
xmlhttp.send();
}
</script>
<?php
date_default_timezone_set("Europe/Athens");
?>
<script type="text/javascript">
function checkWindowSize() {
if ( $(window).height() > 800 ) {
document.getElementById('sidebar').class="large");
$('sidebar').addClass('large');
}
else {
$('body').removeClass('large');
}
}
$(window).resize(checkWindowSize);
</script>
<!--[if lt IE 7]>
<style type="text/css">
div, img { behavior: url(iepngfix.htc) }
</style>
<![endif]-->
</head>
<body onload="checkWindowSize();">
<div>
<div id="sidebar">
<p align="center" style="font-size:21px">Ιατρείο Πόνου<br/>Σελίδα Διαχείρισης</p>
<?php if( (session_is_registered("username")) ) {?>
<p align="center" style="font-size:19px;">Καλως ήλθες <b><span class="yellow"><?php echo $_SESSION['username'];?></span></b>. <br/> Αποσύνδεση</p>
<?php } ?>
<ul id="main-nav">
<li>Ασθενείς </li>
<li>Επιτυχόντες </li>
<li>Σχέδια </li>
<li>Ρυθμίσεις Λογαριασμού</li>
</li>
</ul>
<div id="top_menu">
<ul id="links" class="clear">
<li>Η ΣΧΟΛΗ ΜΑΣ</li>
<li>ΑΡΧΙΤΕΚΤΟΝΙΚΗ-ΤΕΙ</li>
<li>ΚΑΛΩΝ ΤΕΧΝΩΝ</li>
<li>PORTFOLIO</li>
<li>ΣΧΕΔΙΑ</li>
<li>ΣΧΟΛΕΣ ΜΕ ΣΧΕΔΙΟ</li>
<li>ΑΝΑΚΟΙΝΩΣΕΙΣ</li>
<li>ΕΠΙΤΥΧΟΝΤΕΣ</li>
<li>FAQ</li>
<li>ΕΠΙΚΟΙΝΩΝΙΑ</li>
</ul>
</div>
</div>
<div id="main-content">
<div class="dock" id="dock">
<div class="dock-container">
<a class="dock-item" href="patients.php"><img src="images/announcement.png" alt="Ανακοινώσεις" /><span>Ανακοινώσεις</span></a>
<a class="dock-item" href="success.php"><img src="images/success.png" alt="Επιτυχόντες" /><span>Επιτυχόντες</span></a>
<a class="dock-item" href="gallery.php"><img src="images/gallery.png" alt="Σχέδια" /><span>Σχέδια</span></a>
<a class="dock-item" href="settings.php"><img src="images/settings.png" alt="Ρυθμίσεις Λογαριασμού" /><span>Ρυθμίσεις Λογαριασμού</span></a>
</div>
</div>
<script type="text/javascript">
$(document).ready(
function()
{
$('#dock').Fisheye(
{
maxWidth: 64,
items: 'a',
itemsText: 'span',
container: '.dock-container',
itemWidth: 50,
proximity: 90,
halign : 'center'
}
)
}
);
</script>
<h2>Ασθενείς</h2>
<div align="right"><table><tr><td align="center"><img src="images/new.png" alt="Νέα Ανακοίνωση"/></td></tr><tr><td>Νέος Ασθενής</td></tr></table></div>
<p></p>
<div align="center" id='details'>Επιλέξτε Ασθενή:
<select name="users" onchange="showDetails(this.value)">
<option value="result">Select</option>
<?php
$id=$_GET['q'];
echo $result = mysql_query("SELECT pa_id, pa_surname, pa_name FROM patient ORDER BY pa_surname");
while ($row = mysql_fetch_array($result))
{
echo "<option value='".$row["pa_id"]. "'";
if($row["pa_id"]==$id) { echo " selected";}
echo ">".$row["pa_surname"]." ".$row["pa_name"]."</option>";
}?>
</select>
</div>
<?php
$details_query= mysql_query("SELECT * FROM patient WHERE pa_id='".$id."'");
while ($details = mysql_fetch_array($details_query))
{ ?>
<p></p>
<div align="center">
<table width="100%" class="box-table-a">
<tr>
<th colspan="5"><div align="center">Στοιχεία Ασθενή</div></th>
</tr>
<tr>
<td>Όνομα :</td>
<td><?php echo $details['pa_name'];?></td>
</tr>
<tr>
<td>Επίθετο :</td>
<td><?php echo $details['pa_surname'];?></td>
</tr>
<tr>
<td>Φύλλο :</td>
<td>
<?php
$sex_query= mysql_query("SELECT * FROM sex WHERE sex_id='".$details['sex_id']."'");
$sex1 = mysql_fetch_array($sex_query);
echo $sex1['sex_name'];?></td>
</tr>
<tr>
<td>Ημερ/νία Γέννησης :</td>
<td>
<?php
$phpdate = strtotime( $details['pa_birth'] );
$mysqldate = date( 'd-m-Y', $phpdate );
echo $mysqldate;
echo " ";
$bday = new DateTime($details['pa_birth']);
// $today = new DateTime('00:00:00'); - use this for the current date
$today = new DateTime(); // for testing purposes
$diff = $today->diff($bday);
printf('( %d Ετών )', $diff->y);
?>
</td>
</tr>
<tr>
<td >Διεύθυνση κατοικίας :</td>
<td><?php echo $details['pa_address'];?></td>
</tr>
<tr>
<td>Περιοχή :</td>
<td><?php echo $details['pa_area'];?></td>
</tr>
<tr>
<td>Πόλη :</td>
<td><?php echo $details['pa_city'];?></td>
</tr>
<tr>
<td>Τ.Κ. :</td>
<td><?php echo $details['pa_tk'];?></td>
</tr>
<tr>
<td>Τηλέφωνο :</td>
<td><?php echo $details['pa_tel'];?></td>
</tr>
<tr>
<td>Κινητό :</td>
<td><?php echo $details['pa_tel2'];?></td>
</tr>
<tr>
<td>E mail :</td>
<td><?php echo $details['pa_mail'];?></td>
</tr>
<tr>
<td>Ταμείο :</td>
<td>
<?php
$asfalisi_query= mysql_query("SELECT * FROM asfalisi WHERE asfalisi_id='".$details['asfalisi_id']."'");
$asfalisi1 = mysql_fetch_array($asfalisi_query);
echo $asfalisi1['asfalisi_name'];?></td>
</tr>
<tr>
<td>Παραπέμπων Ιατρός:</td>
<td><?php echo $details['doctor_come'];?></td>
</tr>
<tr>
<td>Ιστορικό :</td>
<td><?php echo $details['pa_history'];?></td>
</tr>
<tr>
<td>Φάρμακα που έπερνε :</td>
<td><?php echo $details['pa_farmaka'];?></td>
</tr>
<tr>
<td>Σχόλια :</td>
<td><?php echo $details['pa_com'];?></td>
</tr>
<tr>
<td>Πάθηση :</td>
<td>
<?php
$pathisi1= mysql_query("SELECT path_id FROM meeting WHERE pa_id= 1 ORDER BY path_id DESC LIMIT 1");
$pathisi2 = mysql_fetch_array($pathisi1);
$pathisi_query= mysql_query("SELECT * FROM pathiseis WHERE path_id='".$pathisi2['path_id']."'");
$pathisi = mysql_fetch_array($pathisi_query);
echo $pathisi['path_name'];?></td>
</tr>
<tr>
<td>Θεραπεία :</td>
<td>
<?php
$therapy1= mysql_query("SELECT ther_id FROM meeting WHERE pa_id= 1 ORDER BY ther_id DESC LIMIT 1");
$therapy2 = mysql_fetch_array($therapy1);
$therapy_query= mysql_query("SELECT * FROM therapy WHERE ther_id='".$therapy2['ther_id']."'");
$therapy = mysql_fetch_array($therapy_query);
echo $therapy['ther_name'];?></td>
</tr>
</table>
<p></p>
<table width="100%" class="box-table-a">
<tr>
<th colspan="2"><div align="center">Εξετάσεις</div></th>
</tr>
<?php
$result1 = mysql_query("SELECT * FROM document WHERE pa_id='".$id."'");
while ($row = mysql_fetch_array($result1)) {
?>
<tr>
<td><?php echo "<li><a href='eggrafa/".$id."/".$row['document_link']."' target='blank'>".$row['document_title']."</a></li> ";?></td>
<?php } ?>
</tr>
</table>
<p></p>
<table width="100%" class="box-table-a">
<tr>
<th colspan="2"><div align="center">Επισκέψεις</div></th>
</tr>
<?php
$result2 = mysql_query("SELECT * FROM meeting WHERE pa_id='".$id."' ORDER BY meet_id ASC ");
while ($row2 = mysql_fetch_array($result2)) {
?>
<tr>
<td colspan="2"><?php echo "<li><a href='meeting.php?id=".$row2['meet_id']."' class='fancybox'>";$phpdate = strtotime( $row2['meet_date'] );
$mysqldate = date( 'd-m-Y', $phpdate );
echo $mysqldate;"</a></li> ";?></td>
<?php } ?>
</tr>
<tr>
<th colspan="2"><div align="center">Επόμενο ραντεβού</div></th>
</tr>
<?php
$result3 = mysql_query("SELECT * FROM meeting WHERE pa_id='".$id."' ORDER BY meet_id DESC LIMIT 1" );
$result4 = mysql_fetch_array($result3);{
?>
<tr>
<td width="20%">Ημερομηνία:</td>
<td><?php $phpdate2 = $result4['next_date'] ;
if(($result4['next_date'])=='0000-00-00')
{
$mysqldate3 ='Δεν έχει καθοριστεί επόμενο ραντεβού';
echo $mysqldate3;
}
else
{
$mysqldate3 = date('d-m-Y', strtotime($result4['next_date']));
echo $mysqldate3;
}
?>
</td>
</tr>
</tr>
<tr>
<td width="20%">Τοποθεσία :</td>
<td>
<?php
$company_query8= mysql_query("SELECT * FROM mplace WHERE mp_id='".$result4['mp3_id']."'");
$company8 = mysql_fetch_array($company_query8);
echo $company8['mp_name'];?></td>
</tr>
<?php } ?>
</table>
</div>
<?php } ?>
<p></p>
<p></p>
</div>
</div>
</body>
</html>
so i want to reload after the "Επιλέξτε Ασθενή:"
help please

PHP-jQuery Displaying items properly

I have a problem. I want to display every "subject" (titles) in the page and not only the first one like now. When I add a new message, index only displays the first one, and only when I click on the "open" button I can see all the messages.
Any suggestion?
Many thanks.
This is de code:
<?php
require_once("config.php");
if (isset($_SESSION['username']) === FALSE){
header('location:login.php');
exit();
}
$where = "";
$searchCriteria = "";
if (isset($_GET['search']) && $_GET['search'] != '') {
$searchCriteria = mysql_real_escape_string($_GET['search']);
$where = " WHERE subject LIKE '%" . $searchCriteria . "%'";
$where .= " OR message like '%" . $searchCriteria . "%'";
}
$sql = "SELECT * FROM notes " . $where . " LIMIT 30";
$result = mysql_query($sql);
?>
<!DOCTYPE html>
html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
Logout<br/><br/>
<div id="wrapper">
<div id="add-message">
<img src="images/add.png" title="Add"> Add a New Message
</div>
<br>
<?php
while ($row = mysql_fetch_assoc($result)) {
?>
<?php echo $row['subject']; ?>
<input type="button" id="opener" value="Open"/>
<div id="playbox">
<table id="general">
<thead>
<tr>
<th class="general-header"></th>
<th class="general-subject">Subject</th>
<th class="general-message">Message</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4" class="general-foot"><input type="button" id="closer" value="Close"/></td>
</tr>
</tfoot>
<tbody>
<tr>
<td>
<img src="images/edit.png" title="Edit"> Edit
|
<img src="images/delete.png" title="Delete"> Delete
</td>
<td class="subject"><?php echo $row['subject']; ?></td>
<td><?php if ($row['filename']!=''){?>
<img align="right" width="300px" src="<?php echo $row['filename']; ?>" />
<?php } ?>
<?php echo $row['message']; ?>
</td>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$("#playbox").hide();
$("#opener").click(function(){
$("#playbox").slideDown(600);
});
$("#closer").click(function(){
$("#playbox").slideUp(600);
});
});
</script>
I think you should use mysql_num_rows for that and you don't have need that you create many open and close buttons in while loop, just add this once like if you records then, for that you have to add if condition like if(mysql-num_rows($result))
Full Code
<?php
require_once("config.php");
if (isset($_SESSION['username']) or $_SESSION['username']=== FALSE){
header('location:login.php');
exit();
}
$where = "";
$searchCriteria = "";
if (isset($_GET['search']) && $_GET['search'] != '') {
$searchCriteria = mysql_real_escape_string($_GET['search']);
$where = " WHERE subject LIKE '%" . $searchCriteria . "%'";
$where .= " OR message like '%" . $searchCriteria . "%'";
}
$sql = "SELECT * FROM notes " . $where . " LIMIT 30";
$result = mysql_query($sql);
?>
<!DOCTYPE html>
html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
Logout<br/><br/>
<div id="wrapper">
<div id="add-message">
<img src="images/add.png" title="Add"> Add a New Message
</div>
<br>
<?php
if(mysql_num_rows($result))
{
?>
<input type="button" id="opener" value="Open"/>
<div id="playbox">
<table id="general">
<thead>
<tr>
<th class="general-header"></th>
<th class="general-subject">Subject</th>
<th class="general-message">Message</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4" class="general-foot"><input type="button" id="closer" value="Close"/></td>
</tr>
</tfoot>
<?php
while ($row = mysql_fetch_assoc($result)) {
?>
<?php echo $row['subject']; ?>
<tbody>
<tr>
<td>
<img src="images/edit.png" title="Edit"> Edit
|
<img src="images/delete.png" title="Delete"> Delete
</td>
<td class="subject"><?php echo $row['subject']; ?></td>
<td><?php if ($row['filename']!=''){?>
<img align="right" width="300px" src="<?php echo $row['filename']; ?>" />
<?php } ?>
<?php echo $row['message']; ?>
</td>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
<?php
}
?>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$("#playbox").hide();
$("#opener").click(function(){
$("#playbox").slideDown(600);
});
$("#closer").click(function(){
$("#playbox").slideUp(600);
});
});
</script>
If you want to toggle it separately then you have to code like,
HTML
Let there are two records Create the HTML like using while loop
<div class="contentSubject">
<input type="button" class="btnOpener" value="Open" />
<div class="playbox">
<!--your table goes here-->
</div>
</div>
<div class="contentSubject">
<input type="button" class="btnOpener" value="Open" />
<div class="playbox">
//your table goes here
</div>
</div>
SCRIPT
<script>
$(document).ready(function(){
$(".playbox").hide();
$(".btnOpener").click(function(){
$(this).closest('.contentSubject')
.find(".playbox").slideDown(600);
});
// same code for close
});
</script>
please try that code
$("#opener").live("click",function(){
$("#playbox").slideDown(600);
});

Categories