Making a discussion board, how to have more people answer [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
im working on an Discussion board in php and mysql, but my question is; How can i make it that more than 1 person can react on a discussion, like at the moment i have that only one can react because it goes into a field in the database named; reactions
But i want ofcourse to have more people answer it instead of one...
If anyone could tell me how to achieve this, that would be a mayor help!
The code i tried so far:
<?php
include('inc/conn.inc.php');
?>
<?php
if(isset($_POST['post'])){
$reactions= $_POST['msg'];
$sql = "INSERT INTO topics (reactions) VALUES reactions = :reactions";
$sql->bindParam(':reactions', $reactions);
$results = $conn->exec($sql);
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="css/reset.css">
<title>Discussion Board</title>
</head>
<body>
<header>
<h1>Logo comes in here</h1>
</header>
<div id="t1">
<h1>Featured</h1>
</div>
<div id="t2">
<h1>Status</h1>
</div>
<div id="topic-items">
<?php
$id = htmlspecialchars($_GET["id"]);
/*
$sql = "SELECT creator FROM topics WHERE id = :id";
$sql->bindParam(':id', $id);
$results = $conn->query($sql);
*/
$statement = $conn->prepare("SELECT message FROM topics where id = :id");
$statement->execute(array(':id' => $id));
$row = $statement->fetch();
echo "Message: ".$row['message'];
?>
<h2>Featured items come here {discussions} deployed by php </h2>
</div>
<div id="board-status">
<h2>Board statuses come here {status} deployed by php </h2>
</div>
<div id="react-board">
<form>
Message:<br>
<textarea name="msg"></textarea><br>
<input type="submit" name="post" value="Post">
</form>
</div>
<footer>
<h1>Footer Content</h1>
</footer>
</body>
</html>
Isnt it going to replace the field everytime someone presses on the POST button?

You need to first separate your tables in this manner:
Once you do that you can start creating queries using JOINs to obtain your data. Do this, then tell us if you have further difficulties.
Hope this helps.

Related

PHP: Trying to Filter Database information in a table using a combo-box [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So I am trying to sort information based the selected item in the combo box. I am familiar with parts of PHP but still learning.
I was able to fill the combo box with the 'Brand_Name' Column information from my DB.
This is my current output:
It is not filtering though, it is just listing all items in the DB
See code below:
<?php
$hostname = "localhost";
$username = "root";
$password = "root";
$databaseName = "Clients";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$queryDropdown = "SELECT * FROM `Brands` WHERE 1";
$result = mysqli_query($connect, $queryDropdown);
$queryGrid = "SELECT * FROM `Brands` ";
$SearchResult = mysqli_query($connect, $queryGrid);
?>
<html>
<head>
<title>PokerPass</title>
<link rel="stylesheet" type="text/css" href="styles/Main.css">
<link rel="stylesheet" type="text/css" href="styles/ComboBox.css">
<link rel="stylesheet" type="text/css" href="styles/TableGrid.css">
</head>
<body >
<div id="Container" class="Container">
<div id="Header" class="Header">
</div>
<div id="Body" class="Body">
<div name="start" id="Filter_Bar" class="Filter_Bar">
<select class="soflow" id="soflow" Size="1">
<?php while($row1 = mysqli_fetch_array($result)):; ?>
<option><?php echo $row1[1]; ?></option>
<?php endwhile; ?>
</select>
<button class="Submit" ><span><strong>Search<strong></span></button>
<!--<input class="Submit" type="submit" name="search" value="Search </span>">-->
</div>
<div id="Data_Grid" class="Data_Grid">
<table>
<tr>
<th>Server ID</th>
<th>Client</th>
<th>Operator</th>
<th>Username</th>
<th>Password</th>
</tr>
<?php while ($row = mysqli_fetch_array($SearchResult)):; ?>
<tr>
<td><?php echo $row['ServerID']; ?></td>
<td><?php echo $row['Brand_Name']; ?></td>
<td><?php echo $row['Operator_Name']; ?></td>
<td><?php echo $row['Username']; ?></td>
<td><?php echo $row['Password']; ?></td>
</tr>
<?php endwhile; ?>
</table>
</div>
</div>
<div id="Footer" class="Footer">
</div>
</div>
</body>
</html>
In your HTML code, your select element has no name attribute, so you won't be able to pick up its value when the form is submitted. Additionally, your option elements have no value attribute so even if the form was submitted and the select had a name, the value would be empty. See this guide.
Your select element isn't inside a form tag, which means that the page has no idea where to go when the button is pressed. You need a form that specifies the action (the URL you are going to) and the method (post/get). See this guide.
Finally, if you want PHP to know what your query was, you need to get it from the GET or POST parameters. Once you have the variable, you can make your SQL query dynamic - but be careful not to introduce an SQL injection vulnerability - validate the user input carefully (for instance, only allowing numbers as values in your select list) and/or use parameterized queries.
If you want the form to be submitted automatically when the dropdown list is changed, you can use a quick JS attribute to auto-submit the form.
You need to apply the filter value to your query, for your example
you need to construct a new query depending on your selection.
"SELECT * FROM Brands WHERE Client=" + $selectedClient;
Edit:
Here's a reference on how to pass a js variable to php:
How to pass JavaScript variables to PHP?

I want to generate a new page where someone can comment something [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to generate a new page where someone can comment and see the post they clicked on, I currently have my database being looped and echoed onto the screen, they are clickable i'm just not sure how to make it so in generates its own page with the post they clicked on.
else{
$postquery = "SELECT `users`.`username`,`posts`.`text`,`posts`.`date`,`posts`.`title` FROM `users` INNER JOIN `posts` ON `users`.`user_id` = `posts`.`user_id` ORDER BY `posts`.`post_id` DESC";
$post = mysqli_query($dbc,$postquery);
if(mysqli_num_rows($post) > 0) {
foreach($post as $row) {
?>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-preview">
<a href="post.html">
<h2 class="post-title">
<!-- TITLE OF POST -->
<?php echo $row["title"];?>
</h2>
<h3 class="post-subtitle">
<!-- CONTENT OF POST -->
<?php echo $row['text']; ?>
</h3>
</a>
<p class="post-meta">Posted by <?php echo $row['username'];?></a><?php echo " On " . $row['date'];?></p>
</div>
<?php
}
}
}
This will output something like the following:
Title: Post
Content: Blablalala
Posted by: user On 2016-04-02
And what i want to do is make it so i can click the "Title" as a hyperlink and get directed to a different page where i see just that post and are able to comment on it. I heard of using "GET" as a method but currently i'm not sure where to start.
You can simply add and link to the other page.
<h2 class="post-title">
<!-- TITLE OF POST -->
<a href="anotherpage.php?title=<?php echo $row["title"];?>">
<?php echo $row["title"];?>
</a>
</h2>
But the better option is to use the post_id for linking to the post detail:
<h2 class="post-title">
<!-- TITLE OF POST -->
<a href="anotherpage.php?id=<?php echo $row["post_id"];?>">
<?php echo $row["title"];?>
</a>
</h2>
And from anotherpage.php you get it by id and make the query:
$id = $_GET['id'];
$singlepost = "SELECT * FROM `users` WHERE post_id='$id'";
$result = mysqli_query($dbc, $singlepost);
$row = mysqli_fetch_assoc($result);
Then your can normally output like this:
echo $row['title'];
echo $row['text']
echo $row['username'];
And put your comment like below:
<form method="post">
<label>Have your say</label>
<textarea rows="2" cols="5" name="comment"></textarea>
<input type="hidden" name="postid" value="<?php echo $row['post_id']">
<input type="submit" name="submit" value="comment">
</form>
You can check whether there is comment and update the same:
if(isset($_POST['submit'])){
$comment = isset($_POST['comment'])? $_POST['comment']:'';
$id = $_POST['id];
if(empty($comment)){
$error = "Comment field is blank";
}else{
mysqli_query($dbc, "INSERT INTO comment (comment, post_id)
VALUES ('$comment', '$id')");
}
}
Check whther there is error while posting comment.
if(!empty($error)){
echo $error;
}

Open web page according to html table data [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have an HTML table populated from a mysql database table via PHP with 8 different values.
I need to open a second page and pass to it any one from the values I click on in order to query another from the database.
So far I can open the second page via href but I could solve the parameter issue.
Can anyone help me on this?
The code:
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include "ligabd.php";//connects to the server
if(!$l)
{
die("Ligação sem sucesso: ".mysql_error());
}
else
{
$query="SELECT escalao FROM escaloes ORDER BY idescaloes ASC";
$result= mysqli_query($l, $query);
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<table id="t01" align="center">
<br>
<br>
<br>
<br>
<tr>
<td align="center">Escalões</td>
</tr>
<?php
while ($record= mysqli_fetch_array($result))
{
$r=$record['escalao'];
?>
<tr>
<td>
<a href="pag_escalao_mensalidade.php?escalao=">
<?php
echo $record['escalao'];
?>
</a>
</td>
</tr>
<?php
}
}
?>
</table>
</body>
You should use id in your table and use this:
$query="SELECT id, escalao FROM escaloes ORDER BY idescaloes ASC";
...
while ($record=mysqli_fetch_assoc($result)) // Fetch assoc!
...
<?= $record['escalao'] ?>
....
On the second page, you fetch the record again
$query='SELECT * FROM escaloes WHERE id=' . intval( $_GET['id'] );
This is wrong:
<a href="pag_escalao_mensalidade.php?escalao=">
<?php
echo $record['escalao'];
?>
It should be
<a href="pag_escalao_mensalidade.php?escalao=<?php
^^---
echo $record['escalao'];
?>"><?php echo $record['escalao'] ?>
^^^^^^^---
Note the indicated changes

How to print Table of this format [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have following data in mysql, and I want to echo in this format:
Data:
Name,Image URL,Link
I want to print it dynamically like this : http://screensaver.cf/screensavers.php
I don't know user's screen width, still I want it to appear as much as possible in width.
How can I do this in html and PHP?
My code:
<?php
require("config.php");
?>
<div id="main-wrap">
<div class="container">
<div id="main">
<div id="content"><div id='wsite-content' class='wsite-elements wsite-not-footer'>
<div class="paragraph" style="text-align:left;">
<?php
$sql='SELECT * FROM `games` where 1=1';
$data = mysql_query($sql);
echo '<h4 class="result">Result:</h4>';
while($row = mysql_fetch_row($data)){
$table=WHAT TO DO HERE TO MAKE IT LOOK LIKE THAT???????
echo $table;
echo '<br><br>';
}
?>
</div>
</div>
</div>
</div>
</div>
<?php
include("footer.php");
?>
P.S I know mysql is depreciated and I am constantly working to learn Mysqli, as I am in 8th class, I don't have much time.
<style>.a{float:left;}
</style>
>
in while loop use this
<div class = "a">
<?php <img src='".$row['url']."' width='140' height='140'> ?>
</div>

pull Else if from SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need the data to have a different style if the sold = 0 in the mysql table
and when i use the code below the website shows a blank white page
(?=$vehicle-> this is the vehicle reference
and sold is the column withing the sql table
<?php
if (?=$vehicle->sold?!= 1)
{
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
</a>
</div>
}
else {
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
}
?>
You need to learn the PHP from the basics. Learn about operators, PHP and HTML secion, etc..
Anyway, i fixed your code. The condition is if $vehicle->sold is not equal to 1. But i think, (in your OP you mentioned it should be 0) you want this: $vehicle->sold == 0
//Use sytnax like this. See php opeartors.
if ($vehicle->sold != 1) {
?> <!-- Close the php -->
<div class = "foo">
<div class = "fboverlay"></div>
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
</div>
<?php
//Open the php again
} else {
?> <!-- close the php -->
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
<?php //Open again
}

Categories