update query not work - php

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.

Related

I can't edit my mail text in the PHP mailer

I have set up a site and added a contact form into it. Php mailer work correctly but when the mail text arrives to me there is no empty between the letters. All of them is adjoining. I want to list titles one under to other mailer.php. The code is like this
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->SetLanguage("tr", "phpmailer/language");
$mail->CharSet ="utf-8";
$mail->Username = "sample";
$mail->Password = "sample";
$mail->SetFrom("sample#sample.com", "Baslik");
$mail->AddAddress("sample#sample.com");
$mail->Subject = "Siteden Gönderildi";
include("iletisim.html");
$mail->Body = $frmName= $_POST["frmName"].
$frmCity= $_POST["frmCity"] .
$adressatiri= $_POST["adressatiri"].
$adressatiri2= $_POST["adressatiri2"].
$email= $_POST["email"] .
$frmTelephone= $_POST["frmTelephone"] .
$frmPhoneType= $_POST["frmPhoneType"] .
$frmContactBy= $_POST["frmContactBy"] .
$frmBestTime= $_POST["frmBestTime"] .
$frmMessage= $_POST["frmMessage"];
if(!$mail->Send()){
echo "Mailer Error: ".$mail->ErrorInfo;
} else {
echo "Mesajınız Gonderilmistir";
}
?>
and contact.html file is like this. If you can help me i will be very happy. Because i didnt solve this problem throughout one
<!doctype html>
<html>
<head>
<link rel="Shortcut Icon" href="image/favicon.ico" type="image/x-icon">
<meta charset="utf-8">
<title>Sena DOĞAN Kişisel Web Sitesi</title>
<style type="text/css">
body, p, table, th, td, div {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
th {
background-color:#0080C0;
color:white;
font-weight:bold;
font-size:18px;
border: 1px solid #0080C0;
}
input.text, textarea {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
width: 99%;
}
.text:focus, textarea:focus {
background-color: #FFFACC;
border: 1px solid #000000;
}
#mydiv {
margin-left: auto ;
margin-right: auto ;
width: 500px;
text-align: left;
}
td.colone {
text-align: right;
vertical-align: top;
padding-top:6px;
width:20%;
}
td.coltwo {
color:red;
text-align: center;
vertical-align: top;
padding-top:9px;
}
td.colthree {
width:80%
}
table.border {
border: 1px solid #0080C0;
border-collapse: collapse;
}
</style>
<link href="banner.css" rel="stylesheet" type="text/css">
}
</head>
<body>
<div class="container"> <img src="image/Sena banner.png" width="999" height="258" alt="KTU"/>
<div id="navbar">
<ul style="">
<li style="">Ana Sayfa</li>
<li> Hakkında</li>
<li> Projeler</li>
<li>Deneyim</li>
<li> Galeri</li>
<li> İletişim</li>
<br>
<br>
<br></ul>
<br/>
<form method="POST" action="mailer.php" enctype="multipart/form-data">
<input type="hidden" value="samplecontactus.html" name="referer">
<table class="border" width="500" cellpadding="3" cellspacing="0">
<tr>
<th colspan="3" align="center">İletişim İçin Lütfen Aşağıdaki Kutuları Doldurun</th>
</tr>
<tr>
<td colspan="3"><div style="height:5px;"></div></td>
</tr>
<tr>
<td class="colone">Ad Soyad</td>
<td class="coltwo">*</td>
<td class="colthree"><input class="text" type="text" name="frmName" style="width:98%;"></td>
</tr>
<tr>
<td class="colone">Şehir</td>
<td class="coltwo"> </td>
<td class="colthree"><input class="text" type="text" name="frmCity" style="width:98%;"></td>
</tr>
<tr>
<td class="colone">Adres</td>
<td class="coltwo"> </td>
<td class="colthree"><input class="text" type="text" name="adressatiri" style="width:98%;"></td>
</tr>
<tr>
<td class="colone">Adres-2</td>
<td class="coltwo"> </td>
<td class="colthree"><input class="text" type="text" name="adressatiri2" style="width:98%;"></td>
</tr>
<tr>
<td class="colone">E-posta</td>
<td class="coltwo">*</td>
<td class="colthree"><input class="text" type="text" name="email" style="width:98%;"></td>
</tr>
<tr>
<td class="colone">Telefon</td>
<td class="coltwo"> </td>
<td class="colthree">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="200"><input class="text" type="text" name="frmTelephone" style="width:200px;"></td>
<td>
<select size="1" name="frmPhoneType">
<option value="Home">Ev</option>
<option value="Worx">İş</option>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="colone">Görüşme Şekli</td>
<td class="coltwo"> </td>
<td class="colthree">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="1">
<select size="1" name="frmContactBy">
<option value="Telefon">Telefon</option>
<option value="Email">E-Posta</option>
</select>
</td>
<td>
<select size="1" name="frmBestTime">
<option value="Morning">Gündüz</option>
<option value="Afternoon">Öğle</option>
<option value="Evening">Akşam</option>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="colone">Mesaj</td>
<td class="coltwo">*</td>
<td class="colthree"><textarea class="text" name="frmMessage" style="width:98%;height:100px;"></textarea></td>
</tr>
<tr>
<td class="colone" colspan="2"> </td>
<td class="colthree"><input type="submit" value="Gönder" name="submit"><input type="reset" value="Reset" name="reset"></td>
</tr>
<tr>
<td colspan="3"><div style="height:5px;"></div></td>
</tr>
</table>
</form>
</div>
<h2><span style="color: #ED0F13"><center>
</center>
</span></h2>
<blockquote>
<p> </p>
<p><span class="copyright" style="text-align: center"><span class="copyright"><center class="copyright">Copyright © 2018 DOĞAN Web Tasarım™</center><span class="copyright"><span class="copyright"></span></span>
</center>
</span></span></p>
</blockquote>
<p><span class="imagefloatleft">
<article id="123"> </article>
</span>
<span class="imagefloatleft">
<article id="text"> </article>
</span>
<span class="imagefloatleft">
<article id="text"> </article>
</span>
<span class="imagefloatleft">
<article id="text"> </article>
</span>
<span class="imagefloatleft">
<article id="text"> </article>
</span>
<span class="imagefloatleft">
<article id="text"> </article>
</span><span class="imagefloatleft">
<article id="text"> </article>
</span><span class="imagefloatleft">
<article id="text"></article>
</span></p>
</div>
</body>
</html>
It's because HTML collapses white space. The easiest way to fix this is to convert real line breaks into HTML break tags in your message body:
$mail->Body = nl2br($mail->Body);
As a result of my researches I have found a solution like this
<a><span style='font-weight: bold;'>İsim:</span> ".$_POST["frmName"]."</a><br>
<a><span style='font-weight: bold;'>Şehir:</span> ".$_POST["frmCity"]."</a><br>
<a><span style='font-weight: bold;'>Adres 1:</span> ".$_POST["adressatiri"]."</a><br>
<a><span style='font-weight: bold;'>Adres 2:</span> ".$_POST["adressatiri2"]."</a><br>
<a><span style='font-weight: bold;'>E-posta:</span> ".$_POST["email"]."</a><br>
<a><span style='font-weight: bold;'>Telefon:</span> ".$_POST["frmTelephone"]."</a><br>
<a><span style='font-weight: bold;'>Telefon Tipi:</span> ".$_POST["frmPhoneType"]."</a><br>
<a><span style='font-weight: bold;'>Görüşme Şekli:</span> ".$_POST["frmContactBy"]."</a><br>
<a><span style='font-weight: bold;'>En uygun zaman:</span> ".$_POST["frmBestTime"]."</a><br>
<a><span style='font-weight: bold;'>Mesaj:</span> ".$_POST["frmMessage"]."</a>

methode $_POST is empty php

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

Form doesn't submit all fields

I have a pretty huge form which I am able to extend dynamically with JavaScript. In this form I am having different DataSets with about 50 fields to submit each. When I submit the form I am running through a for loop from 0 to 100 to check which fields are set. So I create the HTML like this:
<form id = "formUpdate" role="form" action="index.php?action=update" method="post">
<table id="table" class="table table-hover"><thead>
<tr>
<th> Head1
<th> Head2
<th> Head3
<th> Head4
<th> Head5
<th> Head6
<th> ...
<tbody>
<?php
for ($i=0;$i<$dataSets;$i++){ ?>
<tr>
<td style="text-align: center; vertical-align: middle;"><label><?php echo $test[$i]['1']; ?> </label></td>
<td style="text-align: center; vertical-align: middle;"> <input required class="form-control formsUser" form="formUpdate" name="fieldA<?php echo $test[$i]['2']; ?>" value=""></input>
<td style="text-align: center; vertical-align: middle;"> <textarea style="height:34px" class="form-control formsUser" form="formUpdate" name="fieldB<?php echo $test[$i]['3'];?>" required></textarea>
<td style="text-align: center; vertical-align: middle;"> <input class="form-control formsUser" form="formUpdate" name="fieldC<?php echo $test[$i]['4']; ?>" required value=""></input>
<td style="text-align: center; vertical-align: middle;"> <input class="form-control formsUser" form="formUpdate" name="fieldD<?php echo $test[$i]['5']; ?>" required value=""></input>
<td style="text-align: center; vertical-align: middle;"> <input class="form-control formsUser" form="formUpdate" name="fieldE<?php echo $test[$i]['6']; ?>" value=""></input>
</tr>
<?php } ?>
</table>
<button class="btn btn-success" form="formUpdate" type="submit"> Submit </button>
</form>
PHP:
public function update(){
print_r($_REQUEST);
for ($i=0;$i<100;$i++){
$string = "fieldA".$i;
if (isset($_POST[$string])){
// set the other _POSTS
}
else {
//do something different
}
}
}
But this works only for the first 10 Datasets. When I call print_r($_REQUEST); it also just contains the content of the fields of the first 10 Datasets. I read about the limit of max_input_vars in the php.ini and increased this value, but nothing has changed. Besides I shouldn't reach the default value of 1,000 with my data. I also tried changing the value of max_input_nesting_level, memory_limit and post_max_size.
OMG. Got the Problem. I am using DataTables and when submitting the form, the table is redrawed showing the first 10 Datasets only...sorry for that guys and thanks for your help :)

Grab multidimensional array value in to table using foreach loop

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.... :(

Passing value inside JavaScript function and saving it into a PHP variable

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

Categories