I want to create something like a bulletin board, manage posts in the DB, add and display them.
I want to satisfy the following conditions.
-Users can speak by entering their name and comment.
・ Manage the user's past statements in a database.
・ Past utterances of all users can be viewed in a list, and at least three of "name, comment, utterance date" are displayed on one line.
・ User names can be up to 20 characters long. If the name is longer than that, an error message is displayed so that the user cannot speak.
-User comments can be up to 100 characters long, and if it exceeds that, an error message is displayed so that the user cannot speak.
-If either or both of the user's name and comment are not entered, an error message is displayed so that the user cannot speak.
I feel like I can't get data with POST.
The error is not displayed and the cause is unknown.
Applicable source code
<? php
$name = "";
$comment = "";
$data = array ();
$error = array ();
$log = date ('Y-m-d H: i: s');
$host = "IP address";
$username = "username";
$passwd = "password";
$dbname = "DB name";
// Connect to sql. Assign to variable
$link = mysqli_connect ($host, $username, $passwd, $dbname);
if ($link) {
// Preventing garbled characters
mysqli_set_charset ($link, 'utf8');
// Execute when transmission data is POST
if ($_SERVER ['REQUEST_METHOD'] === 'post') {
// Substitute transmission data for name
if (isset ($_ POST ['name']) === TRUE) {
$name = $_POST ['name'];
}
// If the send data name is incomplete, assign it to the array errorif (mb_strlen ($name)>20) {
$error [] = 'Please enter a name within 20 characters. ';
} else if (mb_strlen ($name) === 0) {
$error [] = 'Please enter a name';
}
if (isset ($_ POST ['comment']) === TRUE) {
$comment = $_POST ['comment'];
}
// If the send data comment is incomplete, assign it to the array error
if (mb_strlen ($comment)>100) {
$error [] = 'Please enter a comment using 100 characters or less. ';
} else if (mb_strlen ($comment) === 0) {
$error [] = 'Please enter a comment. ';
}
var_dump ($name);
var_dump ($comment);
// Get the number of array $error.
if (count ($error) === 0) {
$query = "INSERT INTO bulletion_bord (user_name, user_comment, data) VALUES ('$name', '$comment', '$log')";
$result = mysqli_query ($link, $query);
if ($result === FALSE) {
$error [] = 'Registration failed. ';
}
}
}
$query = "SELECT * FROM bulletion_bord";
$result = mysqli_query ($link, $query);
while ($row = mysqli_fetch_array ($result)) {
$data [] = $row;
}
mysqli_free_result ($result);
mysqli_close ($link);
} else {
$error [] = 'Connection failure';
}?>
<! DOCTYPE html>
<html lang = "en">
<head>
<meta chaarset = "utf-8">
<title>Assignment (Intermediate)</title>
</head>
<body>
Short Message Board
<!-Display error->
<? php foreach ($error as $value) {?>
<p><? php print $value;?></p>
<? php}?>
<form method = "post">
Name:<input type = "text" name = "name" size = "15" value = "">
Comment:<input type = "text" name = "comment" size = "40" value = "">
<input type = "submit" value = "post">
</form>
<ul>
<? php foreach ($data as $value) {?>
<li>
<? php print $value ['user_name'];?>
<? php print $value ['user_comment'];?>
<? php print $value ['data'];?>
</li>
<? php}?>
</ul>
</body>
</html>
Check if there is data using var_dump ().
I thought that it was not done from the processing in IF ($link).
Please provide more detailed information here.
-
Answer # 1
Related articles
- php - i want to display the layout neatly using the while statement in tcpdf
- php - i want to display thumbnails in rss feeds using tags in wordpress rss files
- i want to store the image file path in mysql using php
- php - i want to reflect the datetime data saved in mysql in the value of and display it initially
- docker, nginx, php, mysql environment construction
- i'm using phplaravel and the screen gives an error
- creating an associative array using php and variable names as keys
- php - [mysql] use the select result of the subquery in the final select
- php - to display the record of the search condition specified in where
- python - how to display a list using curly braces
- php - how to convert from excel to pdf using libreoffice on ec2
- php - display of tag clouds corresponding to categories (excluding specific tags)
- regarding repeated display in php
- python 3x - i want to display a japanese map using japanmap, but i can't no error
- php - i want to expand and display a nested array in view
- php - in a test using mockey for sns authentication, provider :: stateless () does not exist on this mock object is displayed
- javascript - i want to display pdf from url using react-pdf
- css - i want to create a table using table and display multiple pieces of information in the same row
- php - the display size of paging is strange
- php - i want to display array values on an html table in laravel
- php : How to ignore not entered query data in sql query?
- php - i want to create a condition that contains multiple ands and ors in laravel's query builder
- how to insert values when creating sql table structure in php
- php - i want to be able to view messages written by other people even if i am not logged in
- php - i want to add a search function within the page i want to display the table if there is even one posted value
- php - i don't understand why i get a syntax error
- php - cannot display the value received by $_get []
- php sql if statement conditional expression
- i would like to know how to operate sql that calculates the aggregation period from the deadline in php
- php - i want to delete the specified value in the database when i press the delete button
, check the value of $link.
Use var_export () to check the conditions.
Set up a debugging environment and step by step. Increase learning efficiency