The problem is $_POST["nomuniv"] & cod $_POST["coduniv"], they are empty and I do not understand why despite all of input names being correct.
webpage1:
<style type="text/css">
input[type=text],button{
width: 100%;padding: 12px 20px;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;`enter code here`
box-sizing: border-box;
}
::-webkit-input-placeholder {
font-size: 13px;
color: #000;
}
</style>
<?php
include 'fonctionUnivesrite.php';
$array = selectFCT();//selection data from DB
for ($i = 0; $i < count($array); $i++) {
?>
<form method="post" action="../universites/supprimer_universite.php?id=<?php echo $array[$i][0]; ?>">
<table class="table table-striped " style="width: 70%;" align="center">
<tr>
<td style="width: 5%;" ><?php echo $i; ?> </td>
<td style="width: 30%;">
<input type="text" name="nomuniv" id="nomuniv" placeholder="<?php echo $array[$i][1]; ?>">
</td>
<td style="width: 20%;">
<input type="text" name="coduniv" id="coduniv" placeholder="<?php echo $array[$i][2]; ?>" >
</td>
<td style="width: 10%;">
<input type="submit" name="modifier" class="btn btn-warning" value="Modifier">
</td>
<td style="width: 10%;">
<input type="submit" name="supprimer" class="btn btn-danger" value="Supprimer">
</td>
</tr>
<?php
}
?>
</table>
</form>
webpage2:../universites/supprimer_universite.php
include './fonctionUnivesrite.php';
if (isset($_GET["id"])) {
if(isset($_POST["modifier"])){
try {
echo $_GET["id"]." nom ".$_POST["nomuniv"]." cod ".$_POST["coduniv"];
modifierFCT($_GET["id"],$_POST["nomuniv"],$_POST["coduniv"]);
//echo $_GET["id"]." nom ".$_POST["nomuniv"]." cod ".$_POST["coduniv"];
} catch (Exception $exc) {
echo "Error : " . $exc->getMessage();
}
}
elseif(isset($_POST["supprimer"])) {
try {
deletFCT($_GET["id"]);
} catch (Exception $exc) {
echo "Error : " . $exc->getMessage();
}
}
}
Your problem is simple ,
You didnt add a value attribute to the input fileds ,
In webpage 1
Try to add inside
<input value=" your php code " />
Since when you use $_POST it will access the value , according to the name
Related
I have multiple divs , show/hide on button click div , inside one of these divs I have a table and to filter this table to search a specific user I use a PHP code and a submit form the problem is after submitting the form the page refreshes and the 1st div appears although the request worked and when I revisit the table div the filtering appears. I used this code to stop the refresh but the form is not being submitted:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('#myform').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'admin.php',
data: $('#myform').serialize(),
success: function () {
alert('table is filtered');
}
});
});
});
</script>
and here is my form:
<div class="in5 n5" id="users">
<br>
<form method="post" action="" id="myform" >
<table style="width:25%;height: 13%;table-layout: fixed; font-family: signika;background-color:white;color:white;border-bottom:1px solid white;">
<tr>
<td width="30%" style="text-align:center;">
<button style="width:100%;height: 100%;border:0; font-size: 20px;font-family: signika;background: transparent;">Show all</button>
</td>
<td>
<div style="height:100%;width: 100%;">
<input type="text" name="valueToSearch" placeholder="Search user" style="height:100%;width: 70%; font-size: 20px;" >
<input value="Search" id="search" name="search" type="submit" style="width:30%; height: 100%; float: right; background-color: gray; color:white; font-size: 20px; ">
</div>
</td>
</tr>
</table>
<table style="width:100%;height:10%; background-color: white; font-size: 20px; border-bottom: 1px solid #cccccc; table-layout: fixed;border-collapse: collapse;">
<tr>
<td style="width:3%;">ID</td>
<td style="width:10%;">Username</td>
<td style="width:10%;">Email</td>
<td style="width:10%;">First name</td>
<td style="width:10%;">Last name</td>
<td style="width:5%;">Gender</td>
<td style="width:10%;">Birthday</td>
<td style="width:8%;">Country</td>
<td style="width:7%;">City</td>
<td style="width:10%;">Bio</td>
<td style="width:5%;">Access</td>
<td style="width:7%;">Picture</td>
<td style="width:5%;">Ban user</td>
</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr >
<td style="width:3%; overflow: hidden;" title="<?php echo $row[0]; ?>">
<input style="border:0;background: transparent; font-size: 20px;" readonly="readonly" name="id" value="<?php echo $row[0]; ?>">
</td>
<td style="width:10%; overflow: hidden;" title="<?php echo $row[1]; ?>"><?php echo $row[1]; ?></td>
<td style="width:10%; overflow: hidden;" title="<?php echo $row[2]; ?>"><?php echo $row[2]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[4]; ?>"><?php echo $row[4]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[5]; ?>"><?php echo $row[5]; ?></td>
<td style="width:5%; overflow: hidden;"title="<?php echo $row[6]; ?>"><?php echo $row[6]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[7]; ?>"><?php echo $row[7]; ?></td>
<td style="width:8%; overflow: hidden;"title="<?php echo $row[8]; ?>"><?php echo $row[8]; ?></td>
<td style="width:7%; overflow: hidden;"title="<?php echo $row[9]; ?>"><?php echo $row[9]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[11]; ?>"><?php echo $row[11]; ?></td>
<td style="width:5%; overflow: hidden;">
<?php if($row['12']=="moderate"){ ?>
<a href="lock.php?id=<?php echo $row[0]; ?>">
<img class="img2" src="icons/access.png" ></a>
<?php } else{ ?>
<a href="access.php?id=<?php echo $row[0]; ?>">
<img class="img2" src="icons/locked.png" >
</a> <?php } ?>
</td>
<td style="width:7%; overflow: hidden;">
<a href="#image" title="See profile picture" class="cover" >
<?php if($row[10]==""){ ?>
<img class="cimg2 " src="images/profile.png"> <?php
} else { ?>
<img class="cimg2 " src="img/<?php echo $row[10] ?>" >
<?php }?>
</a>
</td>
<td style="width:5%; overflow: hidden;">
<a title="Delete user" href="deleteuser.php?id=<?php echo $row[0]; ?>" style="border:0;background: transparent;">
<img src="icons/ban.png"></a></td>
</tr>
<?php endwhile;?>
</table>
</form>
and the PHP code:
<?
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `r` WHERE CONCAT(`id`, `username`,`email`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `r`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "x");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
the problem is on submit the page is not refreshing and the alert appears but also the table is not filtering.
Use on click not on submit and input type button
$('#myform').on('click', function (e) {
Oops! You missed a concept also ! When using ajax you need to manipulate your DOM(Document Object Model) by yourself on callback functions
You are missing return false; at the end of submit event. The form submit event when customized and e.preventDefault() is used then your implementation overrides the default behavior thus it needs to tell the form if it needs to submit the whole page or not.
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('#myform').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'admin.php',
data: $('#myform').serialize(),
success: function () {
//filter the table using javascript code by changing the elements etc.
alert('table is filtered');
}
});
return false;
});
});
</script>
If this not works then there must be some uncertainty like there may be some **runtime error ** which is preventing your script to propagate.
In this below code i am searching a value.if the value is searched it displays the result but if the value is not present it should displays no result. In my case if i execute and not search any value it displays no record .Please any one help me.
<form action="<?php echo site_url('search1_site/index');?>" method = "post">
<input type="text" name = "keyword" />
<input type="submit" id="opn" value = "Search" />
</form>
<?php
if($results){
?> <div id='hideme'>
CLOSE<a href='#' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" >
<table class="display2 table table-bordered table-striped">
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo "no results";
}
?>
</table></div></div>
<script>
$('a.modal').bind('click', function(event) {
event.preventDefault();
$('#modal').fadeIn(10);
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
</script>
Try adding name attribute to your submit button and check if it's set before the if...else block.
<!-- HTML -->
<input type="submit" name="submit" id="opn" value = "Search" />
// PHP
<?php
if (isset($_POST['submit'])) { // Here
// Do the search here
if($results){
?> <div id='hideme'>
CLOSE<a href='#' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" >
<table class="display2 table table-bordered table-striped">
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo "no results";
}
} // If closing
?>
Is this something similar to what you're looking for?
If the variable $results is array of results use something like this:
if (count($results) > 0)
{
// show results
} else
{
echo "No results";
}
This is the full code of the page which i am using to update data.I Tried many time but it still not updating values in database..also tried to echo but still not updating
<?php
session_start();
include '../func-tion/func.php';
if(isset($_SESSION['m_uname']) && isset($_SESSION['m_pass']))
{
?>
<?php
if(isset($_POST['subup']))
{
$SQL="update appid set android_appid='".$_POST['and_a']."' , iphone_appid='".$_POST['iph_a']."' , ipad_appid='".$_POST['ipa_a']."' where u_name='".$_GET['name']."'";
echo $SQL;
}
?>
<?php
$main_qry=mysql_query("select * from users where u_name='".$_GET['name']."'");
$main_fetch=mysql_fetch_assoc($main_qry);
?>
<center><h2 class="art-postheader">Edit details of <b></b></h2></center><br/><br/>
<table align="center">
<tr align="center">
<td style="height: 60px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Username:<br>
<input type="text" name="u_name" style="width: 300px;" value="<?php echo $main_fetch['u_name']?>"></td>
</tr>
<tr align="center">
<td style="height: 60px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Email:<br>
<input type="text" name="u_email" style="width: 300px;" value="<?php echo $main_fetch['u_email']?>"></td>
</tr><?php
$main_qrys=mysql_query("select * from appid where u_name='".$_GET['name']."'");
$row=mysql_fetch_assoc($main_qrys);
?> <form name="user" method="post" action="users_edit.php" onSubmit="return valid();">
<tr align="center">
<td style="width: 100px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Android Appid:<br>
<input type="text" name="and_a" style="width: 300px;" value="<?php echo $row['android_appid']?>"></td>
</tr>
<tr align="center">
<td style="width: 100px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Iphone Appid:<br>
<input type="text" name="iph_a" style="width: 300px;" value="<?php echo $row['iphone_appid']?>"></td>
</tr>
<tr align="center">
<td style="width: 100px; font-family: Helvetica,Arial,sans-serif; font-weight: bold;">Iphone(ipad) Appid:<br>
<input type="text" name="ipa_a" style="width: 300px;" value="<?php echo $row['ipad_appid']?>"></td>
</tr>
<tr align="center">
<td style="height: 28px;">
<button name="subup" type="submit">Edit</button>
</td>
</tr>
</form>
</table>
</div>
</div>
</div>
</div>
</div>
</body></html>
<?php
}
else
{
header("Location:notserver.php?l=fake");
}
?>
if anyone know..Please help me i will be very thankfull to him
Use the query:
UPDATE appid
set android_appid='$android_appid', iphone_appid='$iphone_appid', ipad_appid='$ipad_appid'
where u_name IN (select u_name from users where u_id = $_GET[id])
I wonder why you're using $_GET['id'] rather than $_POST['id'] like the other parameters in your script. Make sure that's correct. And you should check for errors from mysql_query(); if it returns false, print mysql_error() to see the reason.
This is my code; I will tell you the issue then.
<?php
//checking for perfect loging
session_start();
$user_name = $_SESSION['username'];
$user_pass = $_SESSION['password'];
require ("connection.php");
if ( $user_name == '' ) {
header('location:home.php');
exit();
}
/////////////////////////////////////
?>
<?php
//collecting posted variables by pressing addanother button
if(isset($_POST['adnother'])) {
$date = $_POST['date'];
$billnmbr = $_POST['billnmbr'];
$itemcode = $_POST['itemcode'];
$itemname = $_POST['itemname'];
$exdate = $_POST['exdate'];
$eachprice = $_POST['eachprice'];
$itmtotal = $_POST['itmtotal'];
$wasFound=false;
$i=0;
// check for >>>>>>>>>>> if the session bill_array array is not set or cart array is empty <<<<<<<<<<<<<<<
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
// Run if the bill_array is empty or not set
$_SESSION["bill_array"]= array(1 => array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
} else {
// Run if the bill has at least one item in it
foreach($_SESSION["bill_array"] as $each_item) {
$i++;
while(list($key,$value)=each($each_item)){
if($key=="itemcode" && $value == $itemcode){
// That item is in cart already so push a error message in to screen
$wasFound = true;
?>
<script type="text/javascript">
var error = "<?= $wasFound ?>";
if(error == "true") {
alert("You trying to add same item twice")
}
</script>
<?php
}//close if condition
}//close while loop
}//close foreach loop
//if the next item is not in the bill and then add it to the bill_array
if($wasFound==false){
array_push($_SESSION["bill_array"],array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
}//clos if condition
}//close else statment
}//close ifisset
?>
<!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>Front-end Billing</title>
<link href="main.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
.mainheder {
font-size: 36px;
font-weight: bolder;
color: #00C;
text-align: center;
}
#headertopic {
position:absolute;
left:304px;
top:1px;
width:395px;
height:44px;
z-index:1;
background-color: #999900;
}
#mainmenue {
position:absolute;
left:208px;
top:78px;
width:614px;
height:48px;
z-index:10000;
}
#dateandtime {
position:absolute;
left:790px;
top:251px;
width:208px;
height:82px;
z-index:1;
}
#redcross {
position:absolute;
left:377px;
top:321px;
width:247px;
height:239px;
z-index:0;
}
#usrlogin {
position:absolute;
left:4px;
top:216px;
width:265px;
height:184px;
z-index:1;
}
#address {
position:absolute;
left:2px;
top:462px;
width:204px;
height:155px;
z-index:2;
}
#logdas {
position:absolute;
left:10px;
top:92px;
width:197px;
height:58px;
z-index:1;
}
.logdas {
font-weight: bold;
color: #00F;
}
#pagetheam {
position:absolute;
left:332px;
top:49px;
width:341px;
height:24px;
z-index:1;
text-align: center;
font-size: 18px;
font-weight: bolder;
color: #0CF;
text-decoration: underline;
}
#billingitems {
position:absolute;
left:11px;
top:186px;
width:489px;
height:293px;
z-index:1;
}
#printlayout {
position:absolute;
left:531px;
top:186px;
width:211px;
height:322px;
z-index:1;
text-align: center;
}
.printlayoutshopname {
font-size: 14px;
font-weight: bold;
color: #000;
}
.billaddrs {
font-size: 10px;
}
.bilnmbr {
font-size: 10px;
font-weight: bold;
text-align: left;
}
</style></head>
<body>
<div id="wrap">
<div id="headertopic" class="mainheder">Accoutnig for Phamacy</div>
<p> </p>
<p> </p>
<div id="mainmenue"> <?php // include 'index.html' ;?> </div>
<div id="logdas"><p class="logdas">Logged in as : <?php echo $user_name; ?></p>
<p class="logdas">Date : <?php echo date("Y-m-d") ?></p>
</div>
<div id="pagetheam">Front-end Billing </div>
<div id="billingitems">
<form id="form1" name="form1" method="post" action="biling.php">
<?php $data = mysql_query("SELECT * FROM billnumber ") ;
$info = mysql_fetch_array( $data );
$oldnumber = $info['bill_number'];
$oldnumber= $oldnumber + 1;
$Transaction_number = "PM". $oldnumber ;
?>
<table width="490" height="282" border="0">
<tr>
<td width="160"><input type="hidden" name="date" id="date" value=" <?php echo date("Y-m-d") ?> " /><?php echo date("Y-m-d") ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td width="206">Bill Number</td>
<td width="160"><input type="hidden" name="billnmbr" id="billnmbr" value="<?php echo $Transaction_number; ?>" /><?php echo $Transaction_number; ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td>Item Code</td>
<td><input type="text" name="itemcode" id="itemcode" tabindex="1" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Name</td>
<td><input type="text" name="itemname" id="itemname" tabindex="2" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Expier Date</td>
<td><input type="text" name="exdate" id="exdate" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Price</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Each :
<input type="text" name="eachprice" id="eachprice" /></td>
<td>Total :
<input type="text" name="itmtotal" id="itmtotal" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="adnother" id="adnother" value="add another item" tabindex="5" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
</div>
<div id="printlayout">
<p><span class="printlayoutshopname">Yasitha Pharacy<br />
</span><span class="billaddrs">22,Colombathanthiri Mawatha, Ethulkotte, Kotte.</span></p>
<table width="211" border="0">
<tr>
<td width="103"><span class="bilnmbr">Bill No: <?php echo $Transaction_number; ?></span></td>
<td colspan="2" class="bilnmbr">Date: <?php echo date("Y-m-d") ?></td>
</tr>
<?php
if(isset($_POST['adnother'])) {
//taking items in the bill to variables if the bill_array is not empty.
$cartOutput="";
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
$cartOutput = "<h2 align='center'> Bill is still empty </hd>";
}
else {
$i = 0;
foreach ($_SESSION["bill_array"]as $each_item ): ?>
<tr>
<td class="bilnmbr">Item code: </td>
<td colspan="2" class="bilnmbr"><?php echo $each_item['itemcode']; ?></td>
</tr>
<tr>
<td colspan="3" class="bilnmbr">Item Name:</td>
</tr>
<tr>
<td colspan="3" class="bilnmbr"><?php echo $each_item['itemname']; ?></td>
</tr>
<tr class="bilnmbr">
<td>Each</td>
<td width="98">Qty</td>
<td width="98">Total</td>
</tr>
<tr class="bilnmbr">
<td><?php echo $each_item['eachprice']; ?></td>
<td>20</td>
<td><?php echo $each_item['itmtotal']; ?></td>
</tr>
</table>
<?php endforeach; ?>
<?php
}
}
////////////////////////////////////////
?>
<p>
</p>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php //closing div for wrapper?>
</div>
</body>
</html>
I used two dimensional array for insert item details to a session array, after inserting a item I want its details to be displayed in a separate table (right hand side) there is no problem with one item, when I add a item it is viewing in the perfect place, but when I add the second item it is going under that table without creating new row. What is the wrong with what I had done?
I found my error
i ended my foreach loop like this
</tr>
</table>
<?php endforeach;
}
}
////////////////////////////////////////
?>
but now i corrected to this way
</tr>
<?php endforeach;
}
}
////////////////////////////////////////
?>
</table>
now it's all ok.... thank you guys for wasting your time for my silly mistake... sorry.... :(
I am creating an application like that of Facebook photo albums having comments.
I have a webpage, which shows the pics inside an album, when a pic is clicked, a lightbox opens up, and the caption and comments on the pic will be shown. Here's the pictures.php code
<?php
session_start();
ob_start;
include('connection.php');
?>
<html>
<head>
<title>Photos</title>
<style type="text/css">
.wraptocenter
{
width: 200px;
height: 150px;
overflow: hidden;
}
.wraptocenter img
{
vertical-align: top;
}
.black_overlay
{
display: none;
position: fixed;
top: 0%;
left: 0%;
width: 100.7%;
height: 100%;
background-color: black;
z-index: 1001;
-moz-opacity: 0.8;
opacity: .80;
filter: alpha(opacity=80);
}
.white_imagebox
{
display: none;
position: fixed;
top: 5%;
left: 6%;
width: 900px;
height: 500px;
padding: 0px;
border: 0px solid #a6c25c;
background-color: white;
z-index: 1002;
overflow: visible;
}
</style>
<script type="text/javascript" src="AJAX/AjaxInsertPicComment.js"></script>
<script>
function showpic(image_path,image_id,album_id,pic_caption)
{
document.getElementById('AlbumDiv').style.display = "block";
document.getElementById('fade').style.display = "block";
document.getElementById('image').src = image_path; // this line added
img = new Image();
img.src = image_path;
document.getElementById('t_albumid').value = album_id;
document.getElementById('t_imageid').value = image_id;
document.getElementById('t_albid').value = album_id;
document.getElementById('t_picid').value = image_id;
document.getElementById('albumid').value = album_id;
document.getElementById('imageid').value = image_id;
document.getElementById('t_imagepath').value = image_path;
document.getElementById('caption_holder').value = pic_caption;
if(img.width > 500 && img.height > 450)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
else if(img.height > 450 && img.width < 500)
{
document.getElementById('image').style.height = "450px";
delete img;
return false;
}
else if(img.height < 450 && img.width > 500)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
else if(img.width < 500 && img.height < 450)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
delete img;
alert("humm");
return false;
}
</script>
</head>
<body>
<div id="photo_holder">
<table width="1000px" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td width="50px" align="center"/>
<td align="center" colspan="2" background="Images/header_menu.png" style="padding-right:2px;">
<?php include('header.php');?>
</td>
<td width="50px" align="center"/>
</tr>
<tr>
<td width="50px" align="center" ></td>
<td width="600px" align="center">
<?php
$album_id=$_REQUEST['txt_albumid'];
echo $album_id;
/* how many columns */
$column_number='3';
/* html table start */
?>
<div id="photo_container" align="center" width="600px">
<table border="1px" cellspacing="5" cellpadding="0" align="left">
<?php
$sql="SELECT * FROM candidate_pics WHERE album_id='$album_id'";
$result=mysql_query($sql,$con);
// $row=mysql_fetch_array($result);
$recordcounter=1; /* counts the records while they are in loop */
while($row=mysql_fetch_array($result))
{
/* decide if there will be new Table row (<TR>) or not ... left of division by column number is the key */
if($recordcounter%$column_number==1)
{
echo "<tr>";
}
?>
<td align="center" width="200px">
<div class="wraptocenter" align="center">
<?php $_SESSION['pic_id']=$row[pic_id];?>
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
</div>
</td>
<?php
/* decide if there will be end of table row */
if($recordcounter%$column_number==0)
{
echo "</tr>";
}
$recordcounter++; /* increment the counter */
}
if(($recordcounter%$column_number)!=1){ echo "</tr>"; }
?>
</table>
</div>
</td>
<td width="300px" align="center" >
<div id="photo_uploader">
<form method="post" action="photo_upload.php" enctype="multipart/form-data">
<table width="300px" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" width="100px">Upload Pic::</td>
<td align="center" width="200px">
<input type="file" name="file" id="file" style="width: 200px;"/>
</td>
</tr>
<tr>
<td align="center" width="100px"/>
<td align="center" width="200px">
<input type="submit" name="submit_pic" id="submit_pic" value="Click to upload" style="width: 200px;"/>
<input name="txt_albumid" type="hidden" value="<?php echo $album_id;?>"/>
</td>
</tr>
</table>
</form>
</div>
</td>
<td width="50px" align="center" ></td>
</tr>
</table>
</div>
<div id="AlbumDiv" class="white_imagebox">
<table align="center" cellpadding="0" cellspacing="0" border="0" width="900px">
<tr>
<td colspan="2" height="25px">
<div id="close">
<a href="javascript:void(0)"
onclick="document.getElementById('AlbumDiv').style.display =
'none';document.getElementById('fade').style.display='none'">
<img src="images/close-icon.png" style="border-style: none; border-color: inherit;
border-width: 0px; height: 17px; width: 16px;" align="right" /></a>
</div>
</td>
</tr>
<tr>
<td width="600px" align="center">
<table width="600px" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="50px" align="center"/>
<td align="center" width="500px">
<div id="image_holder" style="width: 500px; height: 450px;
background-color:#666666;">
<input type="image" id="image" name="image"/>
</div>
</td>
<td width="50px" align="center"/>
</tr>
<tr>
<td/>
<td>
<input type="text" id="caption_holder" name="caption_holder"
style="width:500px;"/>
</td>
<td/>
</tr>
</table>
</td>
<td width="300px" align="center">
<table width="300px" cellpadding="0" cellspacing="0" border="0" align="top">
<tr>
<td align="center" width="100px">
<form method="post" action="photo_delete.php">
<input type="submit" name="delete" id="delete" value="Delete"
class="button" style="width: 100px;"/>
<input type="hidden" name="t_imageid" id="t_imageid"/>
<input type="hidden" name="t_imagepath" id="t_imagepath"/>
<input type="hidden" name="t_albumid" id="t_albumid"/>
</form>
</td>
<td align="center" width="100px">
<form>
<input type="button" name="edit" id="edit" value="Edit" class="button"
style="width: 100px;"
onclick="document.getElementById('pic_caption').style.visibility = 'visible';
document.getElementById('enter_caption').style.visibility = 'visible';"/>
</form>
</td>
<td align="center" width="100px">
<form method="post" action="">
<input type="submit" name="cover_pic" id="cover_pic" value="Set CoverPic" class="button"
style="width: 100px;"/>
<input type="hidden" name="t_albumname" id="t_albumname"/>
<input type="hidden" name="t_imagename" id="t_imagename"/>
</form>
</td>
</tr>
<tr>
<td height="100px" colspan="3">
<form method="post" action="photo_edit.php">
<input type="text" name="pic_caption" id="pic_caption" style="visibility:hidden;"/>
<input type="submit" name="enter_caption" id="enter_caption" style="visibility:hidden;"/>
<input type="hidden" name="t_picid" id="t_picid"/>
<input type="hidden" name="t_albid" id="t_albid"/>
</form>
</td>
</tr>
<tr>
<td height="300px" colspan="3">
<div id="" style="overflow-y:scroll; height:300px;">
<table width="282px" cellpadding="0" cellspacing="0" border="0"
align="center">
<tr>
<td>
<?php
echo $_SESSION[pic_id];?>
<div id="message_report">
</div>
</td>
</tr>
<tr>
<td>
<form method="post" action=
"javascript:get(document.getElementById('pic_comment_form'));" name=
"pic_comment_form" id="pic_comment_form">
<table width="280px" cellpadding="0" cellspacing="0" border="0"
align="center" >
<tr>
<td width="100px">
<input type="text" name="comment" id="comment" style="width:100px"/>
</td>
<td width="80px"/>
<td width="100px">
<input type="submit" name="comment_enter" id="comment_enter" style="width:100px"/>
</td>
<tr>
<td>
<input type="hidden" name="albumid" id="albumid"/></td>
<td>
<input type="hidden" name="imageid" id="imageid"/></td>
<td>
<input type="hidden" name="user" id="user"
value="<?php echo $_SESSION[logged_user];?>"/></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div id="fade" class="black_overlay">
</div>
</body>
</html>
The code
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
pass the album_id, pic_id to the javascript functions which is then passed to the objects in the lightbox such as id="t_albumid", id="t_imageid"
I need to write a SQL query in the lightbox like this:
SELECT * FROM candidate_pics_comment WHERE pic_id='$VariableHavingPicId
but for this I must use the variable in the JavaScript image_id and pass it again to the lightbox div in the JavaScript. The code:
document.getElementById('t_imageid').value = image_id;
assigns the object, the value as image_id, but how can we assign the image_id to a php variable so that I can use it in the sql query?
I mean in the JavaScript can it be something like this:
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$var = //assign the value image_id;?>
// rest of the code here;
}
I know it's not possible, but is there some trick to achieve this?
Moreover as I was experimenting, I did something like this:
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$_SESSION[pic_id]="hmmm";?>
//rest codes;
}
Then when I used echo $_SESSION[pic_id] in php script, it displayed hmmm
So I was thinking can it be done something like this?
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$_SESSION[pic_id]=//assign image_id to session variable;?>
//rest codes;
}
Besides I used AJAX application, but I saw that AJAX returns the response to the objects innerHTML, how ca it be stored in a php variable?
Update
My question is that, I am passing values from this
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
to the JavaScript fiunction
function showpic(image_path,image_id,album_id,pic_caption)
Now how can I assign image_id to a PHP variable which I can use in the div AlbumDiv which is used for the lightbox. If that not possible how can a session variable be assign the value of image_id, is it possible inside the JavaScript function?
ajax is the only option to get something from JavaScript to PHP.
If you are using jQuery then take a look at the docs here
Otherwise I recommend you use a Library like jQuery or jQuery itself