Adding PHP comment box to my site - php

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

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" > ';
}

Passing a href value inside a php function on same page

$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.

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());
}

delete selected images with the help of checkboxes

This is a page where users can edit their uploaded images. There is a checkbox near each image. I want to delete the selected images after user clicks the "delete selected images" button (each checkbox contains the image name as value). How can I do that?
<?php
session_start();
//////////////if user already logged in go to login.php/////////
if (isset($_SESSION['email'] )&& isset($_SESSION['password'] ))
{
} else{header( "Location: login.php" ); }
include('includes/config.php');
if (isset($_POST['esubmit']) ){
$checkbox=$_POST['delete'];
echo $checkbox;
}//main one
if (isset($_POST['esubmit']) ){
} else { $clickeditid=$_GET["id"];
$_SESSION['eid']= $clickeditid ;
}
?>
<!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 href="css/css.css" rel="stylesheet" type="text/css" />
<style rel="stylesheet" type="text/css">
input {
border-style: solid;
border-color: #000000;
border-width: 1px;
background-color: #ffffff;
}
</style>
<script src="js/css_browser_selector.js" type="text/javascript"></script>
</head>
<body>
<?php
include('includes/topmenu.php');//top menu
echo '<br />';
include('includes/usermenu.php');///bcoz of this menu error occurs
////////////////////
include('includes/edit_img_menu.php');
?>
<form id="form1" name="form1" method="post" action="editimg.php?id=<?php echo $_SESSION['eid'];?>">
<table align="center" width="70%" cellspacing="0">
<tr>
<td colspan="3" align="center" bgcolor="#FFFFFF"></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#FFFFFF"><?php
$imgcheck=mysql_query("
SELECT *
FROM `images`
WHERE `deal_id` =$_SESSION[eid]
LIMIT 0 , 30
");
$numimgcheck=mysql_num_rows($imgcheck);
if($numimgcheck==0){echo '<span style=color:#ff0000; >No pictures uploaded</span>';}
while ($rowimg2= mysql_fetch_array($imgcheck)){
$imgname=$rowimg2['name'];
{
echo ' <a href="users/'.$_SESSION['userid'].'/images/'.$imgname.'" rel="lightbox[slide]" caption=".">';
}
{ echo '<img src="users/'.$_SESSION['userid'].'/images/thumbs/'.$imgname.'" border="0" />';}
{ echo '</a><input type="checkbox" name="delete" id="delete" value="'.$imgname.'">
';}
}
?></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#95F8FD"><input name="esubmit" type="submit" class="red" id="esubmit" value="Delete selected images" /></td>
</tr>
<tr>
<td width="89"> </td>
<td colspan="2"> </td>
</tr>
</table>
</form>
</body>
</html>
You have to create a form to submit the data of the checked checkboxes and treate the submited result with the php code : if you want to put the php code on the same page, you can check if there is any data in the POST vars and create a SQL Query to delete the corresponding pictures.
You can find a very well documented tutorial here : http://sharemyphp.wordpress.com/2009/12/21/ajax-jquery-php-multiple-delete-item-with-check-box/
Regards,
Max
I use the below code to delete images in my admin panel. I saved the file as deletephoto.php. Note that this script works without login. You need to make some changes to fit your use case
<form method="post" action="deletepho.php">
<center>
<input type="submit" value="Delete" name="Delete">
</center>
<?php
\\lets assign the folder name in $title
\\You can assign any name
$title= "test";
\*$directory corresponds to whole path. Edit to your preference. (i assume u store your
images in directory named "images") */
$directory = "$title/images";
\\The array specifies the format of the files
$allowed_types=array('jpg','jpeg','gif','png');
$file_parts=array();
$ext='';
$title='';
$i=0;
$dir_handle = #opendir($directory) or die("There is an error with your image directory!");
while ($file = readdir($dir_handle))
{
if($file=='.' || $file == '..') continue;
$file_parts = explode('.',$file);
$ext = strtolower(array_pop($file_parts));
$title = implode('.',$file_parts);
$title = htmlspecialchars($title);
$nomargin='';
if(in_array($ext,$allowed_types))
{
if(($i+1)%4==0)
$nomargin='nomargin';
echo'
<div id="picture">
<img src="'.$directory.'/'.$file.'" width="150" height="150"><br>
Select <input type="checkbox" value="'.$directory.'/'.$file.'" name="imgfile[]">
\* I specified input name as an array . So that we can store in an array and delete it.*/
</div>';
}
$i++;
}
closedir($dir_handle);
\\Now we have the list of images within form elements
?>
</form>
Now here is the actual code to delete the photos. I saved it as deletepho.php.
$file = $_REQUEST['imgfile'];
$num_files=count($file);
for($i=0;$i<$num_files;$i++)
{
unlink ("$file[$i]");
}
echo "Images successfully deleted.Go <a href='deletephoto.php'>back</a>";

Categories