Passing a href value inside a php function on same page - php

$disply_storage variable has list of value, now what i want call storage_facility_id in php myfunction() i cant understand how to get storage_facility_id values in myfunction()
<?php
function myfunction(){
$x=$_POST['storage_facility_id'];
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php include('include/admin-header.php');
$disply_storage=edit_storage_facility();
?>
<script language="javascript" type="text/javascript">
function ILovePHP() {
b = "<?=myfunction();?>";
alert(b);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post">
<?php
for ($i = 0 ;$i<count($disply_storage);$i++){?>
<tr class="light-gray-bg">
<td align="center"><?php echo $disply_storage[$i]['add_facility_name'];?></td>
<td align="center"><a href="storage_mapping.php?id=<?php echo $disply_storage[$i]['storage_facility_id'];?>"><img src="images/edit.png" border="0" /></td>
<td align="center"><a onClick="javascript:return confirm_delete()" href="delete_facility.php?id=<?php echo $disply_storage[$i]['storage_facility_id'];?>"><img src="images/delete.png" border="0" /></td>
<td><a href="javascript:ChangeStatus(<?php echo $disply_storage[$i]['storage_facility_id'];?>)" title="<?=($rec['is_active']==1)?'Turn off':'Turn on'?>">
<?=($disply_storage[$i]['is_active']==1)?'<img src="images/active.gif" border="0">':'<img src="images/inactive.gif" border="0">'?>
</a></td>
</tr>
<?php }?>
</form><p>
</body>
</html>

I really don't get what you are doing here but I will take a stab at it.
First off, myfunction pretty much does nothing. I guess you want...
function myfunction(){
return $_POST['storage_facility_id'];
}
which makes to no sense to me as you can just echo the $_POST var inline any time. However the data is only going to be there the page was posted to.

Related

dynamically added link are not triggering in php

I have added images and the corresponding links to the database and viewed on index page, problem is when i click the images it goes to the present page, it does not open corresponding links related to images. But same is working fine in marquee.
code for adding images and links is
<?php
include_once("../init.php");
validation_check($_SESSION['UID'], SITE_HOME_ADMIN);
$msg='';
if(isset($_POST['save']))
{
$upDir ='../'.VIDEO;
$videourl = $_POST['videourl'];
$insertSql =("INSERT INTO videonews (videourl)
VALUES ('$videourl')");
$insertSql="INSERT INTO ".VIDEONEWS." SET
`adv_url` = '".realStrip($_POST['adv_url'])."'";
$query = mysql_query($insertSql);
$adv_id = mysql_insert_id();
$adv = '';
if($_FILES["adv"]['name']!= ''){
$fileData = pathinfo(basename($_FILES["adv"]["name"]));
$adv = $adv_id . '_adv.' . $fileData ['extension'];
move_uploaded_file($_FILES["adv"]["tmp_name"], $upDir . $adv);
}
$upSql="UPDATE ".VIDEONEWS." SET `adv` = '".$adv."' WHERE id = '$adv_id'";
$query = mysql_query($upSql);
$msg = '<h3>Record Saved</h3>';
}
?>
<!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>Video News</title>
<link rel="stylesheet" type="text/css" href="headerstyle.css" />
<script type="text/javascript">
</script>
</head>
<body>
07/25/2014
<div class="fixx">
<?php include('header.php');?>
</div>
<div class="tabl">
<table width="700" border="0">
<tr>
<td><form action="news1.php" method="post" enctype="multipart/form-data">
<table width="900" border="1" cellpadding="10">
<tr>
<td colspan="2"><h3> ADD Files To Video News | EDIT </h3></td>
</tr>
<tr>
<td colspan="2"><?php echo $msg;?></td>
</tr>
<tr>
<td><input type="file" name="adv" id="adv" /><input type="text" placeholder="URL" name="adv_url" id="adv_url" size="50" /></td></tr>
</tr>
<tr>
<td>Video Link <input type="text" name="videourl" id="videourl" size="100" /></td></tr>
<tr> <td><input type="submit" name="save" id="save" value="Submit" /></td></tr>
</table>
</form></td>
</tr>
</table>
</div>
</body>
</html>
Retrieving file code is
<?php
validation_check($_SESSION['UID'], SITE_HOME_ADMIN);
$msg='';
$adDir ='./'.VIDEO;
$qr = mysql_query("select * from ".VIDEONEWS) or die('Error in connection');
while($rs = mysql_fetch_array($qr))
{
$adv = '';
if($rs['adv']!='') {
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:250px; height:150px" > ';
}
$image = $adv;
$msg .='<tr>
<tr>'.$image.'</tr>
</tr>';
}
?>
<!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>Videonews Lists</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="headerstyle.css" />
</head>
<body>
<div class="tabl">
<table width="100%" border="0" align="center" class="main">
<td>
<table width="95%" border="1" align="center" cellpadding="10">
<?php echo $msg;?>
</table>
</td></tr></table>
</body>
</html>
Retrieving file is included in index.php to show all images in a frame.
Marquee code in index page which is working fine is
<div class="ads-242x90 right">
<strong>VIDEO NEWS</strong>
<marquee direction="up" scrollamount="2" onmouseover="this.stop();" onmouseout="this.start();">
<div align="left" >
<span style="text-transform:uppercase;">
<?
$qryAdv = mysql_query("SELECT * FROM ".VIDEONEWS." WHERE 1");
if(mysql_num_rows($qryAdv) > 0)
{
while($adv = mysql_fetch_assoc($qryAdv))
{
?>
<img src="<?=VIDEO.$adv['adv']?>" width="98%" height="90" alt=""> <br />
<?
}
} else { echo 'NO ADDS FOUND!!!'; }
?>
</marquee>
First thing you should do is to protect yourself from SQL injection, read about it.
I think your problem lies here:
$adv = ''; ///you set $adv equal to empty string
if($rs['adv']!='') { //VVVV here you try to use your empty string
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:250px; height:150px" > ';
}
I believe it should be
//VVVVVV
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:250px; height:150px" > ';

Link URL to image or Title rather than echo link , retriving image,title and link from database in php

I am getting image, title and external URL from database, and display it on my page, code is working well, But i don't want to display URL, I want when I click image or title it should go direct to that URL in new window. My Code is
<?php
include_once("init.php");
$msg='';
$adDir ='./'.EDITORIALNEWS;
$qr = mysql_query("select * from " .enews) or die('Error in connection');
while($rs = mysql_fetch_array($qr))
{
$adv = '';
if($rs['adv']!='') {
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:60px; height:60px" > ';
}
$image = $adv;
$msg .='<tr>
<td>'.$image.'</td>
<td>'.$rs['title'].'</td>
<td>'.$rs['adv_url'].'</td>
</tr>';
}
?>
<!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>Editorialt News Lists</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="headerstyle.css" />
</head>
<body>
<div class="tabl">
<table width="95%" border="1" align="center" cellpadding="10">
<tr>
<td width="35%"><strong>File</strong></td>
<td width="30%"><strong>Title</strong></td>
<td width="30%"><strong>Link</strong></td>
</tr>
<?php echo $msg;?>
</table>
</body>
</html>
Image, Title, URL are adv, title and adv_url respectively.
I think the line added should be like
<img src="<?=VIDEO.$adv['adv']?>" width="98%" height="90" alt="">
but how and where to use it don't know. Being a student I have keen interest in learning PHP through projects.
You can do it like as follows:
Replace the following line of your code with my code:
if($rs['adv']!='') {
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:60px; height:60px" > ';
}
//My code
if($rs['adv']!='') {
$adv = '<img src="'.$adDir.$rs['adv'].'" style="width:60px; height:60px" > ';
}

Adding PHP comment box to my site

Hi i've managed to make some sort of a comment box that relies on the use of a mysql database and php coding. I'm able to run the comment box by opening its index.php file on my server but when i try adding it to a html page by using a simple include_once php code
it doesn't seem to work.
please excuse me if I sound stupid but this is my first time using php.
here is the code i've been trying to use.
<?php
include_once("../connect.php");
$commenting_form = '<form action="addcomment.php" method="post">
<table width="310" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><strong>Add Comment:</strong></td>
</tr>
<tr>
<td width="105">Title</td>
<td width="205"><input type="text" name="msg_title" id="msg_title" style="width:200px;" /></td>
</tr>
<tr>
<td colspan="2"><textarea name="msg_message" id="msg_message" style="width:100%;height:200px;font-family:Courier New">Message</textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Add Comment" name="msg_submit" id="msg_submit" /></td>
</tr>
</table>
</form>';
$get_comments = mysql_query("SELECT * FROM comments");
$comments_count = mysql_num_rows($get_comments);
if ($comments_count>0)
{
while ($com = mysql_fetch_array($get_comments))
{
$id = $com['id'];
$title = $com['text'];
$message = $com['message'];
$comment .= '<strong>'.$title.'</strong><br />'.$message.'<hr />';
}
$comment .= $commenting_form;
$page_title = $comments_count.' Comments';
}
else
{
$comment = 'There are no comments at the moment.<br />'.$commenting_form;
$page_title = 'No Comments';
}
?><!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><?php echo $page_title; ?></title>
</head>
<body>
<?php
echo $comment;
?>
</body>
</html>
Try this:
include "../connect.php";
NOTE: make sure you put the right path of connect.php

div coming down while refreshing the page

I want to make a page for android which is refreshing in every sec . All things are working well but the problem i am facing on this page when you click on the reserve button then entire div come down and leave a small space above but after next refresh it becomes ok . I have tried without div but its not working Here is the code
<!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">
<?php
Header('Refresh:2;url=http://medical.gofreeserve.com/and/checkm.php');
?>
<head>
<style type="text/css">
<!--
.style2 {color: #FFFFFF}
-->
</style>
</head>
<body bgcolor="#000000">
<?php
include("../common/connection.php");
?>
<?php
if(isset($_GET['reserve']))
{
echo $sql = "UPDATE newsevents SET booking ='1' WHERE news_id='$_GET[val]'";
$query = mysql_query($sql) or die(mysql_error());
}
$new_query=mysql_query("select * from newsevents where booking=0") or die(mysql_error());
while($row=mysql_fetch_array($new_query))
{
$id=$row['news_id'];
$date=$row['date'];
$news_text=$row['text'];
?>
<div style="border-bottom:2px solid #FFFFFF" >
<form name="fm1" action="checkm.php" method="get">
<table width="95%">
<tr>
<td width="60%" height="50" ><span class="style2"><?php echo $date ?></span></td>
<td width="40%"><span class="style2"><?php echo $news_text ?></span></td>
<td width="40%"><span class="style2"><input type="hidden" name="val" value="<?php echo $id?>" / ></span></td>
<td width="30%"><input type="submit" name="reserve" id="reserve" value="reserve" /></td>
</tr>
</table>
</form>
</div>
<?php }?>
</body>
</html>
You're echoing the SQL statement when running the SQL query, which is pushing down the div. Just use the following instead:
if(isset($_GET['reserve']))
{
$sql = "UPDATE newsevents SET booking ='1' WHERE news_id='".$_GET['val']."'";
$query = mysql_query($sql) or die(mysql_error());
}

JQuery Tab Events Triggers

I want to see tab No. 2 when "IF Condition" will meet the requirements. Here is my code. Please advice me how can I do this.
Thanks
Shahid
<?php
//Authorization / Security
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link type="text/css" href="../javascript/jquery/themes/ui-lightness/jquery.ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="../javascript/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="../javascript/jquery/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../javascript/jquery/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../javascript/jquery/ui/jquery.ui.tabs.js"></script>
<script type="text/javascript">
$(function() {
alert('main');
$("#container").tabs({
ajaxOptions: {
error: function(xhr, status, index, anchor) {
$(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible. If this wouldn't be a demo.");
}
}
});
});
</script>
<?php
if($_GET['action'] == "add")
{
////////////////// Trigger Tab No. 2 ////////////////
///////////////// and ///////////////
//////////////// change url of Tab 3 ///////////////
}
?>
</head>
<body leftmargin="0" topmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><?php include("../includes/headerone.php");?></td>
</tr>
<tr>
<td width="15%"><?php include("../includes/leftbar.php");?></td>
<td width="83%" ><div id="container">
<ul class="tabs-nav">
<li><span>Add</span></li>
<li><span>Edit</span></li>
<li><span>View</span></li>
</ul>
</div></td>
</tr>
<tr>
<td colspan="2"><?php include("../includes/footer.php");?></td>
</tr>
</table>
</body>
</html>
Try your script tag like this, it adds javascript to do what you want by echoing it into the self calling anonymous function if the php condition is met
<script type="text/javascript">
$(function() {
alert('main');
$("#container").tabs({
ajaxOptions: {
error: function(xhr, status, index, anchor) {
$(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible. If this wouldn't be a demo.");
}
}
});
<?php
if($_GET['action'] == "add"){
echo "$('.tabs-nav li a:eq(1)').trigger('click');";
echo "$('.tabs-nav li a:eq(2)').attr('href', 'newurl');";
}
?>
});
</script>

Categories