Hello I would like to know how to add a description, title, & keywords to my file upload script? I already have the file upload working.
So I want people to be able to enter a title and description and keywords and save it to the database.
P.S: I already have the file upload system working. User uploads file saves it to a temp folder and uploads it to database so you don’t need to mess with the file uploading part just adding the title, keywords, & description.
File Upload Script:
This allows file uploads.
<?php
<?php
include_once 'dbconnect.php';
// fetch files
$sql = "select filename from tbl_files";
$result = mysqli_query($con, $sql);
?>
<?php
session_start();
include_once "vendor/autoload.php";
$page = new membership\Page(1);
if ($page->isValid() == true) {
?>
<center>
<div class='container'>
<div class='row'>
<div class='col-xs-8 col-xs-offset-2 well'>
<form action='upload.php' method='post' enctype='multipart/form-data'>
<legend>Select File to Upload:</legend>
<div class='form-group'>
<input type='textname' name='title' />
<input type='textname' name='desc' />
<input type='file' name='file1' />
</div>
<div class='form-group'>
<input type='submit' name='submit' value='Upload' class='btn btn-info'/>
</div>
<?php if (isset($_GET['st'])) { ?>
<div class='alert alert-danger text-center'>
<?php
if ($_GET['st'] == "success") {
echo "File Uploaded Successfully!";
} else {
echo 'Invalid File Extension!';
}
?>
</div>
<?php } ?>
</form></div></div></center>
<?php } ?>
upload.php:
This is the file that controls the file upload.
<?php include('dbconnect.php'); ?>
<?php
//check if form is submitted
if (isset($_POST['submit']))
{
$filename = $_FILES['file1']['name'];
//upload file
if($filename != '')
{
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$allowed = ['zip', 'rar', 'php', 'html', 'sql'];
//check if file type is valid
if (in_array($ext, $allowed))
{
// get last record id
$sql = 'select max(id) as id from tbl_files';
$result = mysqli_query($con, $sql);
if (count($result) > 0)
{
$row = mysqli_fetch_array($result);
$filename = ($row['id']+1) . '-' . $filename;
}
else
$filename = '1' . '-' . $filename;
//set target directory
$path = 'uploads/';
$created = #date('Y-m-d H:i:s');
move_uploaded_file($_FILES['file1']['tmp_name'],($path . $filename));
// insert file details into database
$sql = "INSERT INTO tbl_files(filename, created) VALUES('$filename', '$created')";
mysqli_query($con, $sql);
header("Location: new-project.html?st=success");
}
else
{
header("Location: new-project.html?st=error");
}
}
else
header("Location: new-project.html");
}
?>
MySQL:
CREATE TABLE IF NOT EXISTS `tbl_files` (
`id` int(9) NOT NULL AUTO_INCREMENT,
`filename` varchar(255) NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
Also I need help on creating the tables for the keywords, title, & description.
EDIT: : So I got everything working but now I can’t get the title to display on the page it’s just blank. Anyway here’s the code for the project display:
<?php
include_once 'dbconnect.php';
// fetch files
$sql = "select filename from tbl_files";
$result = mysqli_query($con, $sql);
?>
<div class="gboxtop"></div>
<div div="button-pro">
<button>New Project</button>
</div>
<div class="left">
<div class="left_articles">
<h2>Lastest Projects</h2>
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>File Name</th>
<th>View</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while($row = mysqli_fetch_array($result)) { ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $row['title']; ?></td>
<td>View</td>
<td><a href="uploads/<?php echo $row['filename']; ?>" download>Download</td>
</tr>
<?php } ?>
</tbody>
</table>
</div></div></div>
</div></div></div></div>
//Start Table Style
<style>table.blueTable {
border: 1px solid #1C6EA4;
background-color: #EEEEEE;
width: 100%;
text-align: left;
border-collapse: collapse;
}
table.blueTable td, table.blueTable th {
border: 1px solid #AAAAAA;
padding: 3px 2px;
}
table.blueTable tbody td {
font-size: 13px;
}
table.blueTable tr:nth-child(even) {
background: #D0E4F5;
}
table.blueTable thead {
background: #1C6EA4;
background: -moz-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
background: -webkit-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
background: linear-gradient(to bottom, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
border-bottom: 2px solid #444444;
}
table.blueTable thead th {
font-size: 15px;
font-weight: bold;
color: #FFFFFF;
border-left: 2px solid #D0E4F5;
}
table.blueTable thead th:first-child {
border-left: none;
}
table.blueTable tfoot {
font-size: 14px;
font-weight: bold;
color: #FFFFFF;
background: #D0E4F5;
}
.button-pro {
float: right;
}
</style>
run:
ALTER TABLE tbl_files ADD title VARCHAR(255) AFTER created;
edit:
<input type='text' name='title' maxlength="255"/>
add before // insert file details into database:
$title = '';
if(!empty($_POST['title']))
{
$title = mysqli_real_escape_string($con, $_POST['title']);
}
edit:
$sql = "INSERT INTO tbl_files(filename, created, title) VALUES('$filename', '$created', '$title')";
the rest by analogy
Related
I'm currently trying to make a blog. When I try to make a "preview" of the body of the post. The first post seems to be fine, but the second post goes over its div. I tried changing what tags to use and css formatting but it stays like that.
My code:
HTML
<div class="module">
<div class="blog">
<div class="recents">
<h2>Recent Posts</h2>
<br><br>
<?php
$sql = "select title, body, created_at FROM posts";
$result = mysqli_query($link, $sql);
$query = mysqli_query($link, $sql) or die(mysqli_error($link));
while ($row = mysqli_fetch_assoc($query)) {
$title = $row['title'];
$body = $row['body'];
$created_at = $row['created_at'];
if (strlen($body) > 500) {
$body = substr($body, 0, 500);
}
echo "<h3>" . $title . "</h3><br>";
echo "<p>" . $body . "</p>";
echo "<small>" . $created_at . "</small>";
echo "<br><br>";
}
?>
</div>
<div class="categories">
<h3>Categories</h3>
</div>
</div>
CSS
html {
font-family: 'IBM Plex Serif', serif;
}
.module {
background-color: #fffff7;
box-shadow: 3px 10px 18px #888888;
padding-top: 70px;
padding-left: 130px;
border: 1px solid;
width: 1080px;
margin-left: 380px;
height: 821px;
}
.blog {
display: flex;
flex-direction: row;
text-align: left;
}
.recents {
flex-grow: 2;
width: 570px;
}
.categories {
flex-grow: 1;
}
Any help would be appreciated.
It is because there are no spaces
to fix this try this:
word-wrap: break-word;
I am trying to make image show permanent on refreshing.
The image should be constant. We can add images and text permanent and we can add more posts.
A database called image_upload and create a table called images with fields:
id - int(11)
image - varchar(100)
image_text - text
index.php
<?php
// Create database connection
$db = mysqli_connect("localhost", "root", "", "image_upload");
// Initialize message variable
$msg = "";
// If upload button is clicked ...
if (isset($_POST['upload'])) {
// Get image name
$image = $_FILES['image']['name'];
// Get text
$image_text = mysqli_real_escape_string($db, $_POST['image_text']);
// image file directory
$target = "images/".basename($image);
$sql = "INSERT INTO images (image, image_text) VALUES ('$image', '$image_text')";
// execute query
mysqli_query($db, $sql);
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$msg = "Image uploaded successfully";
}else{
$msg = "Failed to upload image";
}
}
$result = mysqli_query($db, "SELECT * FROM images");
?>
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
<style type="text/css">
#content{
width: 50%;
margin: 20px auto;
border: 1px solid #cbcbcb;
}
form{
width: 50%;
margin: 20px auto;
}
form div{
margin-top: 5px;
}
#img_div{
width: 80%;
padding: 5px;
margin: 15px auto;
border: 1px solid #cbcbcb;
}
#img_div:after{
content: "";
display: block;
clear: both;
}
img{
float: left;
margin: 5px;
width: 300px;
height: 140px;
}
</style>
</head>
<body>
<div id="content">
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
echo "<img src='images/".$row['image']."' >";
echo "<p>".$row['image_text']."</p>";
echo "</div>";
}
?>
<form method="POST" action="index.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div>
<input type="file" name="image">
</div>
<div>
<textarea
id="text"
cols="40"
rows="4"
name="image_text"
placeholder="Say something about this image..."></textarea>
</div>
<div>
<button type="submit" name="upload">POST</button>
</div>
</form>
</div>
</body>
</html>
Help me How to solve this problem. I have created database and uploading images and text. while refreshing page. The posts is repeating after and after.
It now works. Tested. For over two hours I was baffled why the page could not redirect after successful upload. Undoing some indentations at the top of the page solved the problem.
<?php
session_start();
// Create database connection
$db = mysqli_connect("localhost", "root", "", "image_upload");
if(isset($_POST['image_text'])){
// Get text
$image_text = mysqli_real_escape_string($db, $_POST['image_text']);
}
if(isset($_FILES['image'])){
// Get image name
$image = $_FILES['image']['name'];
$tempath = $_FILES['image']['tmp_name'];
}
// If upload button is clicked ...
if(isset($_POST['upload'])){
if(isset($image) && isset($tempath) && !empty($image)){
$image = time()."_".$image;
$image_folder = "images/";
if(is_uploaded_file($tempath)){
if(move_uploaded_file($tempath, $image_folder.$image)) {
$image_uploaded = true;
}
}
}else{
$msg = "Failed to upload image";
}
if(isset($image_uploaded) && ($image_uploaded == true)){
$sql = "INSERT INTO images (image, image_text) VALUES('$image', '$image_text')";
// execute query
mysqli_query($db, $sql);
$sent = true;
$_SESSION['sent'] = "Image uploaded successfully";
}
}
if(isset($sent) && ($sent == true)){
header("Location: index.php");
exit();
}
$result = mysqli_query($db, "SELECT * FROM images");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Image Upload</title>
<style type="text/css">
#content{
width: 50%;
margin: 20px auto;
border: 1px solid #cbcbcb;
}
form{
width: 50%;
margin: 20px auto;
}
form div{
margin-top: 5px;
}
#img_div{
width: 80%;
padding: 5px;
margin: 15px auto;
border: 1px solid #cbcbcb;
}
#img_div:after{
content: "";
display: block;
clear: both;
}
img{
float: left;
margin: 5px;
width: 300px;
height: 140px;
}
</style>
</head>
<body>
<div id="content">
<?php
if(isset($_SESSION['sent'])){
echo "<p style='color:#006400;font-weight:bold;'>" . $_SESSION['sent'] . "</p>";
unset($_SESSION["sent"]);
}
if(isset($msg)){
echo "<p style='color:#ff0000;font-weight:bold;'>" . $msg . "</p>";
}
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
echo "<div id='img_div'>";
echo "<img src='images/".$row['image']."' >";
echo "<p>".$row['image_text']."</p>";
echo "</div>";
}
}else{
echo "<h4>No data has been uploaded</h4>";
}
?>
<form method="POST" action="index.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div>
<input type="file" name="image">
</div>
<div>
<textarea
id="text"
cols="40"
rows="4"
name="image_text"
placeholder="Say something about this image..."></textarea>
</div>
<div>
<button type="submit" name="upload">POST</button>
</div>
</form>
</div>
</body>
</html>
Hopefully the following will provide guidance ~ fully working but the paths used to store images is relevant to my laptop so you'll need to edit that portion slightly.
<?php
session_start();
$dbhost = 'localhost';
$dbuser = 'root';
$dbpwd = 'xxx';
$dbname = 'xxx';
$db = new mysqli( $dbhost, $dbuser, $dbpwd, $dbname );
$msg='Failed to upload image';
/* utility to find error if something goes wrong */
function uploaderror( $error ){
switch( $error ) {
case UPLOAD_ERR_INI_SIZE: return "The uploaded file exceeds the upload_max_filesize directive in php.ini";
case UPLOAD_ERR_FORM_SIZE: return "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
case UPLOAD_ERR_PARTIAL: return "The uploaded file was only partially uploaded";
case UPLOAD_ERR_NO_FILE: return "No file was uploaded";
case UPLOAD_ERR_NO_TMP_DIR: return "Missing a temporary folder";
case UPLOAD_ERR_CANT_WRITE: return "Failed to write file to disk";
case UPLOAD_ERR_EXTENSION: return "File upload stopped by extension";
default: return "Unknown upload error";
}
}
if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_FILES['image'] ) && isset( $_POST['image_text'] ) ){
try{
/* try to filter input of bad characters though using a prepared statement should help */
$text=filter_input( INPUT_POST, 'image_text', FILTER_SANITIZE_STRING );
/* get a reference to the uploaded FILE object*/
$obj=(object)$_FILES['image'];
$name=$obj->name;
$tmp=$obj->tmp_name;
$size=$obj->size;
$error=$obj->error;
$type=$obj->type;
/* proceed to save file and log to db */
if( is_uploaded_file( $tmp ) && $error==UPLOAD_ERR_OK ){
#$destination = 'images/' . $name;
$root='c:/wwwroot';
$path='/images/tmp/';
$filepath = $path. $name;
$destination=$root . $filepath;
$status=move_uploaded_file( $tmp, $destination );
if( $status ){ /* moved/saved the file OK */
/* create a prepared statement */
$sql='insert into `images` ( `image`, `image_text`) values (?,?)';
$stmt=$db->prepare( $sql );
if( $stmt ){/* bind variables to placecholders ~ store path to image rather than just image name */
$stmt->bind_param('ss', $filepath, $text );
$status = $stmt->execute();
$stmt->close();
$msg = $status ? 'Image uploaded successfully' : 'Failed to log image to database';
}
} else {
throw new Exception('unable to move file');
}
} else {
throw new Exception( sprintf( 'error: possible file upload attack - %s',uploaderror( $error ) ) );
}
}catch( Exception $e ){
$msg = $e->getMessage();
}
}
/* fetch all image details from db */
$sql='select `image`,`image_text` from `images`;';
$result=$db->query( $sql );
?>
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
<style>
#content{
width: 50%;
margin: 20px auto;
border: 1px solid #cbcbcb;
}
form{
width: 50%;
margin: 20px auto;
}
form div{
margin-top: 5px;
}
#img_div{
width: 80%;
padding: 5px;
margin: 15px auto;
border: 1px solid #cbcbcb;
}
#img_div:after{
content: "";
display: block;
clear: both;
}
img{
float: left;
margin: 5px;
width: 300px;
height: 140px;
}
</style>
</head>
<body>
<div id="content">
<?php
$i=0;
while( $row = $result->fetch_object() ) {
$i++;
/* an ID MUST be unique! */
echo "
<div class='img_div' id='img_div__$i'>
<img src='{$row->image}' />
<p>{$row->image_text}</p>
</div>";
}
?>
<form method='POST' enctype='multipart/form-data'>
<input type='hidden' name='MAX_FILE_SIZE' value='1000000' />
<div>
<input type='file' name='image' />
</div>
<div>
<textarea
id='text'
cols='40'
rows='4'
name='image_text'
placeholder='Say something about this image...'></textarea>
</div>
<div>
<button type='submit' name='upload'>POST</button>
<?php
if( !empty( $msg ) && $_SERVER['REQUEST_METHOD']=='POST' ) echo $msg;
?>
</div>
</form>
</div>
</body>
</html>
my question is that why float left is not working under these codes
when i use them all the result just display on single div and other 7 where showing under that div at same place so please tell me what is the solution of this prob
<div class="tv_l" style="top:1465px;
left:10px;
position:absolute;
width:1690px;
height:10px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;">
<hr>
</div>
<?php
$link = mysqli_connect("localhost" , "***" ,"***" , "***");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
} else {
echo "";
}
?>
<?php
$result = mysqli_query($link, "SELECT * FROM **** ORDER BY RAND()
LIMIT 8" )
or die(mysqli_error());
while($row = mysqli_fetch_array( $result )){
?>;
<div class="son_s_p" style="top:1957px;
left:12px;
-webkit-box-shadow:0 3px 8px rgba(0, 0, 0, .25);
position:inherit;
background:white;
width:190px;
height:240px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:center;
float:left;
">
<img src="../lu/music/tumb/<?php echo $row['img']; ?>"style="width:198px; height:148px;" >
<br>
<?php echo $row['name']; ?><br><br>
<div id="son_s_p" style="top:218px;
left:px;
position:absolute;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:justify;">
<?php echo $row['time']; ?> <span class="time&type" style="top;10px;"><?php echo $row['type']; ?></span>
</div>
</div>
<?php
}
?>
with using position
without using position data will go top and top do not work
your wrong is that you put in div "float: left;" and thats wrong.you should put before it style attribute and it is Style="float: left;"
correct code is:
<div class="tv_l" style="top:1465px;
left:10px;
position:absolute;
width:1690px;
height:10px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;">
<hr>
</div>
<?php
$link = mysqli_connect("localhost" , "***" ,"***" , "***");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
} else {
echo "";
}
?>
<?php
$result = mysqli_query($link, "SELECT * FROM **** ORDER BY RAND()
LIMIT 8" )
or die(mysqli_error());
while($row = mysqli_fetch_array( $result )){
?>;
<div class="son_s_p" style="top:1957px;
left:12px;
-webkit-box-shadow:0 3px 8px rgba(0, 0, 0, .25);
position:inherit;
background:white;
width:190px;
height:240px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:center;
float:left;
">
<img src="../lu/music/tumb/<?php echo $row['img']; ?>"style="width:198px; height:148px;" >
<br>
<?php echo $row['name']; ?><br><br>
<div id="son_s_p" style="top:218px;
left:px;
position:absolute;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:justify;">
<?php echo $row['time']; ?> <span class="time&type" style="top;10px;"><?php echo $row['type']; ?></span>
</div>
</div>
<?php
}
?>
Your question was unclear, however I have cleaned up your code so that the div .tv_l is to the left of the div .son_s_p and its content:
.tv_l {
border-radius: 3px/3px;
padding-right: 10px;
border-left: 10px;
border: 1px solid;
float: left;
}
.son_s_p {
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
background: white;
width: 190px;
height: 240px;
border-radius: 3px/3px;
padding-right: 10px;
border-left: 10px;
text-align: center;
float: left;
}
#son_s_p {
border-radius: 3px/3px;
padding-right: 10px;
padding-top: px;
border-left: 10px;
text-align: justify;
}
<div class="tv_l">
<hr>
</div>
<?php
$link = mysqli_connect("localhost" , "***" ,"***" , "***");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
}else{
echo "";
}
$result = mysqli_query($link, "SELECT * FROM **** ORDER BY RAND()
LIMIT 8")
or die(mysqli_error());
while($row = mysqli_fetch_array( $result )){
?>
<div class="son_s_p">
<img src="../lu/music/tumb/<?php echo $row['img']; ?>" style="width:198px; height:148px;">
<br>
<?php echo $row['name']; ?>
<br>
<br>
<div id="son_s_p">
<?php echo $row['time']; ?>
<span class="time&type" style="top;10px;"><?php echo $row['type']; ?></span>
</div>
</div>
<?php } ?>
It looks like you are using absolute positioning on your DIVs. Floats cannot work that way. Use this instead:
position: static;
float: left;
If I were you I would first try to get it to work with pure HTML and CSS with some dummy data, before hooking it up to the database.
Here's an example of how you can achieve floating with divs, in contrast to your approach:
https://jsfiddle.net/19zrr99n/
I am trying to delete comments from my comment system but the code I have is not working. I want to be able to delete each comment from my table including the parent comments. At the moment my code does not get the parameter of the comment from the delete button link.
function.php:
<?php
function getComments($row) {
echo "<li class='comment'>";
echo "<div class='aut'>" . $row['author'] . "</div>";
echo "<div class='comment-body'>" . $row['comment'] . "</div>";
echo "<div class='timestamp'>" . $row['created_at'] . "</div>";
echo "<a href='#comment_form' class='reply' id='" . $row['id'] . "'>Edit Song</a>";
echo "<span> </span>";
echo "<a href='delete.php?id='" . $row['id'] . "'>Delete Song</a>";
$q = "SELECT * FROM threaded_comments WHERE parent_id = ".$row['id']."";
$r = mysql_query($q);
if(mysql_num_rows($r)>0)
{
echo "<ul>";
while($row = mysql_fetch_assoc($r)) {
getComments($row);
}
echo "</ul>";
}
echo "</li>";
}
?>
delete.php:
<?php
include 'includes/config.php';
$deleteid = $_GET['id'];
mysql_query("DELETE FROM threaded_comments WHERE id='$deleteid'");
echo "Song has been deleted!";
header ('Location: index.php');
?>
I have added the index.php and post_comment page page. Also the delete function still doesn't work when I made the changes.
index.php:
<?php
include("config.php");
include("functions.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Multi-Lyric Collaboration System</title>
<script type='text/javascript' src='jquery.pack.js'></script>
<script type='text/javascript'>
$(function(){
$("a.reply").click(function() {
var id = $(this).attr("id");
$("#parent_id").attr("value", id);
$("#name").focus();
});
});
</script>
<style type='text/css'>
html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote,
pre, form, fieldset, table, th, td { margin: 0; padding: 0; }
body {
font-size: 14px;
line-height:1.3em;
background: url('music.jpg');
height: 100%;
background-size:100% ;
background-position: static;
background-color: purple;
min-height: 100%;
background-repeat: no-repeat;
}
label{
color: white;
font-size: 2em;
}
a, a:visited {
outline:none;
color:#7d5f1e;
}
.clear {
clear:both;
}
#wrapper {
width:480px;
margin:0px auto;
padding:15px 0px;
}
.comment {
padding:5px;
border:2px solid black;
border-width: 1px;
margin-top:15px;
list-style:none;
background-color: white;
opacity: 0.96;
-moz-border-radius:20px;
-webkit-border-radius:20px;
overflow-y: scroll;
}
.aut {
font-weight:bold;
}
.timestamp {
font-size:85%;
float:right;
}
#comment_form {
margin-top:15px;
}
#comment_form input {
font-size:1.2em;
margin:0 0 10px;
padding:3px;
display:block;
width:100%;
}
#comment_body {
display:block;
width:100%;
height:150px;
}
#submit_button {
text-align:center;
clear:both;
}
header{
color: white;
text-align: center;
}
</style>
</head>
<body>
<div id='wrapper'>
<header><font size="20">MultiLyric Collaborator</font></header>
<br>
<ul>
<?php
$q = "SELECT * FROM threaded_comments WHERE parent_id = 0";
$r = mysql_query($q);
while($row = mysql_fetch_assoc($r)):
getComments($row);
endwhile;
?>
</ul>
<form id="comment_form" action="post_comment.php" method='post'>
<label for="name">Name:</label>
<input type="text" name="name" id='name'/>
<label for="comment_body">Enter Song:</label>
<textarea name="comment_body" id='comment_body'></textarea>
<input type='hidden' name='parent_id' id='parent_id' value='0'/>
<div id='submit_button'>
<input type="submit" value="Add comment"/>
</div>
</form>
</div>
</body>
</html>
post_comment.php:
<?php
include("config.php");
$author = mysql_real_escape_string($_POST['name']);
$comment_body = mysql_real_escape_string($_POST['comment_body']);
$parent_id = mysql_real_escape_string($_POST['parent_id']);
$q = "INSERT INTO threaded_comments (author, comment, parent_id) VALUES ('$author', '$comment_body', $parent_id)";
$r = mysql_query($q) or die(mysql_error());
if(mysql_affected_rows()==1) {
header("location:index.php");
}
else {
echo "Comment cannot be posted. Please try again.";
}
?>
From the "SELECT" statement in getComments(), it looks like what you need to do is:
mysql_query("DELETE FROM threaded_comments WHERE parent_id ='$deleteid'");
It is 'parent_id' not 'id'.
i have table created inside php with css but the table isn't complete as you see in the photo from the download part. its coming half in the download part.
please someone look to my code and let me know where i gone wrong.
thank you.
my css code
<style type='text/css'>
.container3 {
float:left;
width:100%;
/*background:green;*/
overflow:hidden;
position:relative;
}
.container2 {
float:left;
width:100%;
background:#FFA500;
position:relative;
right:45%;
}
.container1 {
float:left;
width:100%;
/*background:red;*/
position:relative;
right:40%;
}
.col1 {
float:left;
width:26%;
position:relative;
left:87%;
bottom:-200px;
font-size:20px;
text-align:left;
overflow:hidden;
height:570px;
}
.col2 {
float:left;
width:50%;
position:relative;
left:90%;
overflow:hidden;
}
.col3 {
float:left;
width:26%;
position:relative;
left:80%;
overflow:hidden;
}
.footer {
border:1px solid orange;
position: relative;
padding:0px;
margin-top:-5px;
font-size:15px;
}
.signout {
position: absolute;
left: 5px;
bottom: 150px;
width: 130px;
clear: both;
font-size:20px;
text-align:center;
}
.tableClass{
margin-bottom:60px;
}
</style>
<style>
table
{
border-collapse:collapse;
}
table, td, th
{
border:1px solid black;
}
</style>
<style>
table,td,th
{
border:1px solid black;
}
td
{
text-align:center;
}
</style>
<style>
table,td,th
{
border:1px solid black;
}
table
{
width:100%;
}
th
{
height:50px%;
}
</style>
my php code
<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;">Wellcome To Balhaf Services Customer Reports</h1>
<div class="container3 ">
<div class="container1 ">
<div class="container2 ">
<div class="col1">
View Report <br />
View Chart <br />
</div>
<?php
$username = $_POST["username"];
$password = $_POST["password"];
// Connect to the database
$dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
//for mysql injection (security reasons)
$username = mysqli_real_escape_string($dbLink, $username);
$password = mysqli_real_escape_string($dbLink, $password);
mysqli_select_db($dbLink,"balhaf2");
//checking if such data exist in our database and display result
$login = mysqli_query ($dbLink,"select * from users where USERNAME = '$username' and
PASSWORD = '$password'");
if(mysqli_num_rows($login) == 1) {
// Fetch the file information
$query = "select * from users WHERE username = '".$dbLink->escape_string($username)."'";
$result = $dbLink->query($query);
$company = false;
//Now get the result information
$row = $result->fetch_object(); //will store the record in $row
//Access what you need
if($row) {
$company = $row->company; //variable name should match the field name in your database
echo $company; //See if you get the value stored in the database
}
mysqli_select_db($dbLink,"balhaf");
// Query for a list of all existing files
$sql = "SELECT id, name, mime, size, created FROM $company";
$result = $dbLink->query($sql);
// Check if it was successfull
if($result) {
// Make sure there are some files in there
if($result->num_rows == 0) {
echo '<p>There are no files in the database</p>';
}
else {
// Print the top of a table
echo '<div class="col2">';
echo '<div align="center">';
echo '<H2 align="center"> Report Table</H></div>';
echo '<table border="1" align="center"class="tableClass">
<tr>
<td><b>Name</b></td>
<td><b>Mime</b></td>
<td><b>Size (bytes)</b></td>
<td><b>Created</b></td>
<td><b>Download</b></td>
</tr>';
// Print each file
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>{$row['name']}</td>
<td>{$row['mime']}</td>
<td>{$row['size']}</td>
<td>{$row['created']}</td>
<td><a style='text-decoration:none;'href=' get_file_work.php?id={$row['id']}&company=$company'>Download</a></td>
</tr>";
}
// Close table
echo '</table>';
echo '</div>';
}
// Free the result
$result->free();
}
else
{
echo 'Error! SQL query failed:';
echo "<pre>{$dbLink->error}</pre>";
}
// Close the mysql connection
$dbLink->close();
}
else {
echo "worng user"."</br>";
}
?>
<div class="col3">
</div>
</div>
</div>
<div class="signout">
<a style='text-decoration:none;' href= "index.html">Sign Out </br></a>
</div>
<div class="footer" style="background-color:#FFA500;clear:both;text-align:center;">
Copyright balhaf services 20103-2014</div>
</div>
Your container3 is cutting off the display of it's contents with "overflow:hidden;"
You could switch it to:
.container3 {
float:left;
width:100%;
/*background:green;*/
overflow:auto;
position:relative;
}
Or if you don't want to bleed off the edge you could either replace the filename with a download link, something like "view document". Or you could limit the number of characters allowed to show in the table cell. OR you could look into the word-break property (not reliable across all browsers) - see the link below for documentation.
W3Schools - Word-break