I am very New with php and Database…
I have a File where Display the Comment, contact.php , here to schow it and my Css, because codepen have only for JS , the Comment form not to Display , the Code for Comment to be call classprove.php it have in PHP and it is here , people help me, for build these Code…
Than have the File kommenter_verwalter.php where i will to Display my Comments output on Tabelle .
So , i have Two Files for my Comments , classprove.php for Administrate my Comments , and kommenter_verwalter.php , where i will they to Display.
I to try with these Code to build a File for delete with a button beside each row so that if I want to delete that row I click the delete button .
Edit new my Code
Now to search my Code without connect to my classprove.php File .
The Code from kommenter_verwalter.php,
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class ClassProveContakt2
{
private $dbHost = 'localhost'; # Host der Datenbank
private $dbName = 'meine'; # Name der Datenbank
private $dbUser = 'root'; # Name phpmyadmin
private $dbPass = 'pass'; # Passwort
private $name;
private $email;
private $message;
private $datetime;
private $ip;
private $db;
private $connection;
private $id;
private $sql;
private $statement;
private $success;
function CommentToDatabase()
{
// Establish connection with MYSQL Server
try
{
$db = new PDO("mysql:host=localhost;dbname=meine", "root", "pass");
}
catch (PDOException $pe)
{
echo "<br>Cannot connect to database: " . $pe->getMessage();
return false;
}
if(isset($_POST["delete"])) {
try {
$connection = new PDO($id, $name, $email, $message, $datetime, $ip);
$id = $_POST["id"];
$sql = "DELETE FROM mela WHERE id = :id";
$statement = $connection->prepare($sql);
$statement->bindValue(':id', $id);
$statement->execute();
$success = "User successfully deleted";
}catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
}
function tabelle()
{
$db = $this ->CommentToDatabase();
if ($db)
{
echo "<table id='user' class='table table-bordered'>
<tr>
<th>id</th>
<th>name</th>
<th>email</th>
<th>message</th>
<th>datetime</th>
<th>ip</th>
<th>Delete User</th>
</tr>";
foreach ($db as $row){
echo <<<EOT
<tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['email']}</td>
<td>{$row['message']}</td>
<td>{$row['datetime']}</td>
<td>{$row['ip']}</td>
<td><button type "submit" name="delete" value="{$row['id']}">löschen</button>
</tr>
EOT;
}
echo "</table>";
}
}
}
$News = new ClassProveContakt2;
$News -> CommentToDatabase();
$News -> tabelle();
?>
When write sudo tail -n0 -f /var/log/apache2/error.log /var/log/mysql/error.log
Now to come not error , but nothing Display…
I to observe that i have not,
$_POST[“delete”]
and
$_POST[“id”];
I to build my form with only (name, email and message) , id have with phpmyadmin to build . . These piece Code have in internet to found…
Can Please anyone tell me , how can to change these part the Code .
How to show my Tabelle on phpmyadmin ,
I to want that the the File kommenter_verwalter.php (there which here give) , the output Display only the comments(name, email , message,..) on a Table whith the button , delete as this Screeshot to show…,and the File classprove.php to stay as Administrate for Comment .
Can Please anyone help me with this Problem , Thanks !
2
Answers
Because are People on stackoverflow which not to let my another Question to answer ,they to hiding it.....Titel name from it "How to use CRUD on SQL" , and because it is very similar as these , i answer here ....
Now can Display the File kommenter_verwalter.php without connect to my classprove.php File .
I has some mistakes therefore can't Display it....
How have now my kommenter_verwalter.php,
Screehot how to show now my File kommenter_verwalter.php , how to show it
Above error indicate that there is error in
'
and"
you have not place them properly that’s whycomplier
is not able toparse
that part of your code. Change that line like below this should work :