Comment system won't work through php - php

A comment posting tutorial for a guestbook type situation I watched on the internet works fine for many others but for me I keep having
" . $name. ":
" . $content . "
"); fclose ($handle); } ?>
appear above the comment box. Also it does not post anything after doing all that in php. Here is the code:
<?php
if($_POST){
$name = $_POST ['name'];
$content = $_POST ['commentcontent'];
$handle = fopen("JackPackNetwork.html","a");
fwrite ($handle, "<b>" . $name. "</b>:<br/>" . $content . "<br/>");
fclose ($handle);
}
?>
<html>
<head>
</head>
<body>
<form action="" method= "POST">
Comments: <textarea rows= "10" cols= "30" name= "commentContent"></textarea> <br/>
Name: <input type= "text" name = "name"> <br/>
<input type= "submit" value = "Post!"> <br/>
</form>
<?php include "JackPackNetwork.html"; ?>
</body>
</html>
Specifically I want to link to JackPackNetwork.html and update the comments with the ability of someone being able to put their name on it as well. Thanks for your time and consideration.

Your code should look like this:
<?php
if($_POST){
$name = $_POST ['name'];
$content = $_POST ['commentContent'];
$handle = fopen("JackPackNetwork.html","a");
fwrite ($handle, "<b>" . $name. "</b>:<br/>" . $content . "<br/>");
fclose ($handle);
}
?>
<html>
<head>
</head>
<body>
<form action="" method= "POST">
Comments: <textarea rows= "10" cols= "30" name= "commentContent"></textarea> <br/>
Name: <input type= "text" name = "name"> <br/>
<input type= "submit" value = "Post!"> <br/>
</form>
<?php require_once("JackPackNetwork.html"); ?>
</body>
</html>
MISTAKE
array index are case sensitive so $content post request fetch should be done correctly.
Suggestion
Use require_once() instead of include().

Related

How to insert textbox value from form to csv one by one?

My Goal is to insert the value from a textbox from a form to csv one by one.
I tried to look for answers in the internet but I can't seems to find similar scenario on this problem
<?php
if(isset($_POST['submit']))
{
//read data from form
$lName = filter_input(INPUT_POST, "lName");
$fName = filter_input(INPUT_POST, "fName");
$email = filter_input(INPUT_POST, "email");
$phone = filter_input(INPUT_POST, "phone");
//generate output for text file
$output = $fName . " ";
$output .= $lName . " ";
$output .= $email . " ";
$output .= $phone . " ";
//here "t" means tab
//here "n" newline
//open file for output with append mode "a"
$fp = fopen("contacts.csv", "a");
//write to the file
fwrite($fp, $output);
fclose($fp);
}
else
{
echo "empty submit";
}
?>
<html>
<head>
</head>
<body>
<form action="next_page.php" method="post" >
Lastname:<input type="text" name="lName" />
Firstname:<input type="text" name="fName" />
Email:<input type="text" name="email" />
Phone:<input type="text" name="phone" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
My expected output is Lastname will be save in first cell, Firstname will be saev in 2nd cell, and so on.

PHP- Save input data into CSV file and display the entire file in another page

Pretty much in the title. I want to make a solution that saves the input data of a html form and display the entire csv file in a separate page that isn't connected. Here's the code I'm currently using that isn't saving the input data nor display the csv file.
Input Data Page:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<h2>PHP Form Validation Example</h2>
<form method="post" name="test1" action="" onsubmit="required()">
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$web = $_POST['website'];
$comment = $_POST['comment'];
$csv =
array($_POST['name'],$_POST['email'],$_POST['website'],$_POST['comment']);
$file = fopen('form.csv', 'a');
foreach ($csv as $line)
{
fputcsv($file,explode(',',$line));
}
fclose($file);
?>
</html>
PHP:Display CSV file
<!DOCTYPE html>
<html>
<?php
echo "</br >";
echo '<table style="width=100%">';
// Print other student details here (minus the private stuff)
//The CSV file is read and printed on the page when using the 'r' value.
$myfile = fopen("form.csv" , "r") or die ("Unable to open file");
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
echo "</table>";
?>
<body>
</body>
</html>

fwrite sort by date (latest high up)

I've tried to make a comment system, by using fwrite() code. It works but I want my latest comments to list on top of the list.
Here is my code which works but it doesn't work the way I want. Latest comments appears under the list :((
<?php
if ($_POST){
$name = $_POST['name'];
$content = $_POST['commentcontent'];
$date = date("Y-m-d H:i:s");
$handle = fopen("comments.html","a");
fwrite($handle,"<b>" . $name . "<b> (" .$date . ") </b>" ."</b>:</br>" . $content . "</br>");
fclose($handle);
}
?>
<html>
<body>
<form action="" method="POST">
Comments: <textarea rows="10" cols="30" name="commentcontent"/></textarea></br>
Name: <input type="text" name="name"></br>
<input type="submit" value="post!"></br>
<?php include"comments.html";?>
</form>
</body>
</html>

html,css.php? help how output my form subissions into webpage instead of text file?

help i have bit knowledge in html,css but
im kinda new to php forms,database,etc stuffs
my php is working well, when user click submit all forms goes to carlist.txt
but i want it output it through webpage html instead of .txt so i can view it online
how i can able to do that?
and i dont want the users sees their submisions... only me can view it
html :
<html>
<form action"awesome.php" method=get>
First name: <input type="text" name="firstname"><br>
blah.. blahh.
<select name="cars">
<option value="volvo">Volvo XC90</option>
<option value="saab">Saab 95</option>
<option value="mercedes">Mercedes SLK</option>
<option value="audi">Audi TT</option>
</select>
<input type="submit" value="Submit">
</form>
etc. etc. blah blah
</html>
awesome.php:
<?php
header("Location: thanksforsubmiting.html");
$handle = fopen("carslist.txt", "a");
foreach($_GET as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>
thanksforsubmitting.html:
<html>
<title>thank you</title>
<h1> <font color=red>
thank you for submission </h1></font>
</html>
please be gentle to me im kinda newbie :)) TIA
<?php
foreach($_GET as $variable => $value) {
echo $value."<br />";
}
?>
If you want view it online create another page with something like this
$file = file_get_contents('carlist.txt');
$rows = explode("\n", $file);
foreach($rows as $row) {
print_r($row);
}
at awesome.php write following code
if(isset($_GET['submit'])){
$firstName = $_GET['firstname'];
$car = $_GET['cars'];
echo $firstname;
echo $car;
}
ok here is an example code you want. i'm using just 2 files form.php and form1.php. Form.php contains:
<?php
if(isset($_POST['submit'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
header("Location:form1.php");
}
?>
<form name="test" action="" method="post">
<label for="fname">First Name:</label>
<input type="text" name="fname"/>
<label for="lname">Last Name:</label>
<input type="text" name="lname"/>
<input type="submit" name="submit" />
</form>
and form1.php contains following statement:
<?php
echo "Form Submitted!";
?>
On submition form will stay on the same page since action is null in form. In the if statement it will be redirected!

Retrieving data from textarea php

I cannot seem to retrieve the data input into this text area. Also I know this code may not be secure, but I am just beginning with php.
echo '<tr><td align=right>Description:</td><td><textarea name=description form=description cols=100 rows=5></textarea></td></tr>';
$descriptionToSend = $("#description").val()
DBSubmit("INSERT INTO Conference (conferenceid,description,submission_due,review_due) VALUES ('".$_POST['conferenceName']."', '" . $descriptionToSend . "','" .$_POST['submitdeadline'] . "','" .$_POST['reviewdeadline']. "')");
Are you mixing up jquery with php ?
First, the <textarea> should reside in a <form>
After the form is submitted to php, you can access the data sent with $_REQUEST['description'] so you would have
$descriptionToSend = $_REQUEST['description'];
<html>
<head>
<title>Test</title>
</head>
<body>
<?php $name = 'nick';
?>
<form action="Test.php">
Name: <input type="text" name="name" value="<?php echo $name; ?>">
About Me: <textarea name="about" rows="5" cols="10"><?php echo $comment; ?></textarea><br/>
Click Me: <input type="submit" vaule="submit">
</body>
</html>
Use $comment to set text and then just retrieve value using $_GET['about'] in next page
<html>
<body>
<?php
$about = $_GET['about'];
echo $about;
?>
</body>
</html>

Categories