Ich habe eine LEFT JOIN
gemacht, um die Werte aus 2 Tabellen aus meiner Datenbank zu bekommen.
Die Abfrage ist wie folgt aus:Wie wählt man eine Spalte in einem linken Join aus, wenn es zwei Spalten mit demselben Namen gibt? [MySql]
SELECT *
FROM thread
LEFT JOIN comments ON thread.id_thread = comments.id_thread
WHERE id_type = '1'
ORDER BY data DESC, hour DESC
Dann habe ich auf diese Weise die Werte Ausgabe:
<?
while($row = mysqli_fetch_array($query))
{
echo '<div class="col-md-1"></div>';
echo '<div class="col-md-11">';
echo $row['title'] ."<br><br>".$row['content']."<br><br>";
echo $row['content_com'];
echo '<div class="col-md-2 pull-right">'. "date: ".$row['data']."<br>"."author: ".'<a href ="/user.php?id='.$row['username'].'">'.$row['username'].'</a>'.'</div>' ."<br><br>";
echo '<form role="form" action="commit.php" method="post"><div class="col-md-offset-1 col-md-9"><input class="form-control" type="text" name="comm"><input type="hidden" name="thread_id" value="'.$row['id_thread'].'"></div></form> <br><br><hr><br>';
echo '</div>';
}
mysqli_close($connect);
?>
Dann in der commit.php (form action):
<?php
session_start();
if(isset($_SESSION['id']))
{
$servername = "mysql9.000webhost.com";
$username = "a5461665_admin";
$password = "xenovia1";
$dbname = "a5461665_pap";
$connect = mysqli_connect($servername, $username, $password, $dbname);
$id = (isset($_GET['id'])) ? $_GET['id'] : $_SESSION['id'];
$ctn = $_POST["comm"];
$com = mysqli_query($connect,"INSERT INTO comments(content_com,id_thread) values ('".$ctn."', '".$_POST['thread_id']."')");
header("location:javascript://history.go(-1)");
if (!$connect) {
die("Connection failed: " . mysqli_connect_error());
}
}
else
{
header(" url=index.php");
}
?>
Mein Problem ist, dass das versteckte Eingabefeld an die Formularaktion das Feld id_thread
aus der Tabelle comments
übergibt, aber ich möchte, dass es das fie passiert ld id_thread
aus der Tabelle threads
, wie mache ich das ??
Sie breit [SQL Injections] geöffnet sind (http://php.net/manual/en/security.database.sql -injektion.php). Da Sie MySQLi verwenden, sollten Sie in [Prepared Statements] (http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) –