For what you're asking about, Weedpacket is more than likely correct. However, you also don't close the form(s) that you open in the tabelle() function. That'll cause other problems further down the line.
Table from form not Display
- Edited
Now i have to change a little my code, people help me and found unifier errors...
<?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 $PostOK;
private $datetime;
private $items;
private $ip;
function ShowForms()
{
echo '<form method="POST" action="classprove.php">
<label for="name"><b>Name * </b></label>
<input type="text" id="name" name="Name" value="">
<label for="email"><b>E-mail * </b></label>
<input type="email" id="email" name="Email" value="">
<br><br>
<label><b> Message * </b><br>
<textarea cols="45" rows="6" id="text" name="Message"></textarea>
</label>
<br><br>
<input type="submit" name="post" value="POST COMMENT" id="comment">
</form>';
}
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 {
require classprove.php;
$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()
{
if ($sb)
{
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>
</tr>";
foreach ($sb as $row):
echo "<form action=classprove.php method=post>"
. "<tr>"
. "<td>" $row["id"];"</td>"
. "<td>" $row["name"];"</td>"
. "<td>" $row["email"];"</td>"
. "<td>" $row["datetime"];"</td>"
. "<td>" $row["ip"];"</td>"
. "</tr>"
. "</form>";
endforeach;
echo "</table>";
}
}
}
$Newobjects = new ClassProveContakt2();
$Newobjects -> ShowForms();
$Newobjects -> tabelle();
?>
With s
udo tail -n0 -f /var/log/apache2/error.log /var/log/mysql/error.log
to come these error,
Parse error: syntax error, unexpected '$row' (T_VARIABLE), expecting ',' or ';' in /var/www/html/kommenter_verwalter.php on line 106
On Line 106 have;
. "<td>" $row["name"];"</td>"
Line 106 doesn't seem to end with a semicolon. 1st rule of PHP syntax.
You have to concatenate the variables into the output string, and there should only be one semicolon at the end of a full line of code - whitespace doesn't matter to PHP, so each line of code may not be a single typed line. So, this:
hdgc2ws echo "<form action=classprove.php method=post>"
. "<tr>"
. "<td>" $row["id"];"</td>"
. "<td>" $row["name"];"</td>"
. "<td>" $row["email"];"</td>"
. "<td>" $row["datetime"];"</td>"
. "<td>" $row["ip"];"</td>"
. "</tr>"
. "</form>";
becomes this:
echo "<form action=\"classprove.php\" method=\"post\">"
. "<tr>"
. "<td>" .$row["id"]. "</td>"
. "<td>" .$row["name"]. "</td>"
. "<td>" .$row["email"]. "</td>"
. "<td>" .$row["datetime"]. "</td>"
. "<td>" .$row["ip"]. "</td>"
. "</tr>"
. "</form>";
Note the "." between the output strings and the variables.
Better yet:
echo <<<EOT
<form action="classprove.php" method="post"><tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['email']}</td>
<td>{$row['datetime']}</td>
<td>{$row['ip']}</td>
</tr></form>
EOT;
What the <form>
tags are doing there is of course yet another matter entirely.
- Edited
Very Thanks for your recommendations ! , i Edit new my Code because before i did a mistake.. , i will which on the File Only Display the Table with Comments with a button for DELETE beside each row so that if I want to delete that row I click the delete button ....
Before I has not gut explain what i have , sorry about these mistake....
So , i have Two Files for my Comments , classprove.php for Administrate my Comments (People help me with these Code..), and kommenter_verwalter.php , where i will they to Display.
My classprove.php , https://codeshare.io/Gq9byk
The Code from kommenter_verwalter.php,
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'classprove.php';
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 $PostOK;
private $datetime;
private $items;
private $ip;
private $db;
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 {
require classprove.php;
$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($New)
{
$db = $this ->getMessages();
if ($sb)
{
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 ($sb as $row):
echo "EOT
<form action="classprove.php" method="post"><tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['email']}</td>
<td>{$row['datetime']}</td>
<td>{$row['ip']}</td>
</tr></form>
EOT";
endforeach;
echo "</table>";
}
}
}
$New = new ClassProveContakt2();
$New -> tabelle();
?>
With
sudo tail -n0 -f /var/log/apache2/error.log /var/log/mysql/error.log
Now to come,
PHP Parse error: syntax error, unexpected 'classprove' (T_STRING), expecting ',' or ';' in /var/www/html/kommenter_verwalter.php on line 91
On Line 91 , I have
<form action="classprove.php" method="post"><tr>
- Edited
Your echo statement in that location is buggy.
Weedpacket was demonstrating HEREDOC syntax for complex strings. HEREDOC is special: you need the three <<< with your EOT, and then you can use whatever quotes you want:
$string = <<<FOOBAR
I can write whatever I want here.
FOOBAR;
Note that the closing token, in this case "FOOBAR;" must be positioned at character 0 in the line and be followed by a newline.
As it stands in your current code, PHP will print the letters "EOT" and then some HTML, except that you have a string inside double quotes that contains double quotes ... and that's your parse error's cause.
When writing,
echo <<<EOT
<form action="classprove.php" method="post"><tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['email']}</td>
<td>{$row['datetime']}</td>
<td>{$row['ip']}</td>
</tr></form>
EOT;
With
sudo tail -n0 -f /var/log/apache2/error.log /var/log/mysql/error.log
to come ,
PHP Parse error: syntax error, unexpected 'id' (T_STRING), expecting ',' or ';' in /var/www/html/kommenter_verwalter.php on line 92
On Line 92 have
<td>{$row['id']}</td>
Sounds like you've got a stray '
character in an earlier line somewhere.
What editor are you using to write this? Most text editors designed for programmers (at least most that I can think of) can do PHP syntax highlighting which will reveal errors like this. That Codeshare thing you linked to can do this also.
- Edited
Sounds like you've got a stray ' character in an earlier line somewhere.
function tabelle($New)
{
$ok = $New->getMessages();
if ($ok)
{
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 ($ok as $row){
echo '<<<EOT
<form action="classprove.php" method="post"><tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['email']}</td>
<td>{$row['datetime']}</td>
<td>{$row['ip']}</td>
</tr></form>
EOT';
}
echo "</table>";
}
}
What editor are you using to write this?
i am with Linux , the editor i using is Pluma... , now i will install Bluefish...
Notice Weedpacket's syntax - there are no quotes around the heredoc.
- Edited
My Problem was that i write
'<<<EOT
, when should
<<<'EOT'
.....
How now habe my foreach,
foreach ($ok as $row){
echo <<<'EOT'
<form action="classprove.php" method="post">
<tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['email']}</td>
<td>{$row['datetime']}</td>
<td>{$row['ip']}</td>
</tr>
</form>
EOT';
}
But nothing to Display...with
sudo tail -n0 -f /var/log/apache2/error.log /var/log/mysql/error.log
to come
Parse error: syntax error, unexpected 'ClassProveContakt3' (T_STRING) in /var/www/html/kommenter_verwalter.php on line 7
On my Line 7 , have
$New ClassProveContakt3();
, it is above with these Code,
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include 'classprove.php';
$New ClassProveContakt3();
$New -> writeCommentToDatabas();
$New -> getMessages();
My Class ClassProveContakt3(); , come from another File , https://codeshare.io/29BW3M
I have two Files which does same , this and These , https://codeshare.io/Gq9byk , now I am with ClassProveContakt3(); , these both Codes have Two difference people to writing for me ...
- Edited
here tell why... https://www.php.net/manual/de/language.types.string.php#language.types.string.syntax.heredoc
What don't understand what you means with new is not a variable.
You're getting an error because you wrote $new
instead of new
.
- Edited
How now have my Code,
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'classprove.php';
$News = new ClassProveContakt3();
$News -> writeCommentToDatabas();
$News -> getMessages();
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 $PostOK;
private $datetime;
private $items;
private $ip;
private $db;
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 {
require classprove.php;
$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($New)
{
$db = $this ->getMessages();
if ($sb)
{
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 ($sb 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>";
}
}
$Newcomment = new ClassProveContakt2();
$Newcomment -> tabelle();
?>
with
sudo tail -n0 -f /var/log/apache2/error.log /var/log/mysql/error.log
to come,
PHP Parse error: syntax error, unexpected '$Newcomment' (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST) in /var/www/html/kommenter_verwalter.php on line 112, referer: http://localhost/kommenter_verwalter.php
You're missing a closing brace somewhere. Try tidying up your code, be a bit more consistent about how you format it.
- Edited
You're missing a closing brace somewhere. Try tidying up your code, be a bit more consistent about how you format it.
thanks i have it to show , it was the closing brace from function tabelle....but nothing to change...
Now i to change my Code , i to search my Code WITHOUT to connect to my classprove.php , i to search my Code to connect direct to Sql...
My Code Now,
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($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();
?>
Now to come not error , but display nothing....
How to show my Tabelle on phpmyadmin,
- Edited
CommentToDatabase
(which you call twice for some reason) doesn't return anything. So if($db)
fails.
Now: I have some work of my own to attend to, so...